Skip to content

Commit f86691f

Browse files
codebieninancgumusolegbespalovmstoykov
authored
🤖 Merge PR DefinitelyTyped#72052 [@types/k6] Update k6 for the latest version v1.0.0 by @codebien
Co-authored-by: İnanç Gümüş <[email protected]> Co-authored-by: Oleg Bespalov <[email protected]> Co-authored-by: Mihail Stoykov <[email protected]>
1 parent 06d5061 commit f86691f

File tree

6 files changed

+111
-1
lines changed

6 files changed

+111
-1
lines changed

‎types/k6/browser/index.d.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,36 @@ export interface Page {
30363036
*/
30373037
on(event: "metric", listener: (metricMessage: MetricMessage) => void): void;
30383038

3039+
/**
3040+
* Registers a handler function to listen for the network requests that
3041+
* the page makes. The handler will receive an instance of {@link Request},
3042+
* which includes information about the request.
3043+
*
3044+
* **Usage**
3045+
*
3046+
* ```js
3047+
* page.on('request', request => {
3048+
* console.log(request.url());
3049+
* });
3050+
* ```
3051+
*/
3052+
on(event: "request", listener: (request: Request) => void): void;
3053+
3054+
/**
3055+
* Registers a handler function to listen for the network responses that the
3056+
* page receives. The handler will receive an instance of {@link Response},
3057+
* which includes information about the response.
3058+
*
3059+
* **Usage**
3060+
*
3061+
* ```js
3062+
* page.on('response', response => {
3063+
* console.log(response.url());
3064+
* });
3065+
* ```
3066+
*/
3067+
on(event: "response", listener: (response: Response) => void): void;
3068+
30393069
/**
30403070
* Returns the page that opened the current page. The first page that is
30413071
* navigated to will have a null opener.

‎types/k6/experimental/webcrypto/index.d.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
* https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/webcrypto/
66
*/
77

8+
/**
9+
* @deprecated use global crypto instead.
10+
*/
811
export const crypto: Crypto;
912

13+
/**
14+
* @deprecated use global crypto instead.
15+
*/
1016
export interface Crypto extends SubtleCrypto {
1117
/**
1218
* Returns a SubtleCrypto object providing access to common cryptographic
1319
* primitives, like hashing, signing, encryption, or decryption.
20+
*
21+
* @deprecated use global crypto.subtle instead.
1422
*/
1523
readonly subtle: SubtleCrypto;
1624

@@ -20,17 +28,24 @@ export interface Crypto extends SubtleCrypto {
2028
* @param typedArray - The TypedArray to fill with random values.
2129
* @throws {QuotaExceededError} - thrown if the `byteLength` of `typedArray` exceeds 65536.
2230
* @returns The typedArray argument.
31+
*
32+
* @deprecated use global crypto.getRandomValues crypto instead.
2333
*/
2434
getRandomValues(typedArray: TypedArray): TypedArray;
2535

2636
/**
2737
* Returns a 36 character long string containing a cryptographically random UUID v4.
2838
*
2939
* @returns A 36 character long string containing a cryptographically random UUID v4.
40+
*
41+
* @deprecated use global crypto.randomUUID instead.
3042
*/
3143
randomUUID(): string;
3244
}
3345

46+
/**
47+
* @deprecated use global crypto.subtle instead.
48+
*/
3449
export interface SubtleCrypto {
3550
/**
3651
* The `decrypt()` method decrypts some encrypted data.
@@ -41,6 +56,7 @@ export interface SubtleCrypto {
4156
* @throws {InvalidAccessError} - if the provided key cannot be used for the decrypt operation.
4257
* @throws {OperationError} - if the operation failed for an operation-specific reason.
4358
* @returns A promise that resolves with the decrypted data (also known as "plaintext").
59+
* @deprecated use global crypto.subtle.decrypt instead.
4460
*/
4561
decrypt(
4662
algorithm: AesCtrParams | AesCbcParams | AesGcmParams | RsaOaepParams,
@@ -63,6 +79,7 @@ export interface SubtleCrypto {
6379
* @param algorithm names the algorithm to use.
6480
* @param data the data to be digested
6581
* @returns A promise that resolves with the digest value.
82+
* @deprecated use global crypto.subtle.digest instead.
6683
*/
6784
digest(
6885
algorithm: HashAlgorithmIdentifier | Algorithm<HashAlgorithmIdentifier>,
@@ -78,6 +95,7 @@ export interface SubtleCrypto {
7895
* @throws {InvalidAccessError} - if the provided key cannot be used for the encrypt operation.
7996
* @throws {OperationError} - if the operation failed for an operation-specific reason.
8097
* @returns A promise that resolves with the encrypted data (also known as "ciphertext").
98+
* @deprecated use global crypto.subtle.encrypt instead.
8199
*/
82100
encrypt(
83101
algorithm: AesCtrParams | AesCbcParams | AesGcmParams | RsaOaepParams,
@@ -97,6 +115,7 @@ export interface SubtleCrypto {
97115
* @throws {NotSupportedError} - if the format is not supported.
98116
* @throws {TypeError} - when trying to use an invalid format.
99117
* @returns A promise that resolves with the exported key.
118+
* @deprecated use global crypto.subtle.exportKey instead.
100119
*/
101120
exportKey(format: "raw" | "jwk" | "spki" | "pkcs8", key: CryptoKey): Promise<ArrayBuffer | JWK>;
102121

@@ -108,6 +127,7 @@ export interface SubtleCrypto {
108127
* @param keyUsages indicates what can be done with the newly generated key.
109128
* @throws {SyntaxError} - if the result is a `CryptoKey` of type `secret` or `private` but `keyUsages is empty.
110129
* @returns A promise that resolves with the newly generated `CryptoKey`.
130+
* @deprecated use global crypto.subtle.generateKey instead.
111131
*/
112132
generateKey(
113133
algorithm: AesKeyGenParams | HmacKeyGenParams,
@@ -123,6 +143,7 @@ export interface SubtleCrypto {
123143
* @param keyUsages indicates what can be done with the newly generated key.
124144
* @throws {SyntaxError} - if the result is a `CryptoKey` of type `secret` or `private` but `keyUsages is empty.
125145
* @returns A promise that resolves with the newly generated `CryptoKeyPair`.
146+
* @deprecated use global crypto.subtle.generateKey instead.
126147
*/
127148
generateKey(
128149
algorithm: EcKeyGenParams | RSAHashedKeyGenParams,
@@ -143,6 +164,7 @@ export interface SubtleCrypto {
143164
* @throws {SyntaxError} - if the result is a `CryptoKey` of type `secret` or `private` but `keyUsages is empty.
144165
* @throws {TypeError} - when trying to use an invalid format or if the `keyData` is not suited for that format.
145166
* @returns A promise that resolves with the imported `CryptoKey`.
167+
* @deprecated use global crypto.subtle.importKey instead.
146168
*/
147169
importKey(
148170
format: "raw" | "jwk" | "spki" | "pkcs8",
@@ -170,6 +192,7 @@ export interface SubtleCrypto {
170192
* @param data the data to sign.
171193
* @throws {InvalidAccessError} - if the provided key cannot be used for the sign operation.
172194
* @returns A promise that resolves with the signature.
195+
* @deprecated use global crypto.subtle.sign instead.
173196
*/
174197
sign(
175198
algorithm: "HMAC" | Algorithm<"HMAC"> | EcdsaParams | RsaPssParams,
@@ -186,6 +209,7 @@ export interface SubtleCrypto {
186209
* @param data the data to verify.
187210
* @throws {InvalidAccessError} - if the provided key cannot be used for the verify operation.
188211
* @returns A promise that resolves with a boolean indicating whether the signature is valid.
212+
* @deprecated use global crypto.subtle.verify instead.
189213
*/
190214
verify(
191215
algorithm: "HMAC" | Algorithm<"HMAC"> | EcdsaParams | RsaPssParams,
@@ -200,6 +224,7 @@ export interface SubtleCrypto {
200224
* @param algorithm defines the derivation algorithm to use.
201225
* @param baseKey A `CryptoKey` representing the input to the derivation algorithm. Currently, only an ECDH private key is possible.
202226
* @param length A number representing the number of bits to derive. Currently, the number should be a multiple of 8.
227+
* @deprecated use global crypto.subtle.deriveBits instead.
203228
*/
204229
deriveBits(
205230
algorithm: EcdhKeyDeriveParams,

‎types/k6/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/k6",
4-
"version": "0.57.9999",
4+
"version": "1.0.9999",
55
"type": "module",
66
"projects": [
77
"https://grafana.com/docs/k6/latest/"
@@ -21,6 +21,7 @@
2121
"./execution": "./execution/index.d.ts",
2222
"./encoding": "./encoding/index.d.ts",
2323
"./data": "./data/index.d.ts",
24+
"./secrets": "./secrets/index.d.ts",
2425
"./crypto": "./crypto/index.d.ts",
2526
"./browser": "./browser/index.d.ts",
2627
"./experimental/csv": "./experimental/csv/index.d.ts",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* This module provides a way to access secrets provided by secret sources
3+
*/
4+
5+
declare abstract class SecretSource {
6+
/**
7+
* get a secret from the default secret source if such is setup
8+
*
9+
* @param key - the key for the secret
10+
* @returns a promise that will resolve to a string.
11+
*/
12+
get(key: string): Promise<string>;
13+
}
14+
15+
/**
16+
* get a secret from the default secret source if such is setup
17+
*
18+
* @param key - the key for the secret
19+
* @returns a promise that will resolve to a string.
20+
*/
21+
declare function get(key: string): Promise<string>;
22+
23+
/**
24+
* returns a secret source for the provided name
25+
*
26+
* @param name - the name the secret source set with
27+
* @returns a source with the name.
28+
*/
29+
declare function source(name: string): SecretSource;
30+
31+
declare const _default: {
32+
"get": typeof get,
33+
"source": typeof source,
34+
}
35+
36+
export default _default;

‎types/k6/test/secrets.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import secrets from "k6/secrets";
2+
3+
await secrets.get("some") // $ExpectType string
4+
5+
// @ts-expect-error
6+
secrets.get(3)
7+
8+
// @ts-expect-error
9+
secrets.get("some", true)
10+
11+
secrets.source("some") // $ExpectType SecretSource
12+
13+
// @ts-expect-error
14+
secrets.source(3)
15+
16+
await secrets.source("some").get("three") // $ExpectType string

‎types/k6/tsconfig.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"execution/index.d.ts",
3030
"encoding/index.d.ts",
3131
"data/index.d.ts",
32+
"secrets/index.d.ts",
3233
"crypto/index.d.ts",
3334
"browser/index.d.ts",
3435

@@ -57,6 +58,7 @@
5758
"test/crypto.ts",
5859
"test/http.ts",
5960
"test/websockets.ts",
61+
"test/secrets.ts",
6062
"test/redis.ts",
6163
"test/global.ts"
6264
]

0 commit comments

Comments
 (0)