Skip to content

Commit 1520693

Browse files
authored
🤖 Merge PR DefinitelyTyped#74533 [mokapi] Update typings to v0.34.0 by @marle3003
1 parent 037871b commit 1520693

File tree

5 files changed

+122
-8
lines changed

5 files changed

+122
-8
lines changed

types/mokapi/file.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Reads the contents of a file and returns it as a string.
3+
*
4+
* If the path is relative, it is resolved relative to the entry script file.
5+
*
6+
* @param path - Path to the file to read.
7+
* @returns The contents of the file.
8+
*
9+
* @example
10+
* export default function() {
11+
* const data = read('data.json')
12+
* console.log(data)
13+
* }
14+
*/
15+
export function read(path: string): string;
16+
17+
/**
18+
* Writes a string to a file at the given path.
19+
*
20+
* If the path is relative, it is resolved relative to the entry script file.
21+
* If the file does not exist, it will be created.
22+
* If the file exists, it will be overwritten.
23+
*
24+
* @param path - Path to the file to write.
25+
* @param s - The string content to write.
26+
*
27+
* @example
28+
* export default function() {
29+
* writeString('data.json', 'Hello World')
30+
* }
31+
*/
32+
export function writeString(path: string, s: string): void;
33+
34+
/**
35+
* Appends a string to a file at the given path.
36+
*
37+
* If the path is relative, it is resolved relative to the entry script file.
38+
* If the file does not exist, it will be created.
39+
* If the file exists, the string will be appended.
40+
*
41+
* @param path - Path to the file to append to.
42+
* @param s - The string content to append.
43+
*
44+
* @example
45+
* export default function() {
46+
* writeString('data.json', 'Hello')
47+
* appendString('data.json', ' World')
48+
* }
49+
*/
50+
export function appendString(path: string, s: string): void;

types/mokapi/index.d.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Mokapi JavaScript API
3-
* https://mokapi.io/docs/guides/welcome
3+
* https://mokapi.io/docs/welcome
44
*/
55

66
import "./faker";
@@ -10,6 +10,7 @@ import "./mustache";
1010
import "./yaml";
1111
import "./encoding";
1212
import "./mail";
13+
import "./file";
1314

1415
/**
1516
* Attaches an event handler for the given event.
@@ -157,6 +158,9 @@ export interface HttpRequest {
157158
/** Object contains querystring parameters specified by OpenAPI querystring parameters. */
158159
readonly querystring: any;
159160

161+
/** Name of the API, as defined in the OpenAPI `info.title` field */
162+
readonly api: string;
163+
160164
/** Path value specified by the OpenAPI path */
161165
readonly key: string;
162166

@@ -183,6 +187,23 @@ export interface HttpResponse {
183187

184188
/** Data will be encoded with the OpenAPI response definition. */
185189
data: any;
190+
191+
/**
192+
* Rebuilds the entire HTTP response using the OpenAPI response definition for the given status code and content type
193+
* @example
194+
* import { on } from 'mokapi'
195+
*
196+
* export default function() {
197+
* on('http', (request, response) => {
198+
* if (request.path.petId === 10) {
199+
* // Switch to a different OpenAPI response.
200+
* response.rebuild(404, 'application/json')
201+
* response.data.message = 'Pet not found'
202+
* }
203+
* })
204+
* }
205+
*/
206+
rebuild: (statusCode?: number, contentType?: string) => void;
186207
}
187208

188209
/**
@@ -421,10 +442,11 @@ export type DateLayout =
421442
| "RFC3339Nano";
422443

423444
/**
424-
* EventArgs object contains additional arguments for an event handler.
445+
* EventArgs provides optional configuration for an event handler.
425446
* https://mokapi.io/docs/javascript-api/mokapi/on
426447
*
427-
* Use this to customize how the event appears in the dashboard or to control tracking.
448+
* Use this object to control how the event is tracked, labeled,
449+
* and ordered in the execution pipeline.
428450
*
429451
* @example
430452
* export default function() {
@@ -438,16 +460,32 @@ export type DateLayout =
438460
*/
439461
export interface EventArgs {
440462
/**
441-
* Adds or overrides existing tags used to label the event in dashboard
463+
* Adds or overrides tags used to label this event in the dashboard.
464+
* Tags can be used for filtering, grouping, or ownership attribution.
442465
*/
443466
tags?: { [key: string]: string };
444467

445468
/**
446-
* Set to `true` to enable tracking of this event handler in the dashboard.
447-
* Set to `false` to disable tracking. If omitted, Mokapi checks the response
448-
* object to determine if the handler changed it, and tracks it accordingly.
469+
* Controls whether this event handler is tracked in the dashboard.
470+
*
471+
* - true: always track this handler
472+
* - false: never track this handler
473+
* - undefined: Mokapi determines tracking automatically based on
474+
* whether the response object was modified by the handler
449475
*/
450476
track?: boolean;
477+
478+
/**
479+
* Defines the execution order of the event handler.
480+
*
481+
* Handlers with higher priority values run first.
482+
* Handlers with lower priority values run later.
483+
*
484+
* Use negative priorities (e.g. -1) to run a handler after
485+
* the response has been fully populated by other handlers,
486+
* such as for logging or recording purposes.
487+
*/
488+
priority?: number;
451489
}
452490

453491
/**

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.29.9999",
4+
"version": "0.34.9999",
55
"nonNpm": true,
66
"nonNpmDescription": "Mokapi",
77
"projects": [

types/mokapi/test/file-test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { appendString, read, writeString } from "mokapi/file";
2+
3+
// @ts-expect-error
4+
read(123);
5+
read("data.json");
6+
// @ts-expect-error
7+
const i: number = read("data.json");
8+
const s: string = read("data.json");
9+
10+
writeString("data.txt", "Hello World");
11+
// @ts-expect-error
12+
writeString("data.txt", 123);
13+
14+
appendString("data.txt", "Hello Again");
15+
// @ts-expect-error
16+
appendString("data.txt", 123);

types/mokapi/test/mokapi-tests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,29 @@ on("http", handler, "");
4646
on("http", handler, {});
4747
on("http", handler, { tags: { foo: "bar" } });
4848
on("http", handler, { track: true });
49+
on("http", handler, { priority: 12 });
50+
// @ts-expect-error
51+
on("http", handler, { priority: true });
4952
on("http", async () => {});
5053
on("http", (request) => {
5154
request.querystring;
5255
});
5356
on("http", (request, response) => {
5457
const s = request.toString();
5558
const url = request.url.toString();
59+
const api: string = request.api;
5660

5761
response.headers = {
5862
"Content-Type": "application/json",
5963
};
6064
response.headers["Access-Control-Allow-Origin"] = "*";
6165
response.headers["foo"] = { bar: 123 };
66+
67+
response.rebuild(200, "application/json");
68+
// @ts-expect-error
69+
response.rebuild("200", "application/json");
70+
// @ts-expect-error
71+
response.rebuild(200, {});
6272
});
6373

6474
// @ts-expect-error

0 commit comments

Comments
 (0)