mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
@pollyjs/node-server types (#38597)
This commit is contained in:
committed by
Ben Lichtman
parent
100f71247f
commit
f966375bc7
+43
@@ -0,0 +1,43 @@
|
||||
// Type definitions for @pollyjs/node-server 2.6
|
||||
// Project: https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/node-server
|
||||
// Definitions by: Offir Golan <https://github.com/offirgolan>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import * as http from 'http';
|
||||
import * as express from 'express';
|
||||
|
||||
export interface Config {
|
||||
port: number;
|
||||
quiet: boolean;
|
||||
recordingSizeLimit: string;
|
||||
recordingsDir: string;
|
||||
apiNamespace: string;
|
||||
}
|
||||
|
||||
export const Defaults: Config;
|
||||
|
||||
export interface APIResponse {
|
||||
status: number;
|
||||
body?: any;
|
||||
}
|
||||
|
||||
export class API {
|
||||
constructor(options: Pick<Config, 'recordingsDir'>);
|
||||
getRecordings(recording: string): APIResponse;
|
||||
saveRecording(recording: string, data: any): APIResponse;
|
||||
deleteRecording(recording: string): APIResponse;
|
||||
filenameFor(recording: string): string;
|
||||
respond(status: number, data?: any): APIResponse;
|
||||
}
|
||||
|
||||
export class Server {
|
||||
config: Config;
|
||||
app: express.Express;
|
||||
server?: http.Server;
|
||||
|
||||
constructor(options?: Partial<Config>);
|
||||
listen(port?: number, host?: string): http.Server;
|
||||
}
|
||||
|
||||
export function registerExpressAPI(app: express.Express, config: Partial<Config>): void;
|
||||
@@ -0,0 +1,46 @@
|
||||
import * as express from 'express';
|
||||
import { API, Defaults, Server, registerExpressAPI } from '@pollyjs/node-server';
|
||||
|
||||
const api = new API({ recordingsDir: 'recordings' });
|
||||
|
||||
api.getRecordings('id-123');
|
||||
api.saveRecording('id-123', {});
|
||||
api.deleteRecording('id-123');
|
||||
api.filenameFor('id-123');
|
||||
api.respond(200);
|
||||
api.respond(200, {});
|
||||
|
||||
Defaults.apiNamespace;
|
||||
Defaults.port;
|
||||
Defaults.quiet;
|
||||
Defaults.recordingSizeLimit;
|
||||
Defaults.recordingsDir;
|
||||
|
||||
new Server();
|
||||
new Server(Defaults);
|
||||
new Server({ port: 4000, quiet: false });
|
||||
new Server({
|
||||
port: 4000,
|
||||
quiet: false,
|
||||
recordingSizeLimit: '100mb',
|
||||
recordingsDir: 'recordings',
|
||||
apiNamespace: '/api/v2',
|
||||
});
|
||||
|
||||
const server = new Server();
|
||||
|
||||
server.listen();
|
||||
server.listen(3000);
|
||||
server.listen(3000, 'http://localhost');
|
||||
|
||||
server.listen().on('close', () => {});
|
||||
|
||||
server.config;
|
||||
server.app;
|
||||
server.server;
|
||||
|
||||
const app = express();
|
||||
|
||||
registerExpressAPI(app, {});
|
||||
registerExpressAPI(app, { port: 4200 });
|
||||
registerExpressAPI(app, Defaults);
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@pollyjs/node-server": [
|
||||
"pollyjs__node-server"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pollyjs__node-server-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user