mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[k6] Add type documentation (#37056)
* k6: Document fail * k6: Remove docs link Complete docs are included in the doc comment. * k6: Document group * k6: Document sleep * k6: Order signature docs before remarks Renders more usefully in Visual Studio Code. * k6: Document check * k6: Space documented declarations * k6: Space section headers * k6: Document method releases * k6: Simplify check documentation * k6: Simplify fail documentation * k6: Simplify group documentation * k6: Document package * k6: Compress documentation * k6: Document Checker * k6: Document Checkers * k6: Link to check docs * k6: Link to fail docs * k6: Link to group docs * k6: Link to sleep docs * k6: Correct returns tag * k6: Document check type param * k6: Document group return type * k6: Document byte * k6: Document bytes * k6: Document JSON types * k6: Configure API Extractor Enables validating docs with: mkdir -p etc; api-extractor run -c api-extractor.json -l * k6: Ignore docs build * k6: Document doc comment validation * k6: Disable API report generation * k6: Disable doc model generation * k6: Disable .d.ts rollup generation * k6: Disable TSDoc metadata generation * k6: Document typeParam tag warnings * k6/global: Document module * k6/global: Normalize section comments * k6/global: Document open * k6/global: Document __ENV * k6/global: Refine __ENV type * k6/global: Document __VU * k6/global: Document __ITER * k6/global: Document console * k6/global: Normalize VU logic references * k6: Improve section header visibility * k6/crypto: Document module * k6/crypto: Document randomBytes * k6/crypto: Document hmac * k6/crypto: Document md4 * k6/crypto: Document md5 * k6/crypto: Document sha1 * k6/crypto: Document sha256 * k6/crypto: Document sha384 * k6/crypto: Document sha512 * k6/crypto: Document sha512_224 * k6/crypto: Document sha512_256 * k6/crypto: Document ripemd160 * k6/crypto: Document createHash * k6/crypto: Document createHMAC * k6/crypto: Link to createHash docs * k6/crypto: Document Algorithm * k6/crypto: Document StringEncoding * k6/crypto: Document BinaryEncoding * k6/crypto: Document OutputEncoding * k6/crypto: Document Output * k6/crypto: Document Hasher * k6/crypto: Document Hasher#update * k6/crypto: Document Hasher#digest * k6/crypto: Update formatting Repo formatter really wants it this way. * k6/encoding: Document module * k6/encoding: Document b64encode * k6/encoding: Document b64decode * k6/encoding: Document Base64Variant * k6/html: Document module * k6/html: Document parseHTML * k6/html: Add section headers * k6/html: Document Selection * k6: Disable redundant JSDoc check Incorrectly applies to our TSDoc doc comments. * k6/global: Add missing semicolon * k6/global: Correct test * k6/html: Update tests * k6/html: Accept overloads for documentation The overloads in these cases produce more natural IntelliSense rendering of the documentation. * k6/html: Document FormValue * k6/html: Document Tester * k6/html: Document Handler * k6/html: Document Mapper * k6/html: Qualify FormValue description * k6/html: Normalize section header language * k6/html: Document Attribute * k6/html: Document NodeType * k6/html: Document Element * k6/html: Document AnchorElement * k6/html: Document AreaElement * k6/html: Link to Element docs * k6/html: Document AudioElement * k6/html: Document BaseElement * k6/html: Document ButtonElement * k6/html: Document CanvasElement * k6/html: Document DataElement * k6/html: Document DataListElement * k6/html: Document DelElement * k6/html: Document EmbedElement * k6/html: Document FieldSetElement * k6/html: Document FormElement * k6/html: Document FormFieldElement * k6/html: Document HrefElement * k6/html: Document IFrameElement * k6/html: Document ImageElement * k6/html: Document InputElement * k6/html: Document InsElement * k6/html: Document KeygenElement * k6/html: Document LabelElement * k6/html: Document LegendElement * k6/html: Document LiElement * k6/html: Document LinkElement * k6/html: Document MapElement * k6/html: Document MediaElement * k6/html: Document MetaElement * k6/html: Document MeterElement * k6/html: Document ModElement * k6/html: Document ObjectElement * k6/html: Document OListElement * k6/html: Document OptGroupElement * k6/html: Document OptionElement * k6/html: Document OutputElement * k6/html: Document ParamElement * k6/html: Document PreElement * k6/html: Document ProgressElement * k6/html: QuoteElement * k6/html: Document ScriptElement * k6/html: Document SelectElement * k6/html: Document SourceElement * k6/html: Document StyleElement * k6/html: Document TableBodyElement * k6/html: Document TableCellElement * k6/html: Document TableColElement * k6/html: Document TableDataCellElement * k6/html: Document TableElement * k6/html: Document TableFootElement * k6/html: Document TableHeadElement * k6/html: Document TableHeaderCellElement * k6/html: Document TableRowElement * k6/html: Document TableSectionElement * k6/html: Document TextAreaElement * k6/html: Document TimeElement * k6/html: Document TitleElement * k6/html: Document TrackElement * k6/html: Correct MediaElement#textTracks return type * k6/html: Document UListElement * k6/html: Document VideoElement * k6/html: Update HrefElement test * k6/http: Document module * k6/http: Add section headers * k6/http: Normalize refined params type name * k6/http: Normalize refined batch request type names * k6/http: Remove generics justification * k6/http: Document del * k6/http: Document get * k6/http: Document options * k6/http: Document patch * k6/http: Document post * k6/http: Document put * k6/http: Document request * k6/http: Document batch * k6/http: Document file * k6/http: Document cookieJar * k6/http: Include release tags * k6/http: Document Params * k6/http: Document RefinedParams * k6/http: Document AuthMethod * k6/http: Document ResponseType * k6/http: Document ParamsCookieValue * k6/http: Document RequestBody * k6/http: Document StructuredRequestBody * k6/http: Document batch request types * k6/http: Document refined batch request types * k6/http: Document BatchResponses * k6/http: Document Response properties * k6/http: Document Response.html * k6/http: Document Response.json * k6/http: Document Response.clickLink * k6/http: Document Response.submitForm * k6/http: Define SSL/TLS version constants * k6/http: Define OCSP status constants * k6/http: Document OCSP reason constants * k6/http: Define CipherSuite * k6/http: Document Protocol * k6/http: Document CipherSuite * k6/http: Document RefinedResponse * k6/http: Document ResponseBody * k6/http: Document RefinedResponseBody * k6/http: Document RequestCookie * k6/http: Document ResponseCookie * k6/http: Correct Unix time specifications * k6/http: Document FileData * k6/http: Accept formatter changes * k6/http: Link to FileData docs * k6/http: Accept formatter changes * k6/http: Document CookieJar * k6/http: Document CookieJarCookies * k6/http: CookieOptions * k6/metrics: Document module * k6/metrics: Document Metric * k6/metrics: Document Counter * k6/metrics: Document Gauge * k6/metrics: Document Rate * k6/metrics: Document Trend * k6/ws: Document module * k6/ws: Add section headers * k6/ws: Document connect * k6/ws: Document Params * k6/ws: Document Executor * k6/ws: Document Response * k6/ws: Document Socket * k6/ws: Document EventType * k6/ws: Document TimerHandler * k6/ws: Document event handlers * k6/ws: Document WebSocketError * k6/options: Document module * k6/options: Document Options * k6/options: Document CollectorOptions * k6/options: Document Stage * k6/options: Document threshold specifications * k6/options: Document Certificate * k6: Remove API Extractor config No obvious way to get the repo test to accept it. To be restored when an approach is discovered.
This commit is contained in:
parent
b7c382e273
commit
518db0303d
238
types/k6/crypto.d.ts
vendored
238
types/k6/crypto.d.ts
vendored
@ -1,29 +1,175 @@
|
||||
/*
|
||||
* Cryptography utilities.
|
||||
* https://docs.k6.io/docs/k6crypto
|
||||
*/
|
||||
|
||||
import { bytes } from '.';
|
||||
|
||||
/**
|
||||
* Generate random bytes.
|
||||
* @param size - Number of bytes to generate.
|
||||
* @returns Random bytes.
|
||||
* @public
|
||||
*/
|
||||
export function randomBytes(size: number): bytes;
|
||||
export function hmac(algorithm: Algorithm, secret: string, data: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function hmac(algorithm: Algorithm, secret: string, data: string, outputEncoding: StringEncoding): string;
|
||||
export function md4(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function md4(input: string, outputEncoding: StringEncoding): string;
|
||||
export function md5(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function md5(input: string, outputEncoding: StringEncoding): string;
|
||||
export function sha1(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function sha1(input: string, outputEncoding: StringEncoding): string;
|
||||
export function sha256(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function sha256(input: string, outputEncoding: StringEncoding): string;
|
||||
export function sha384(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function sha384(input: string, outputEncoding: StringEncoding): string;
|
||||
export function sha512(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function sha512(input: string, outputEncoding: StringEncoding): string;
|
||||
export function sha512_224(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function sha512_224(input: string, outputEncoding: StringEncoding): string;
|
||||
export function sha512_256(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function sha512_256(input: string, outputEncoding: StringEncoding): string;
|
||||
export function ripemd160(input: string, outputEncoding: BinaryEncoding): bytes;
|
||||
export function ripemd160(input: string, outputEncoding: StringEncoding): string;
|
||||
|
||||
/**
|
||||
* Produce HMAC.
|
||||
* https://docs.k6.io/docs/hmac-algorithm-secret-data-outputencoding
|
||||
* @param algorithm - Hash algorithm.
|
||||
* @param secret - Shared secret.
|
||||
* @param data - Input data.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns Produced HMAC.
|
||||
* @public
|
||||
*/
|
||||
export function hmac<OE extends OutputEncoding>(
|
||||
algorithm: Algorithm,
|
||||
secret: string,
|
||||
data: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with MD4.
|
||||
* https://docs.k6.io/docs/md4-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns MD4 digest.
|
||||
* @public
|
||||
*/
|
||||
export function md4<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with MD5.
|
||||
* https://docs.k6.io/docs/md5-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns MD5 digest.
|
||||
* @public
|
||||
*/
|
||||
export function md5<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with SHA-1.
|
||||
* https://docs.k6.io/docs/sha1-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns SHA-1 digest.
|
||||
* @public
|
||||
*/
|
||||
export function sha1<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with SHA-256.
|
||||
* https://docs.k6.io/docs/sha256-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns SHA-256 digest.
|
||||
* @public
|
||||
*/
|
||||
export function sha256<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with SHA-384.
|
||||
* https://docs.k6.io/docs/sha384-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns SHA-384 digest.
|
||||
* @public
|
||||
*/
|
||||
export function sha384<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with SHA-512.
|
||||
* https://docs.k6.io/docs/sha512-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns SHA-512 digest.
|
||||
* @public
|
||||
*/
|
||||
export function sha512<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with SHA-512/224.
|
||||
* https://docs.k6.io/docs/sha512_224-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns SHA-512/224 digest.
|
||||
* @public
|
||||
*/
|
||||
export function sha512_224<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with SHA-512/256.
|
||||
* https://docs.k6.io/docs/sha512_256-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns SHA-512/256 digest.
|
||||
* @public
|
||||
*/
|
||||
export function sha512_256<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Hash with RIPEMD-160.
|
||||
* https://docs.k6.io/docs/ripemd160-input-outputencoding
|
||||
* @param input - Data to hash.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns RIPEMD-160 digest.
|
||||
* @public
|
||||
*/
|
||||
export function ripemd160<OE extends OutputEncoding>(
|
||||
input: string,
|
||||
outputEncoding: OE
|
||||
): Output<OE>;
|
||||
|
||||
/**
|
||||
* Create a hashing object.
|
||||
* https://docs.k6.io/docs/createhash-algorithm
|
||||
* @param algorithm - Hash algorithm.
|
||||
* @returns Hashing object.
|
||||
* @public
|
||||
*/
|
||||
export function createHash(algorithm: Algorithm): Hasher;
|
||||
|
||||
/**
|
||||
* Create an HMAC hashing object.
|
||||
* https://docs.k6.io/docs/createhmacalgorithm-secret
|
||||
* @param algorithm - Hash algorithm.
|
||||
* @param secret - Shared secret.
|
||||
* @returns HMAC hashing object.
|
||||
* @public
|
||||
*/
|
||||
export function createHMAC(algorithm: Algorithm, secret: string): Hasher;
|
||||
|
||||
/**
|
||||
* Hash algorithm.
|
||||
* @public
|
||||
*/
|
||||
export type Algorithm =
|
||||
| 'md4'
|
||||
| 'md5'
|
||||
@ -34,12 +180,54 @@ export type Algorithm =
|
||||
| 'sha512_224'
|
||||
| 'sha512_256'
|
||||
| 'ripemd160';
|
||||
|
||||
/**
|
||||
* String output encoding.
|
||||
* @public
|
||||
*/
|
||||
export type StringEncoding = 'hex' | 'base64' | 'base64url' | 'base64rawurl';
|
||||
|
||||
/**
|
||||
* Binary output encoding.
|
||||
* @public
|
||||
*/
|
||||
export type BinaryEncoding = 'binary';
|
||||
|
||||
/**
|
||||
* Output encoding.
|
||||
* @public
|
||||
*/
|
||||
export type OutputEncoding = StringEncoding | BinaryEncoding;
|
||||
|
||||
/**
|
||||
* Output type. Varies with output encoding.
|
||||
* @typeParam OE - Output encoding.
|
||||
* @public
|
||||
*/
|
||||
export type Output<OE extends OutputEncoding> = OE extends StringEncoding
|
||||
? string
|
||||
: OE extends BinaryEncoding
|
||||
? bytes
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Hashing object.
|
||||
* https://docs.k6.io/docs/hasher-k6crypto
|
||||
* @public
|
||||
*/
|
||||
export abstract class Hasher {
|
||||
protected __brand: never;
|
||||
update(input: string): void;
|
||||
digest(outputEncoding: BinaryEncoding): bytes;
|
||||
digest(outputEncoding: StringEncoding): string;
|
||||
}
|
||||
protected __brand: never;
|
||||
|
||||
/**
|
||||
* Add more data to the string we want to create a hash of.
|
||||
* @param input - Data to add.
|
||||
*/
|
||||
update(input: string): void;
|
||||
|
||||
/**
|
||||
* Return a digest from the data added so far.
|
||||
* @param outputEncoding - Output encoding.
|
||||
* @returns Digest of data added so far.
|
||||
*/
|
||||
digest<OE extends OutputEncoding>(outputEncoding: OE): Output<OE>;
|
||||
}
|
||||
|
||||
26
types/k6/encoding.d.ts
vendored
26
types/k6/encoding.d.ts
vendored
@ -1,4 +1,30 @@
|
||||
/*
|
||||
* Encoding utilities.
|
||||
* https://docs.k6.io/docs/k6encoding
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base64 encode a string.
|
||||
* https://docs.k6.io/docs/b64encode-input-encoding
|
||||
* @param input - String to encode.
|
||||
* @param encoding - Base64 variant.
|
||||
* @returns Base64 encoded string.
|
||||
* @public
|
||||
*/
|
||||
export function b64decode(input: string, encoding?: Base64Variant): string;
|
||||
|
||||
/**
|
||||
* Base64 decode a string.
|
||||
* https://docs.k6.io/docs/b64decode-input-encoding
|
||||
* @param input - Base64 encoded string.
|
||||
* @param encoding - Base64 variant.
|
||||
* @returns Decoded string.
|
||||
* @public
|
||||
*/
|
||||
export function b64encode(input: string, encoding?: Base64Variant): string;
|
||||
|
||||
/**
|
||||
* Base64 variant.
|
||||
* @public
|
||||
*/
|
||||
export type Base64Variant = 'std' | 'rawstd' | 'url' | 'rawurl';
|
||||
|
||||
94
types/k6/global.d.ts
vendored
94
types/k6/global.d.ts
vendored
@ -1,26 +1,98 @@
|
||||
/*
|
||||
* Custom entities exposed in the global environment.
|
||||
*
|
||||
* The global environment changes with execution context. Some items are
|
||||
* available only in the init context, others only during VU logic execution,
|
||||
* others in both contexts. Comments note availability.
|
||||
*/
|
||||
|
||||
import { bytes } from '.';
|
||||
|
||||
export {};
|
||||
|
||||
// Available without importing
|
||||
declare global {
|
||||
// Init context only
|
||||
// === Init context only ===
|
||||
// -------------------------
|
||||
|
||||
/**
|
||||
* Opens a file, reading all its contents into memory.
|
||||
* https://docs.k6.io/docs/open-filepath-mode
|
||||
* @param filePath - Path to file.
|
||||
* @returns File contents decoded as UTF-8.
|
||||
* @public
|
||||
*/
|
||||
function open(filePath: string): string;
|
||||
|
||||
/**
|
||||
* Opens a file, reading all its contents into memory.
|
||||
* https://docs.k6.io/docs/open-filepath-mode
|
||||
* @param filePath - Path to file.
|
||||
* @returns Binary file contents.
|
||||
* @public
|
||||
*/
|
||||
function open(filePath: string, mode: 'b'): bytes;
|
||||
|
||||
// Init context and VU body
|
||||
const __ENV: object;
|
||||
// === Init context and VU logic ===
|
||||
// ---------------------------------
|
||||
|
||||
// VU body only
|
||||
/**
|
||||
* Environment variables.
|
||||
* https://docs.k6.io/docs/environment-variables
|
||||
* @public
|
||||
*/
|
||||
const __ENV: { [name: string]: string };
|
||||
|
||||
// === VU logic only ===
|
||||
// ---------------------
|
||||
|
||||
/**
|
||||
* Interface to system console.
|
||||
* @public
|
||||
*/
|
||||
let console: Console;
|
||||
const __VU: number; // Changes across VUs
|
||||
const __ITER: number; // Changes across iterations
|
||||
|
||||
/**
|
||||
* Current VU number.
|
||||
* https://docs.k6.io/docs/execution-context-variables
|
||||
* @public
|
||||
*/
|
||||
const __VU: number;
|
||||
|
||||
/**
|
||||
* Current iteration number.
|
||||
* https://docs.k6.io/docs/execution-context-variables
|
||||
* @public
|
||||
*/
|
||||
const __ITER: number;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
interface Console {
|
||||
debug(msg: any, ...fields: any[]): void;
|
||||
error(msg: any, ...fields: any[]): void;
|
||||
info(msg: any, ...fields: any[]): void;
|
||||
log(msg: any, ...fields: any[]): void;
|
||||
warn(msg: any, ...fields: any[]): void;
|
||||
/** Log debug message. */
|
||||
debug: Logger;
|
||||
|
||||
/** Log error message. */
|
||||
error: Logger;
|
||||
|
||||
/** Log informational message. */
|
||||
info: Logger;
|
||||
|
||||
/** Log message. */
|
||||
log: Logger;
|
||||
|
||||
/** Log warning message. */
|
||||
warn: Logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log message procedure.
|
||||
* @public
|
||||
*/
|
||||
interface Logger {
|
||||
/**
|
||||
* @param msg - Message to log.
|
||||
* @param fields - Arbitrary data to attach to message.
|
||||
*/
|
||||
(msg: any, ...fields: any[]): void;
|
||||
}
|
||||
|
||||
1039
types/k6/html.d.ts
vendored
1039
types/k6/html.d.ts
vendored
File diff suppressed because it is too large
Load Diff
571
types/k6/http.d.ts
vendored
571
types/k6/http.d.ts
vendored
@ -1,153 +1,580 @@
|
||||
/*
|
||||
* HTTP client.
|
||||
* https://docs.k6.io/docs/k6http
|
||||
*/
|
||||
|
||||
import { bytes, JSONValue } from '.';
|
||||
import { Selection } from './html';
|
||||
|
||||
// Generics refine response to expose body with correct type
|
||||
// === Main ===
|
||||
// ------------
|
||||
|
||||
/**
|
||||
* Make DELETE request.
|
||||
* https://docs.k6.io/docs/del-url-body-params
|
||||
* @param url - Request URL.
|
||||
* @param body - Discouraged. Request body. Object form encoded.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function del<RT extends ResponseType | undefined>(
|
||||
url: string,
|
||||
body?: RequestBody | null,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Make GET request.
|
||||
* https://docs.k6.io/docs/get-url-body-params
|
||||
* @param url - Request URL.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function get<RT extends ResponseType | undefined>(
|
||||
url: string,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Make OPTIONS request.
|
||||
* https://docs.k6.io/docs/options-url-body-params
|
||||
* @param url - Request URL.
|
||||
* @param body - Request body. Object form encoded.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function options<RT extends ResponseType | undefined>(
|
||||
url: string,
|
||||
body?: RequestBody | null,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Make PATCH request.
|
||||
* https://docs.k6.io/docs/patch-url-body-params
|
||||
* @param url - Request URL.
|
||||
* @param body - Request body. Object form encoded.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function patch<RT extends ResponseType | undefined>(
|
||||
url: string,
|
||||
body?: RequestBody | null,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Make POST request.
|
||||
* https://docs.k6.io/docs/post-url-body-params
|
||||
* @param url - Request URL.
|
||||
* @param body - Request body. Object form encoded.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function post<RT extends ResponseType | undefined>(
|
||||
url: string,
|
||||
body?: RequestBody | null,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Make PUT request.
|
||||
* https://docs.k6.io/docs/put-url-body-params
|
||||
* @param url - Request URL.
|
||||
* @param body - Request body. Object form encoded.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function put<RT extends ResponseType | undefined>(
|
||||
url: string,
|
||||
body?: RequestBody | null,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Make request.
|
||||
* https://docs.k6.io/docs/request-method-url-body-params
|
||||
* @param method - HTTP method.
|
||||
* @param url - Request URL.
|
||||
* @param body - Request body. Object form encoded.
|
||||
* @param params - Request parameters.
|
||||
* @returns Resulting response.
|
||||
* @public
|
||||
*/
|
||||
export function request<RT extends ResponseType | undefined>(
|
||||
method: string,
|
||||
url: string,
|
||||
body?: RequestBody | null,
|
||||
params?: GenericParams<RT> | null
|
||||
params?: RefinedParams<RT> | null
|
||||
): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Batch multiple HTTP requests together,
|
||||
* to issue them in parallel over multiple TCP connections.
|
||||
* https://docs.k6.io/docs/batch-requests
|
||||
* @param requests - Request specifications.
|
||||
* @returns Resulting responses.
|
||||
* @public
|
||||
*/
|
||||
export function batch<Q extends BatchRequests>(requests: Q): BatchResponses<Q>;
|
||||
|
||||
/**
|
||||
* Create a file object used for building multipart requests (file uploads).
|
||||
* https://docs.k6.io/docs/file-data-filename-contenttype
|
||||
* @param data - File data.
|
||||
* @param filename - Filename. Included in MIME message.
|
||||
* @param contentType - Content type. Included in MIME message.
|
||||
* @returns File data object.
|
||||
* @public
|
||||
*/
|
||||
export function file(data: string | bytes, filename?: string, contentType?: string): FileData;
|
||||
|
||||
/**
|
||||
* Get active cookie jar.
|
||||
* https://docs.k6.io/docs/cookiejar
|
||||
* @returns Active cookie jar.
|
||||
* @public
|
||||
*/
|
||||
export function cookieJar(): CookieJar;
|
||||
|
||||
// Params
|
||||
// === SSL/TLS versions ===
|
||||
// ------------------------
|
||||
|
||||
/** @public */
|
||||
export const SSL_3_0 = 'ssl3.0';
|
||||
|
||||
/** @public */
|
||||
export const TLS_1_0 = 'tls1.0';
|
||||
|
||||
/** @public */
|
||||
export const TLS_1_1 = 'tls1.1';
|
||||
|
||||
/** @public */
|
||||
export const TLS_1_2 = 'tls1.2';
|
||||
|
||||
// === OCSP statuses ===
|
||||
// ---------------------
|
||||
|
||||
/** @public */
|
||||
export const OCSP_STATUS_GOOD = 'good';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_STATUS_REVOKED = 'revoked';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_STATUS_SERVER_FAILED = 'server_failed';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_STATUS_UNKNOWN = 'unknown';
|
||||
|
||||
// === OCSP revocation reasons ===
|
||||
// -------------------------------
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_AA_COMPROMISE = 'aa_compromise';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_AFFILIATION_CHANGED = 'affiliation_changed';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_CA_COMPROMISE = 'ca_compromise';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_CERTIFICATE_HOLD = 'certificate_hold';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_CESSATION_OF_OPERATION = 'cessation_of_operation';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_KEY_COMPROMISE = 'key_compromise';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_PRIVILEGE_WITHDRAWN = 'privilege_withdrawn';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_REMOVE_FROM_CRL = 'remove_from_crl';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_SUPERSEDED = 'superseded';
|
||||
|
||||
/** @public */
|
||||
export const OCSP_REASON_UNSPECIFIED = 'unspecified';
|
||||
|
||||
// === Params ===
|
||||
// --------------
|
||||
|
||||
/**
|
||||
* Request parameters.
|
||||
* https://docs.k6.io/docs/params-k6http
|
||||
* @public
|
||||
*/
|
||||
export interface Params {
|
||||
/** Authentication method. */
|
||||
auth?: AuthMethod;
|
||||
|
||||
/** Request scoped cookies. */
|
||||
cookies?: { [name: string]: ParamsCookieValue };
|
||||
|
||||
/** Request headers. */
|
||||
headers?: { [name: string]: string };
|
||||
|
||||
/** Cookie jar to override default VU cookie jar with. */
|
||||
jar?: CookieJar;
|
||||
|
||||
/** Maximum redirects to follow. */
|
||||
redirects?: number;
|
||||
|
||||
/** Response time metric tags. */
|
||||
tags?: { [name: string]: string };
|
||||
|
||||
/** Request timeout. */
|
||||
timeout?: number;
|
||||
|
||||
/** Response type. */
|
||||
responseType?: ResponseType;
|
||||
}
|
||||
export interface GenericParams<RT extends ResponseType | undefined> extends Params {
|
||||
|
||||
/**
|
||||
* Request parameters with refined response type.
|
||||
* Used to infer response body type.
|
||||
* @public
|
||||
*/
|
||||
export interface RefinedParams<RT extends ResponseType | undefined> extends Params {
|
||||
responseType?: RT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request authentication method.
|
||||
* @public
|
||||
*/
|
||||
export type AuthMethod = 'basic' | 'digest' | 'ntlm';
|
||||
|
||||
/**
|
||||
* Response type.
|
||||
* @public
|
||||
*/
|
||||
export type ResponseType = 'binary' | 'none' | 'text';
|
||||
|
||||
/**
|
||||
* Cookie value in request parameters.
|
||||
* https://docs.k6.io/docs/params-k6http
|
||||
* @public
|
||||
*/
|
||||
export type ParamsCookieValue = string | { value?: string; replace?: boolean };
|
||||
|
||||
// RequestBody
|
||||
// === Request body ===
|
||||
// --------------------
|
||||
|
||||
/**
|
||||
* Request body.
|
||||
* @public
|
||||
*/
|
||||
export type RequestBody = string | StructuredRequestBody;
|
||||
|
||||
/**
|
||||
* Structured request body. May include file uploads.
|
||||
* @public
|
||||
*/
|
||||
export interface StructuredRequestBody {
|
||||
[name: string]: string | FileData;
|
||||
}
|
||||
|
||||
// BatchRequest
|
||||
// === Batch request ===
|
||||
// ---------------------
|
||||
|
||||
/**
|
||||
* Batch request specification.
|
||||
* https://docs.k6.io/docs/batch-requests
|
||||
* @public
|
||||
*/
|
||||
export type BatchRequest = string | ArrayBatchRequest | ObjectBatchRequest;
|
||||
|
||||
/**
|
||||
* Array form batch request specification.
|
||||
* @public
|
||||
*/
|
||||
export type ArrayBatchRequest = [ string, string, (RequestBody | null)?, (Params | null)? ];
|
||||
|
||||
/**
|
||||
* Object form batch request specification.
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectBatchRequest {
|
||||
/** Request method. */
|
||||
method: string;
|
||||
|
||||
/** Request URL. */
|
||||
url: string;
|
||||
|
||||
/** Request body. */
|
||||
body?: RequestBody | null;
|
||||
|
||||
/** Requset parameters. */
|
||||
params?: Params | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of batch request specifications.
|
||||
* @public
|
||||
*/
|
||||
export type BatchRequests = BatchRequest[] | { [name: string]: BatchRequest };
|
||||
|
||||
// GenericBatchRequest
|
||||
export type GenericBatchRequest<RT extends ResponseType | undefined> = string | ArrayGenericBatchRequest<RT> | ObjectGenericBatchRequest<RT>;
|
||||
export type ArrayGenericBatchRequest<RT extends ResponseType | undefined> = [ string, string, (RequestBody | null)?, (GenericParams<RT> | null)? ];
|
||||
export interface ObjectGenericBatchRequest<RT extends ResponseType | undefined> {
|
||||
// === Refined batch request ===
|
||||
// -----------------------------
|
||||
|
||||
/**
|
||||
* Refined batch request specification.
|
||||
* Used to infer response body type.
|
||||
* @public
|
||||
*/
|
||||
export type RefinedBatchRequest<RT extends ResponseType | undefined> =
|
||||
| string
|
||||
| ArrayRefinedBatchRequest<RT>
|
||||
| ObjectRefinedBatchRequest<RT>;
|
||||
|
||||
/**
|
||||
* Array form refined batch request specification.
|
||||
* @public
|
||||
*/
|
||||
export type ArrayRefinedBatchRequest<RT extends ResponseType | undefined> = [
|
||||
string,
|
||||
string,
|
||||
(RequestBody | null)?,
|
||||
(RefinedParams<RT> | null)?
|
||||
];
|
||||
|
||||
/**
|
||||
* Object form refined batch request specification.
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectRefinedBatchRequest<RT extends ResponseType | undefined> {
|
||||
method: string;
|
||||
url: string;
|
||||
body?: RequestBody | null;
|
||||
params?: GenericParams<RT> | null;
|
||||
params?: RefinedParams<RT> | null;
|
||||
}
|
||||
|
||||
// BatchResponses
|
||||
// === Batch responses ===
|
||||
// -----------------------
|
||||
|
||||
/**
|
||||
* Set of batch responses. Array or object.
|
||||
* @public
|
||||
*/
|
||||
export type BatchResponses<Q> = {
|
||||
[K in keyof Q]: Q[K] extends GenericBatchRequest<infer RT>
|
||||
? RefinedResponse<RT>
|
||||
: never;
|
||||
[K in keyof Q]: Q[K] extends RefinedBatchRequest<infer RT> ? RefinedResponse<RT> : never;
|
||||
};
|
||||
|
||||
// Response
|
||||
// === Response ===
|
||||
// ----------------
|
||||
|
||||
/**
|
||||
* Response.
|
||||
* https://docs.k6.io/docs/response-k6http
|
||||
* @public
|
||||
*/
|
||||
export interface Response {
|
||||
/** Response body. */
|
||||
body: ResponseBody;
|
||||
|
||||
/** Response cookies. */
|
||||
cookies: { [name: string]: ResponseCookie[] };
|
||||
|
||||
/** Non-HTTP error message. */
|
||||
error: string;
|
||||
|
||||
/** Error code. Present for 4xx 5xx responses and non-HTTP errors. */
|
||||
error_code: number;
|
||||
|
||||
/** Response headers. */
|
||||
headers: { [name: string]: string };
|
||||
|
||||
/** Online Certificate Status Protocol response. */
|
||||
ocsp: {
|
||||
/** When response signed by responder in millisecond Unix time. */
|
||||
produced_at: number;
|
||||
|
||||
/** When indicated status was known correct in millisecond Unix time. */
|
||||
this_update: number;
|
||||
|
||||
/** When response will be refreshed with the CA in millisecond Unix time. */
|
||||
next_update: number;
|
||||
|
||||
/** Certificate revocation reason. One of `OCSP_REASON_*` constants. */
|
||||
revocation_reason: string;
|
||||
|
||||
/** When certificate was revoked in millisecond Unix time. */
|
||||
revoked_at: number;
|
||||
|
||||
/** Certificate status. One of `OCSP_STATUS_*` constants. */
|
||||
status: string;
|
||||
};
|
||||
proto: string;
|
||||
|
||||
/** Protocol used to perform the transfer. */
|
||||
proto: Protocol;
|
||||
|
||||
/** Server IP address. */
|
||||
remote_ip: string;
|
||||
|
||||
/** Remote port connected to. */
|
||||
remote_port: number;
|
||||
|
||||
/** Inciting request details. */
|
||||
request: {
|
||||
/** Request body. */
|
||||
body: string;
|
||||
|
||||
/** Request cookies. */
|
||||
cookies: { [name: string]: RequestCookie[] };
|
||||
|
||||
/** Request headers. */
|
||||
headers: { [name: string]: string[] };
|
||||
|
||||
/** Request method. */
|
||||
method: string;
|
||||
|
||||
/** Request URL. */
|
||||
url: string;
|
||||
};
|
||||
|
||||
/** HTTP status code. */
|
||||
status: number;
|
||||
|
||||
/** Performance timing information. */
|
||||
timings: {
|
||||
/** Milliseconds spent blocked before initiating request. */
|
||||
blocked: number;
|
||||
|
||||
/** Milliseconds spent setting up TCP connection to host. */
|
||||
connecting: number;
|
||||
|
||||
/** Milliseconds spent handshaking TLS session with host. */
|
||||
tls_handshaking: number;
|
||||
|
||||
/** Milliseconds spent sending request. */
|
||||
sending: number;
|
||||
|
||||
/** Milliseconds spent waiting for server response (TTFB). */
|
||||
waiting: number;
|
||||
|
||||
/** Milliseconds spent receiving response data. */
|
||||
receiving: number;
|
||||
|
||||
/** Total time in milliseconds. `sending+waiting+receiving` */
|
||||
duration: number;
|
||||
};
|
||||
tls_cipher_suite: string;
|
||||
|
||||
/** TLS cipher suite used. */
|
||||
tls_cipher_suite: CipherSuite;
|
||||
|
||||
/** TLS/SSL version used. One of `TLS_*` `SSL_*` constants. */
|
||||
tls_version: string;
|
||||
|
||||
/** Fetched URL. May differ from request URL due to redirects. */
|
||||
url: string;
|
||||
|
||||
/**
|
||||
* Click link on page.
|
||||
* https://docs.k6.io/docs/responseclicklink-params
|
||||
* @param selector - Selector expression locating link to click.
|
||||
* @param params - Parameters for link click request.
|
||||
* @returns Link click response.
|
||||
*/
|
||||
clickLink<RT extends ResponseType | undefined>(args?: {
|
||||
selector?: string;
|
||||
params?: GenericParams<RT> | null;
|
||||
params?: RefinedParams<RT> | null;
|
||||
}): RefinedResponse<RT>;
|
||||
|
||||
/**
|
||||
* Parse body as HTML. Optionally filter by selector.
|
||||
* https://docs.k6.io/docs/response-k6http
|
||||
* @param selector - Selector expression.
|
||||
* @returns Document node or selected elements.
|
||||
*/
|
||||
html(selector?: string): Selection;
|
||||
|
||||
/**
|
||||
* Parse body as JSON. Optionally filter by selector.
|
||||
* https://docs.k6.io/docs/response-k6http
|
||||
* @param selector - GJSON expression.
|
||||
* @returns Parse result if successful, `undefined` if unsuccessful.
|
||||
*/
|
||||
json(selector?: string): JSONValue | undefined;
|
||||
|
||||
/**
|
||||
* Submit form on page.
|
||||
* https://docs.k6.io/docs/responsesubmitform-params
|
||||
* @param formSelector - Selector expression locating form to submit.
|
||||
* @param fields - Form field values.
|
||||
* @param submitSelector - Selector expression locating submit button.
|
||||
* @param params - Parameters for form submission request.
|
||||
* @returns Form submission response.
|
||||
*/
|
||||
submitForm<RT extends ResponseType | undefined>(args?: {
|
||||
formSelector?: string;
|
||||
fields?: { [name: string]: string };
|
||||
submitSelector?: string;
|
||||
params?: GenericParams<RT> | null;
|
||||
params?: RefinedParams<RT> | null;
|
||||
}): RefinedResponse<RT>;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP protocol.
|
||||
* @public
|
||||
*/
|
||||
export type Protocol = 'HTTP/1.0' | 'HTTP/1.1' | 'HTTP/2.0';
|
||||
|
||||
/**
|
||||
* TLS cipher suite.
|
||||
* @public
|
||||
*/
|
||||
export type CipherSuite =
|
||||
| 'TLS_RSA_WITH_RC4_128_SHA'
|
||||
| 'TLS_RSA_WITH_3DES_EDE_CBC_SHA'
|
||||
| 'TLS_RSA_WITH_AES_128_CBC_SHA'
|
||||
| 'TLS_RSA_WITH_AES_256_CBC_SHA'
|
||||
| 'TLS_RSA_WITH_AES_128_GCM_SHA256'
|
||||
| 'TLS_RSA_WITH_AES_256_GCM_SHA384'
|
||||
| 'TLS_ECDHE_ECDSA_WITH_RC4_128_SHA'
|
||||
| 'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA'
|
||||
| 'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA'
|
||||
| 'TLS_ECDHE_RSA_WITH_RC4_128_SHA'
|
||||
| 'TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA'
|
||||
| 'TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA'
|
||||
| 'TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA'
|
||||
| 'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256'
|
||||
| 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256'
|
||||
| 'TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384'
|
||||
| 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384';
|
||||
|
||||
/**
|
||||
* Refined response.
|
||||
* Exposes body with best possible type.
|
||||
* @public
|
||||
*/
|
||||
export interface RefinedResponse<RT extends ResponseType | undefined> extends Response {
|
||||
body: RefinedResponseBody<RT>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response body.
|
||||
* @public
|
||||
*/
|
||||
export type ResponseBody = string | bytes | null;
|
||||
|
||||
/**
|
||||
* Refined response body.
|
||||
* Best possible type given `responseType` from request parameters.
|
||||
* @typeParam RT - `Params.responseType` value.
|
||||
* @privateRemarks Default type is a union due to depending on program options.
|
||||
* @public
|
||||
*/
|
||||
export type RefinedResponseBody<RT extends ResponseType | undefined> = RT extends 'binary'
|
||||
? bytes
|
||||
: RT extends 'none'
|
||||
@ -155,46 +582,132 @@ export type RefinedResponseBody<RT extends ResponseType | undefined> = RT extend
|
||||
: RT extends 'text'
|
||||
? string
|
||||
: RT extends undefined
|
||||
? string | null // Default body type conditional on program options
|
||||
? string | null
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Request cookie description in response.
|
||||
* @public
|
||||
*/
|
||||
export interface RequestCookie {
|
||||
/** Name. */
|
||||
name: string;
|
||||
|
||||
/** Value. */
|
||||
value: string;
|
||||
|
||||
/** Whether configured to override VU cookie jar. */
|
||||
replace: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response cookie.
|
||||
* @public
|
||||
*/
|
||||
export interface ResponseCookie {
|
||||
/** Name. */
|
||||
name: string;
|
||||
|
||||
/** Value. */
|
||||
value: string;
|
||||
|
||||
/** Domain allowed to receive. */
|
||||
domain: string;
|
||||
|
||||
/** Scope path. */
|
||||
path: string;
|
||||
|
||||
/** HTTP only. */
|
||||
httpOnly: boolean;
|
||||
|
||||
/** Secure. */
|
||||
secure: boolean;
|
||||
|
||||
/** Seconds until expiration. */
|
||||
maxAge: number;
|
||||
|
||||
/** Expiry time in millisecond Unix time. */
|
||||
expires: number;
|
||||
}
|
||||
|
||||
// FileData
|
||||
// === File data ===
|
||||
// -----------------
|
||||
|
||||
/**
|
||||
* File data for constructing a multipart request with file uploads.
|
||||
* https://docs.k6.io/docs/filedata-k6http
|
||||
* @public
|
||||
*/
|
||||
export abstract class FileData {
|
||||
protected __brand: never;
|
||||
|
||||
/** File data. */
|
||||
data: string | bytes;
|
||||
|
||||
/** Filename to include in MIME message. */
|
||||
filename?: string;
|
||||
|
||||
/** Content type to include in MIME message. */
|
||||
content_type?: string;
|
||||
}
|
||||
|
||||
// CookieJar
|
||||
// === Cookie jar ===
|
||||
// ------------------
|
||||
|
||||
/**
|
||||
* Object for storing cookies.
|
||||
* https://docs.k6.io/docs/cookiejar-k6http
|
||||
* @public
|
||||
*/
|
||||
export abstract class CookieJar {
|
||||
protected __brand: never;
|
||||
|
||||
/**
|
||||
* Get cookies set for a particular URL.
|
||||
* https://docs.k6.io/docs/cookiejarcookiesforurlurl
|
||||
* @param url - URL for which to get cookies.
|
||||
* @returns Cookies for URL.
|
||||
*/
|
||||
cookiesForURL(url: string): CookieJarCookies;
|
||||
|
||||
/**
|
||||
* Set cookie.
|
||||
* https://docs.k6.io/docs/cookiejarsetname-value-options
|
||||
* @param name - Cookie name.
|
||||
* @param value - Cookie value.
|
||||
* @param options - Optional settings.
|
||||
*/
|
||||
set(name: string, value: string, options?: CookieOptions | null): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cookies retrieved from cookie jar.
|
||||
* @public
|
||||
*/
|
||||
export interface CookieJarCookies {
|
||||
[name: string]: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional settings when adding a cookie to a cookie jar.
|
||||
* @public
|
||||
*/
|
||||
export interface CookieOptions {
|
||||
/** Domain allowed to receive. */
|
||||
domain?: string;
|
||||
|
||||
/** Scope path. */
|
||||
path?: string;
|
||||
|
||||
/** Expiry time in RFC1123 format. */
|
||||
expires?: string;
|
||||
|
||||
/** Seconds until expiration. */
|
||||
max_age?: number;
|
||||
|
||||
/** Secure. */
|
||||
secure?: boolean;
|
||||
|
||||
/** HTTP only. */
|
||||
http_only?: boolean;
|
||||
}
|
||||
|
||||
108
types/k6/index.d.ts
vendored
108
types/k6/index.d.ts
vendored
@ -5,7 +5,11 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.4
|
||||
|
||||
/*
|
||||
/**
|
||||
* k6 JavaScript API.
|
||||
* https://docs.k6.io/docs
|
||||
*
|
||||
* @privateRemarks
|
||||
* Uses a branding pattern throughout to reflect the custom classes exposed by
|
||||
* the k6 runtime. These classes have internal state not visible in JavaScript.
|
||||
* The object passed back to k6 must be an actual instance created on the
|
||||
@ -16,6 +20,8 @@
|
||||
*
|
||||
* This follows the pattern used in the TypeScript compiler:
|
||||
* https://github.com/Microsoft/TypeScript/blob/7b48a182c05ea4dea81bab73ecbbe9e013a79e99/src/compiler/types.ts#L693-L698
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
import './global'; // Type global environment
|
||||
@ -29,25 +35,105 @@ import './metrics';
|
||||
import './options';
|
||||
import './ws';
|
||||
|
||||
export function check<T>(val: T, sets: Checkers<T>, tags?: object): boolean;
|
||||
// === Main ===
|
||||
// ------------
|
||||
|
||||
/**
|
||||
* Run checks on a value.
|
||||
* https://docs.k6.io/docs/check-val-sets-tags
|
||||
* @typeParam VT - Value type.
|
||||
* @param val - Value to test.
|
||||
* @param sets - Tests (checks) to run on the value.
|
||||
* @param tags - Extra tags to attach to metrics emitted.
|
||||
* @returns `true` if all checks have succeeded, otherwise `false`.
|
||||
* @public
|
||||
*/
|
||||
export function check<VT>(val: VT, sets: Checkers<VT>, tags?: object): boolean;
|
||||
|
||||
/**
|
||||
* Immediately throw an error, aborting the current script iteration.
|
||||
* https://docs.k6.io/docs/fail-err
|
||||
* @param err - Error message that gets printed to stderr.
|
||||
* @public
|
||||
*/
|
||||
export function fail(err?: string): never;
|
||||
export function group<T>(name: string, fn: () => T): T;
|
||||
|
||||
/**
|
||||
* Run code inside a group.
|
||||
* https://docs.k6.io/docs/group-name-fn-cond
|
||||
* @typeParam RT - Return type.
|
||||
* @param name - Name of the group.
|
||||
* @param fn - Group body. Code to be executed in the group context.
|
||||
* @returns The return value of `fn`.
|
||||
* @public
|
||||
*/
|
||||
export function group<RT>(name: string, fn: () => RT): RT;
|
||||
|
||||
/**
|
||||
* Suspend VU execution for the specified duration.
|
||||
* https://docs.k6.io/docs/sleep-t-1
|
||||
* @param t - Duration, in seconds.
|
||||
* @public
|
||||
*/
|
||||
export function sleep(t: number): void;
|
||||
|
||||
export interface Checker<T> {
|
||||
(val: T): boolean;
|
||||
}
|
||||
export interface Checkers<T> {
|
||||
[description: string]: Checker<T>;
|
||||
/**
|
||||
* Check procedure.
|
||||
* @typeParam VT - Value type.
|
||||
* @public
|
||||
*/
|
||||
export interface Checker<VT> {
|
||||
/**
|
||||
* Check procedure.
|
||||
* @param val - Value to check.
|
||||
* @returns Whether check passed.
|
||||
*/
|
||||
(val: VT): boolean;
|
||||
}
|
||||
|
||||
// Common types
|
||||
export type byte = number; // [0,256)
|
||||
/**
|
||||
* Named check procedures.
|
||||
* @typeParam VT - Value type.
|
||||
* @public
|
||||
*/
|
||||
export interface Checkers<VT> {
|
||||
[description: string]: Checker<VT>;
|
||||
}
|
||||
|
||||
// === Common types ===
|
||||
// --------------------
|
||||
|
||||
/**
|
||||
* Byte represented as number. Value range [0,256)
|
||||
* @public
|
||||
*/
|
||||
export type byte = number;
|
||||
|
||||
/**
|
||||
* Byte array.
|
||||
* @public
|
||||
*/
|
||||
export type bytes = byte[];
|
||||
|
||||
// JavaScript value representable with JSON
|
||||
// === JSON ===
|
||||
// ------------
|
||||
|
||||
/**
|
||||
* JavaScript value representable with JSON.
|
||||
* @public
|
||||
*/
|
||||
export type JSONValue = null | boolean | number | string | JSONArray | JSONObject;
|
||||
|
||||
/**
|
||||
* Array representable with JSON.
|
||||
* @public
|
||||
*/
|
||||
export interface JSONArray extends Array<JSONValue> {}
|
||||
|
||||
/**
|
||||
* Object representable with JSON.
|
||||
* @public
|
||||
*/
|
||||
export interface JSONObject {
|
||||
[key: string]: JSONValue;
|
||||
}
|
||||
|
||||
43
types/k6/metrics.d.ts
vendored
43
types/k6/metrics.d.ts
vendored
@ -1,18 +1,61 @@
|
||||
/*
|
||||
* Custom metrics.
|
||||
* https://docs.k6.io/docs/k6metrics
|
||||
*/
|
||||
|
||||
/**
|
||||
* Custom metric.
|
||||
* @public
|
||||
*/
|
||||
export abstract class Metric {
|
||||
protected __brand: never;
|
||||
|
||||
/**
|
||||
* @param name - Metric name.
|
||||
* @param isTime - Whether values are time values.
|
||||
*/
|
||||
constructor(name: string, isTime?: boolean);
|
||||
|
||||
/**
|
||||
* Add value.
|
||||
* @param value - Value to add.
|
||||
* @param tags - Tags to attach to data point.
|
||||
*/
|
||||
add(value: number | boolean, tags?: { [name: string]: string }): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cumulative counter.
|
||||
* https://docs.k6.io/docs/counter-k6metrics
|
||||
* @public
|
||||
*/
|
||||
export class Counter extends Metric {
|
||||
protected __brand: never;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gauge. Holds only latest value.
|
||||
* https://docs.k6.io/docs/gauge-k6metrics
|
||||
* @public
|
||||
*/
|
||||
export class Gauge extends Metric {
|
||||
protected __brand: never;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks percentage of nonzero values.
|
||||
* https://docs.k6.io/docs/rate-k6metrics
|
||||
* @public
|
||||
*/
|
||||
export class Rate extends Metric {
|
||||
protected __brand: never;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates summary statistics.
|
||||
* https://docs.k6.io/docs/trend-k6metrics
|
||||
* @public
|
||||
*/
|
||||
export class Trend extends Metric {
|
||||
protected __brand: never;
|
||||
}
|
||||
|
||||
113
types/k6/options.d.ts
vendored
113
types/k6/options.d.ts
vendored
@ -1,56 +1,167 @@
|
||||
/*
|
||||
* Program options.
|
||||
* https://docs.k6.io/docs/options
|
||||
*/
|
||||
|
||||
import { CipherSuite } from './http';
|
||||
|
||||
/**
|
||||
* Program options.
|
||||
* https://docs.k6.io/docs/options
|
||||
* @public
|
||||
*/
|
||||
export interface Options {
|
||||
/** Maximum parallel `http.batch()` connections per VU. */
|
||||
batch: number;
|
||||
|
||||
/** Maximum parallel `http.batch()` host connections per VU. */
|
||||
batchPerHost: number;
|
||||
|
||||
/** Blacklist IP ranges from being called. */
|
||||
blacklistIPs: string[];
|
||||
|
||||
/** Discard response bodies. */
|
||||
discardResponseBodies: boolean;
|
||||
|
||||
/** Test duration. */
|
||||
duration: string;
|
||||
|
||||
/** Third party collector configuration. */
|
||||
ext: { [name: string]: CollectorOptions };
|
||||
|
||||
/** Static hostname mapping. */
|
||||
hosts: { [name: string]: string };
|
||||
|
||||
/** Log all HTTP requests and responses. */
|
||||
httpDebug: string;
|
||||
|
||||
/** Disable TLS verification. Insecure. */
|
||||
insecureSkipTLSVerify: boolean;
|
||||
|
||||
/** Iterations to execute. */
|
||||
iterations: number;
|
||||
|
||||
/** Persist the k6 process after test completion. */
|
||||
linger: boolean;
|
||||
|
||||
/** Maximum HTTP redirects to follow. */
|
||||
maxRedirects: number;
|
||||
|
||||
/** Minimum test iteration duration. */
|
||||
minIterationDuration: string;
|
||||
|
||||
/** Disable keepalive connections. */
|
||||
noConnectionReuse: boolean;
|
||||
|
||||
/** Disable usage reports. */
|
||||
noUsageReport: boolean;
|
||||
|
||||
/** Disable cross-VU TCP connection reuse. */
|
||||
noVUConnectionReuse: boolean;
|
||||
|
||||
/** Start test in paused state. */
|
||||
paused: boolean;
|
||||
|
||||
/** Maximum requests per second across all VUs. */
|
||||
rps: number;
|
||||
|
||||
/** Setup function timeout. */
|
||||
setupTimeout: string;
|
||||
|
||||
/** Test stage specifications. Program of target VU stages. */
|
||||
stages: Stage[];
|
||||
|
||||
/** Define stats for trend metrics. */
|
||||
summaryTrendStats: string[];
|
||||
|
||||
/** Which system tags to include in collected metrics. */
|
||||
systemTags: string[];
|
||||
|
||||
/** Tags to set test wide across all metrics. */
|
||||
tags: { [name: string]: string };
|
||||
|
||||
/** Teardown function timeout. */
|
||||
teardownTimeout: string;
|
||||
|
||||
/** Threshold specifications. Defines pass and fail conditions. */
|
||||
thresholds: { [name: string]: Threshold[] };
|
||||
|
||||
/** Throw error on failed HTTP request. */
|
||||
throw: boolean;
|
||||
|
||||
/** TLS client certificates. */
|
||||
tlsAuth: Certificate[];
|
||||
tlsCipherSuites: string[];
|
||||
|
||||
/** Allowed TLS cipher suites. */
|
||||
tlsCipherSuites: CipherSuite[];
|
||||
|
||||
/** Allowed TLS version. Use `http.SSL_*` `http.TLS_*` constants. */
|
||||
tlsVersion: string | { min: string; max: string };
|
||||
|
||||
/** User agent string to include in HTTP requests. */
|
||||
userAgent: string;
|
||||
|
||||
/** Number of VUs to run concurrently. */
|
||||
vus: number;
|
||||
|
||||
/** Maximum VUs. Preallocates VUs to enable faster scaling. */
|
||||
vusMax: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Third party collector configuration.
|
||||
* @public
|
||||
*/
|
||||
export interface CollectorOptions {
|
||||
[name: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test stage.
|
||||
* @public
|
||||
*/
|
||||
export interface Stage {
|
||||
/** Stage duration. */
|
||||
duration: string;
|
||||
|
||||
/** Target number of VUs. */
|
||||
target: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Threshold specification.
|
||||
* https://docs.k6.io/docs/thresholds
|
||||
* @public
|
||||
*/
|
||||
export type Threshold = string | ObjectThreshold;
|
||||
|
||||
/**
|
||||
* Object form threshold specification.
|
||||
* https://docs.k6.io/docs/thresholds
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectThreshold {
|
||||
/** Abort test if threshold violated. */
|
||||
abortOnFail?: boolean;
|
||||
|
||||
/** Duration to delay evaluation. Enables collecting additional metrics. */
|
||||
delayAbortEval?: string;
|
||||
|
||||
/** Threshold expression. */
|
||||
threshold: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* TLS client certificate.
|
||||
* @public
|
||||
*/
|
||||
export interface Certificate {
|
||||
/** PEM encoded certificate. */
|
||||
cert: string;
|
||||
|
||||
/** Domains certificate is valid for. */
|
||||
domains: string[];
|
||||
|
||||
/** PEM encoded certificate key. */
|
||||
key: string;
|
||||
}
|
||||
|
||||
@ -40,4 +40,4 @@ __ITER; // $ExpectType number
|
||||
|
||||
// environment
|
||||
__ENV = 5; // $ExpectError
|
||||
__ENV; // $ExpectType object
|
||||
__ENV; // $ExpectType { [name: string]: string; }
|
||||
|
||||
@ -79,9 +79,9 @@ derived = selection.first();
|
||||
element = selection.get(7);
|
||||
derived = selection.has('.item');
|
||||
selection.html(); // $ExpectType string | undefined
|
||||
derived = selection.is('.item');
|
||||
derived = selection.is(tester);
|
||||
derived = selection.is(selection);
|
||||
selection.is('.item'); // $ExpectType boolean
|
||||
selection.is(tester); // $ExpectType boolean
|
||||
selection.is(selection); // $ExpectType boolean
|
||||
derived = selection.last();
|
||||
selection.map(mapper); // $ExpectType unknown[]
|
||||
derived = selection.next('span');
|
||||
@ -210,8 +210,8 @@ href.hostname(); // $ExpectType string
|
||||
href.origin(); // $ExpectType string
|
||||
href.password(); // $ExpectType string
|
||||
href.pathname(); // $ExpectType string
|
||||
href.port(); // $ExpectType string
|
||||
href.protocol(); // $ExpectType string
|
||||
href.post(); // $ExpectType string
|
||||
href.relList(); // $ExpectType string[]
|
||||
href.search(); // $ExpectType string
|
||||
href.text(); // $ExpectType string
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"npm-naming": false
|
||||
"npm-naming": false,
|
||||
"no-redundant-jsdoc-2": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
217
types/k6/ws.d.ts
vendored
217
types/k6/ws.d.ts
vendored
@ -1,54 +1,233 @@
|
||||
export function connect(url: string, executor: Executor): Response;
|
||||
export function connect(url: string, params: Params | null, executor: Executor): Response;
|
||||
/*
|
||||
* WebSocket client.
|
||||
* https://docs.k6.io/docs/k6-websocket-api
|
||||
*/
|
||||
|
||||
// Parameters
|
||||
// === Main ===
|
||||
// ------------
|
||||
|
||||
/**
|
||||
* Open WebSocket connection.
|
||||
* https://docs.k6.io/docs/connect-url-params-func
|
||||
* @param url - Request URL.
|
||||
* @param callback - Logic to execute with socket.
|
||||
* @returns HTTP response to connection request.
|
||||
* @public
|
||||
*/
|
||||
export function connect(url: string, callback: Executor): Response;
|
||||
|
||||
/**
|
||||
* Open WebSocket connection.
|
||||
* https://docs.k6.io/docs/connect-url-params-func
|
||||
* @param url - Request URL.
|
||||
* @param params - Request parameters.
|
||||
* @param callback - Logic to execute with socket.
|
||||
* @returns HTTP response to connection request.
|
||||
* @public
|
||||
*/
|
||||
export function connect(url: string, params: Params | null, callback: Executor): Response;
|
||||
|
||||
// === Parameters ===
|
||||
// ------------------
|
||||
|
||||
/**
|
||||
* Request parameters.
|
||||
* @public
|
||||
*/
|
||||
export interface Params {
|
||||
/** Request headers. */
|
||||
headers?: { [name: string]: string };
|
||||
|
||||
/** Response time metric tags. */
|
||||
tags?: { [name: string]: string };
|
||||
}
|
||||
|
||||
/**
|
||||
* Socket executor.
|
||||
* @public
|
||||
*/
|
||||
export interface Executor {
|
||||
/** @param socket - The opened socket. */
|
||||
(socket: Socket): void;
|
||||
}
|
||||
|
||||
// Response
|
||||
// === Response ===
|
||||
// ----------------
|
||||
|
||||
/**
|
||||
* HTTP response to connection request.
|
||||
* @public
|
||||
*/
|
||||
export interface Response {
|
||||
/** Fetched URL. May differ from request URL due to redirects. */
|
||||
url: string;
|
||||
|
||||
/** HTTP status code. */
|
||||
status: number;
|
||||
|
||||
/** Response headers. */
|
||||
headers: { [name: string]: string };
|
||||
|
||||
/** Response body. */
|
||||
body: string;
|
||||
|
||||
/** Non-HTTP error message. */
|
||||
error: string;
|
||||
}
|
||||
|
||||
// Socket
|
||||
// === Socket ===
|
||||
// --------------
|
||||
|
||||
/**
|
||||
* Created socket.
|
||||
* https://docs.k6.io/docs/socket
|
||||
* @public
|
||||
*/
|
||||
export abstract class Socket {
|
||||
protected __brand: never;
|
||||
|
||||
/**
|
||||
* Close connection.
|
||||
* https://docs.k6.io/docs/socketclose
|
||||
* @param code - WebSocket status code.
|
||||
*/
|
||||
close(code?: number): void;
|
||||
|
||||
/**
|
||||
* Listen to event.
|
||||
* https://docs.k6.io/docs/socketon
|
||||
* @param event - Event type.
|
||||
* @param handler - Event handler.
|
||||
*/
|
||||
on<ET extends EventType>(event: ET, handler: EventHandler<ET>): void;
|
||||
|
||||
/**
|
||||
* Send ping.
|
||||
* https://docs.k6.io/docs/socketping
|
||||
*/
|
||||
ping(): void;
|
||||
|
||||
/**
|
||||
* Send data.
|
||||
* https://docs.k6.io/docs/socketsend
|
||||
* @param data - Data to send.
|
||||
*/
|
||||
send(data: string): void;
|
||||
|
||||
/**
|
||||
* Call a function repeatedly, while the WebSocket connection is open.
|
||||
* https://docs.k6.io/docs/socketsetinterval
|
||||
* @param handler - The function to call every `interval` milliseconds.
|
||||
* @param interval - Milliseconds between two calls to `callback`.
|
||||
*/
|
||||
setInterval(handler: TimerHandler, interval: number): void;
|
||||
|
||||
/**
|
||||
* Call a function at a later time,
|
||||
* if the WebSocket connection is still open then.
|
||||
* https://docs.k6.io/docs/socketsettimeout
|
||||
* @param handler - The function to call when `delay` has expired.
|
||||
* @param delay - Delay in milliseconds.
|
||||
*/
|
||||
setTimeout(handler: TimerHandler, delay: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event type.
|
||||
* @public
|
||||
*/
|
||||
export type EventType = 'close' | 'error' | 'message' | 'open' | 'ping' | 'pong';
|
||||
export type EventHandler<ET extends EventType> = ET extends 'close'
|
||||
? (code: number) => void
|
||||
: ET extends 'error'
|
||||
? (error: WebSocketError) => void
|
||||
: ET extends 'message'
|
||||
? (message: string) => void
|
||||
: ET extends 'open'
|
||||
? () => void
|
||||
: ET extends 'ping'
|
||||
? () => void
|
||||
: ET extends 'pong'
|
||||
? () => void
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Timer handler.
|
||||
* @public
|
||||
*/
|
||||
export interface TimerHandler {
|
||||
(): void;
|
||||
}
|
||||
|
||||
// Error
|
||||
// === Event handlers ===
|
||||
// ----------------------
|
||||
|
||||
/**
|
||||
* Event handler. Signature varies with event type.
|
||||
* @public
|
||||
*/
|
||||
export type EventHandler<ET extends EventType> = ET extends 'close'
|
||||
? CloseEventHandler
|
||||
: ET extends 'error'
|
||||
? ErrorEventHandler
|
||||
: ET extends 'message'
|
||||
? MessageEventHandler
|
||||
: ET extends 'open'
|
||||
? OpenEventHandler
|
||||
: ET extends 'ping'
|
||||
? PingEventHandler
|
||||
: ET extends 'pong'
|
||||
? PongEventHandler
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Close event handler.
|
||||
* @public
|
||||
*/
|
||||
export interface CloseEventHandler {
|
||||
/** @param code - WebSocket status code. */
|
||||
(code: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error event handler.
|
||||
* @public
|
||||
*/
|
||||
export interface ErrorEventHandler {
|
||||
/** @param error - Error object. */
|
||||
(error: WebSocketError): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message event handler.
|
||||
* @public
|
||||
*/
|
||||
export interface MessageEventHandler {
|
||||
/** @param message - Message. */
|
||||
(message: string): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open event handler.
|
||||
* @public
|
||||
*/
|
||||
export interface OpenEventHandler {
|
||||
(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ping event handler.
|
||||
* @public
|
||||
*/
|
||||
export interface PingEventHandler {
|
||||
(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pong event handler.
|
||||
* @public
|
||||
*/
|
||||
export interface PongEventHandler {
|
||||
(): void;
|
||||
}
|
||||
|
||||
// === Error ===
|
||||
// -------------
|
||||
|
||||
/**
|
||||
* Error.
|
||||
* @public
|
||||
*/
|
||||
export abstract class WebSocketError {
|
||||
protected __brand: never;
|
||||
|
||||
/** Error message. */
|
||||
error(): string;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user