Skip to content

Commit e17a183

Browse files
uchilakaandrewbranch
authored andcommitted
(apimocker:new) new type definition for apimocker library (DefinitelyTyped#36952)
* (lib) initial source for @types/apimocker * (test) typical, documented use case * (cleanup) prep for PR * (apimocker) updates * (apimocker) fixed sample code * (apimocker:refactor) fixes from linting notes * (apimocker:check) generated with dts-gen & tweaked * (apimocker:build) wip to fix CI build * (apimocker:build) fixed header formatting * (apimocker:build) removed .gitignore * (apimocker:build) tweaks * (apimocker:wip) tslint.json issues * (apimocker:build) added package.json & ts3.1/* * (apimocker:refactor) tweaks to fix build * (apimocker:build) removed offending test * (apimocker:build) Removed unused file * (apimocker:refactor) more build fixes 😭 * (feedback) cleanup comments & removed package.json * (feedback) more tweaks from review notes
1 parent fccea92 commit e17a183

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

types/apimocker/apimocker-tests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as ApiMocker from 'apimocker';
2+
3+
const PORT = 7878;
4+
5+
// $ExpectType ApiMocker
6+
const server = ApiMocker.createServer({ quiet: false });
7+
8+
// $ExpectType ApiMocker
9+
server.start(PORT, () => {
10+
console.log(`API mocker started successfully @${PORT}`);
11+
12+
// $ExpectType ApiMocker
13+
server.stop(() => console.log('API mocker stopped successully'));
14+
});

types/apimocker/index.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Type definitions for apimocker 1.1
2+
// Project: https://www.npmjs.com/package/apimocker
3+
// Definitions by: Uchenna <https://github.com/uchilaka>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
// TypeScript Version: 2.2
6+
7+
import { RequestHandler, Application } from 'express';
8+
9+
export interface ConfigOptions {
10+
port?: string;
11+
mockDirectory?: string;
12+
allowedDomains?: string[];
13+
allowedHeaders?: string[];
14+
logRequestHeaders?: boolean;
15+
allowAvoidPreFlight?: boolean;
16+
useUploadFieldname?: boolean;
17+
webServices?: any;
18+
quiet?: boolean;
19+
}
20+
21+
export interface ApiMocker {
22+
express: Application;
23+
middlewares: RequestHandler[];
24+
setConfigFile: (file: string) => ApiMocker;
25+
loadConfigFile: () => void;
26+
setRoutes: (webServices: any) => void;
27+
/**
28+
* Set the route for express, in case it was not set yet
29+
*/
30+
setRoute: (options: any) => void;
31+
/**
32+
* Start a new instance of API Mocker
33+
*/
34+
start: (serverPort: string | number, callback?: () => void) => ApiMocker;
35+
/**
36+
* Stop the referenced instance of API Mocker
37+
*/
38+
stop: (callback?: () => void) => ApiMocker;
39+
}
40+
41+
export const middlewares: RequestHandler[];
42+
43+
export function createServer(options?: ConfigOptions): ApiMocker;
44+
45+
export function setConfigFile(file: string): ApiMocker;
46+
47+
export function start(serverPort: string | number, callback?: () => void): ApiMocker;
48+
49+
export function stop(callback?: () => void): ApiMocker;

types/apimocker/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["es6"],
5+
"baseUrl": "../",
6+
"typeRoots": ["../"],
7+
"types": [],
8+
"noEmit": true,
9+
"noImplicitAny": true,
10+
"noImplicitThis": true,
11+
"strictNullChecks": true,
12+
"strictFunctionTypes": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"apimocker-tests.ts"
18+
]
19+
}

types/apimocker/tslint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "dtslint/dt.json"
3+
}

0 commit comments

Comments
 (0)