Skip to content

Commit fa0a549

Browse files
authored
🤖 Merge PR DefinitelyTyped#74051 [mokapi] Update typings to v0.29.0 by @marle3003
1 parent 2dc1ca1 commit fa0a549

File tree

11 files changed

+288
-22
lines changed

11 files changed

+288
-22
lines changed

types/mokapi/faker.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
export function fake(schema: Schema | JSONSchema): any;
1414

1515
/**
16-
* Retrieves a node from the faker tree by its name.
16+
* Retrieves a node from the faker tree by its name or path.
1717
*
18-
* @param name name - The name of the node to find.
18+
* A node can be referenced either by its simple name (e.g. `"name"`) or by a path
19+
* that describes its location in the tree (e.g. `"/person/name"` for an absolute
20+
* path from the root, or `"middle/name"` for a relative path).
21+
*
22+
* @param name name - The name or path of the node to find.
1923
* @returns The matching {@link Node} from the faker tree.
2024
*
2125
* @example
@@ -392,4 +396,4 @@ export interface Schema {
392396

393397
/** Specifies whether all items in an array must be unique. */
394398
uniqueItems?: boolean;
395-
}
399+
}

types/mokapi/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ declare global {
2424
*/
2525
as: "binary" | "string" | "resolved";
2626
}
27-
}
27+
}

types/mokapi/http.d.ts

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,105 @@ export function del(url: string, body?: JSONValue, args?: Args): Response;
8686
*/
8787
export function options(url: string, body?: JSONValue, args?: Args): Response;
8888

89+
/**
90+
* Sends an HTTP request and returns a Promise resolving to the response.
91+
*
92+
* @param {string} url - The URL to request.
93+
* @param {FetchOptions} opts - Optional fetch configuration.
94+
* @returns {Promise<Response>} A Promise that resolves with the response.
95+
*
96+
* @example
97+
* // Simple GET request
98+
* const res = await fetch('https://foo.bar/api');
99+
* const data = await res.json();
100+
*
101+
* @example
102+
* // POST request with JSON body
103+
* const res = await fetch('https://foo.bar/api', {
104+
* method: 'POST',
105+
* headers: { 'Content-Type': 'application/json' },
106+
* body: { name: 'Alice' }
107+
* });
108+
*
109+
* @example
110+
* // Request with timeout and redirect settings
111+
* const res = await fetch('https://foo.bar/api', {
112+
* timeout: '5s',
113+
* maxRedirects: 2
114+
* });
115+
*/
116+
export function fetch(url: string, opts?: FetchOptions): Promise<Response>
117+
89118
/**
90119
* Request arguments.
91120
* Used to add headers to a request.
92121
*/
93122
export interface Args {
94123
/** Request headers. */
95-
header?: { [name: string]: string };
124+
headers?: { [name: string]: string };
125+
/**
126+
* The number of redirects to follow for this request.
127+
* @default 5
128+
**/
129+
maxRedirects?: number
130+
/**
131+
* Maximum time to wait for the request to complete. Default
132+
* timeout is 60 seconds ("60s"). The type can also be a number, in which
133+
* case Mokapi interprets it as milliseconds
134+
* @example
135+
* const res = get(url, { timeout: '5m' })
136+
*/
137+
timeout?: number | string
138+
}
139+
140+
/**
141+
* Options for the {@link fetch} function.
142+
*/
143+
export interface FetchOptions {
144+
/**
145+
* HTTP method to use for the request.
146+
* @default "GET"
147+
* @example
148+
* const res = await fetch(url, { method: 'POST' });
149+
*/
150+
method?: string
151+
152+
/**
153+
* The body of the request, such as a string or object.
154+
* @example
155+
* const res = await fetch(url, { body: JSON.stringify({ name: 'Alice' }) });
156+
*/
157+
body?: any
158+
159+
/**
160+
* Request headers.
161+
* @example
162+
* const res = await fetch(url, {
163+
* headers: { 'Authorization': 'Bearer token123' }
164+
* });
165+
*/
166+
headers?: { [name: string]: string };
167+
168+
/**
169+
* The number of redirects to follow for this request.
170+
* @default 5
171+
* @example
172+
* const res = await fetch(url, { maxRedirects: 1 });
173+
**/
174+
maxRedirects?: number
175+
176+
/**
177+
* Maximum time to wait for the request to complete. Default
178+
* timeout is 60 seconds ("60s"). The type can also be a number, in which
179+
* case Mokapi interprets it as milliseconds
180+
* @default "60s"
181+
* @example
182+
* const res = get(url, { timeout: '5m' })
183+
* @example
184+
* // Timeout as milliseconds
185+
* const res = await fetch(url, { timeout: 3000 });
186+
*/
187+
timeout?: number | string
96188
}
97189

98190
/**
@@ -117,4 +209,4 @@ export interface Response {
117209
* res.json()
118210
*/
119211
json(): JSONValue;
120-
}
212+
}

types/mokapi/index.d.ts

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export type HttpEventHandler = (request: HttpRequest, response: HttpResponse) =>
130130
* https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httprequest
131131
*/
132132
export interface HttpRequest {
133-
/** Request method. */
133+
/**
134+
* Request method.
135+
* @example GET
136+
* */
134137
readonly method: string;
135138

136139
/** Represents a parsed URL. */
@@ -151,6 +154,9 @@ export interface HttpRequest {
151154
/** Object contains cookie parameters specified by OpenAPI cookie parameters. */
152155
readonly cookie: { [key: string]: any };
153156

157+
/** Object contains querystring parameters specified by OpenAPI querystring parameters. */
158+
readonly querystring: any;
159+
154160
/** Path value specified by the OpenAPI path */
155161
readonly key: string;
156162

@@ -406,13 +412,33 @@ export type DateLayout =
406412
| "RFC3339Nano";
407413

408414
/**
409-
* Additional event arguments
415+
* EventArgs object contains additional arguments for an event handler.
416+
* https://mokapi.io/docs/javascript-api/mokapi/on
417+
*
418+
* Use this to customize how the event appears in the dashboard or to control tracking.
419+
*
420+
* @example
421+
* export default function() {
422+
* on('http', function(req, res) {
423+
* res.data = { message: "tracked event" }
424+
* }, {
425+
* tags: { feature: 'beta', owner: 'team-a' },
426+
* track: true
427+
* })
428+
* }
410429
*/
411430
export interface EventArgs {
412431
/**
413-
* Adds or overrides existing tags used in dashboard
432+
* Optional key-value pairs used to label the event in the dashboard.
414433
*/
415434
tags?: { [key: string]: string };
435+
436+
/**
437+
* Set to `true` to enable tracking of this event handler in the dashboard.
438+
* If omitted, Mokapi automatically checks whether the response object has
439+
* been modified and tracks the handler only if a change is detected.
440+
*/
441+
track?: boolean;
416442
}
417443

418444
/**
@@ -510,3 +536,99 @@ export function patch(target: any, patch: any): any;
510536
* // result: { name: "foo" }
511537
*/
512538
export const Delete: unique symbol;
539+
540+
export interface SharedMemory {
541+
/**
542+
* Returns the value associated with the given key.
543+
* @param key The key to retrieve.
544+
* @returns The stored value, or `undefined` if not found.
545+
*/
546+
get(key: string): any
547+
548+
/**
549+
* Sets a value for the given key.
550+
* If the key already exists, its value will be replaced.
551+
* @param key The key to store the value under.
552+
* @param value The value to store.
553+
*/
554+
set(key: string, value: any): void
555+
556+
/**
557+
* Updates a value atomically using an updater function.
558+
* The current value is passed into the updater function.
559+
* The returned value is stored and also returned by this method.
560+
*
561+
* Example:
562+
* ```js
563+
* mokapi.shared.update("requests", count => (count ?? 0) + 1)
564+
* ```
565+
*
566+
* @param key The key to update.
567+
* @param updater Function that receives the current value and returns the new value.
568+
* @returns The new value after update.
569+
*/
570+
update<T = any>(key: string, updater: (value: T | undefined) => T): T
571+
572+
/**
573+
* Checks if the given key exists in shared memory.
574+
* @param key The key to check.
575+
* @returns `true` if the key exists, otherwise `false`.
576+
*/
577+
has(key: string): boolean
578+
579+
/**
580+
* Removes the specified key and its value from shared memory.
581+
* @param key The key to remove.
582+
*/
583+
delete(key: string): void
584+
585+
/**
586+
* Removes all stored entries from shared memory.
587+
* Use with caution — this clears all shared state.
588+
*/
589+
clear(): void
590+
591+
/**
592+
* Returns a list of all stored keys.
593+
* @returns An array of key names.
594+
*/
595+
keys(): string[]
596+
597+
/**
598+
* Creates or returns a namespaced shared memory store.
599+
* Namespaces help avoid key collisions between unrelated scripts.
600+
*
601+
* Example:
602+
* ```js
603+
* const petstore = mokapi.shared.namespace("petstore")
604+
* petstore.set("sessions", [])
605+
* ```
606+
*
607+
* @param name The namespace identifier.
608+
* @returns A `SharedMemory` object scoped to the given namespace.
609+
*/
610+
namespace(name: string): SharedMemory
611+
}
612+
613+
/**
614+
* Shared memory API for Mokapi scripts.
615+
*
616+
* The `mokapi.shared` object provides a way to persist and share
617+
* data between multiple scripts running in the same Mokapi instance.
618+
*
619+
* Values are stored in memory and shared across all scripts.
620+
* This allows you to coordinate state, cache data, or simulate
621+
* application-level variables without using global variables.
622+
* All values are persisted for the lifetime of the Mokapi process.
623+
*
624+
* Example:
625+
* ```js
626+
* // Increment a shared counter
627+
* mokapi.shared.update("counter", c => (c ?? 0) + 1)
628+
*
629+
* // Retrieve the current counter value
630+
* const count = mokapi.shared.get("counter")
631+
* mokapi.log(`Current counter: ${count}`)
632+
* ```
633+
*/
634+
export const shared: SharedMemory

types/mokapi/kafka.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,4 @@ export interface ProduceRetry {
243243
* @default 5
244244
*/
245245
retries: number;
246-
}
246+
}

types/mokapi/mail.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ export interface Attachment {
7878

7979
/** File data as binary content */
8080
data: Uint8Array;
81-
}
81+
}

types/mokapi/mustache.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ export interface ScopeObject {
3131
[key: string]: Scope | ScopeFunction;
3232
}
3333

34-
export type ScopeFunction = () => Scope;
34+
export type ScopeFunction = () => Scope;

types/mokapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/mokapi",
4-
"version": "0.20.9999",
4+
"version": "0.29.9999",
55
"nonNpm": true,
66
"nonNpmDescription": "Mokapi",
77
"projects": [

0 commit comments

Comments
 (0)