mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
Add optics-agent typings (#13457)
* Add optics-agent * Remove namespace and use default tslint tsconfig * Set no implicit this to true
This commit is contained in:
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
// Type definitions for optics-agent 1.0
|
||||
// Project: https://github.com/apollostack/optics-agent-js#readme
|
||||
// Definitions by: Crevil <https://github.com/crevil>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { GraphQLSchema } from "graphql";
|
||||
import { Request, Response } from "express";
|
||||
import { Server } from "hapi";
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* Your API key for the Optics service.
|
||||
*
|
||||
* This defaults to the OPTICS_API_KEY environment variable, but can be overridden here.
|
||||
*/
|
||||
apiKey?: string;
|
||||
|
||||
/**
|
||||
* Called to determine the query shape for for a GraphQL query.
|
||||
*
|
||||
* You shouldn't need to set this unless you are debugging.
|
||||
*/
|
||||
normalizeQuery?: (graphQLResolveInfo: any) => string;
|
||||
|
||||
/**
|
||||
* Where to send the reports. Defaults to the production Optics endpoint, or the OPTICS_ENDPOINT_URL environment variable if it is set.
|
||||
*
|
||||
* You shouldn't need to set this unless you are debugging.
|
||||
*/
|
||||
endpointUrl?: string;
|
||||
|
||||
/**
|
||||
* HTTP proxy to use when sending reports. Default to no proxying, or the HTTPS_PROXY environment variable if it is set.
|
||||
*
|
||||
* You should only set this when your servers cannot connect directly to the Optics service.
|
||||
*/
|
||||
proxyUrl?: string;
|
||||
|
||||
/**
|
||||
* How often to send reports in milliseconds. Defaults to 1 minute. Minimum 10 seconds.
|
||||
*
|
||||
* You shouldn't need to set this unless you are debugging.
|
||||
*/
|
||||
reportIntervalMs?: number;
|
||||
|
||||
/**
|
||||
* Print a JSON version of reports as they are sent. This may be useful for debugging. Defaults to false.
|
||||
*/
|
||||
printReports?: boolean;
|
||||
|
||||
/**
|
||||
* Send detailed traces along with usage reports. Defaults to true.
|
||||
*/
|
||||
reportTraces?: boolean;
|
||||
|
||||
/**
|
||||
* Send the query variables along with traces. Defaults to true.
|
||||
*/
|
||||
reportVariables?: boolean;
|
||||
}
|
||||
|
||||
export class Agent {
|
||||
constructor(options: Options);
|
||||
|
||||
configureAgent(options: Options): Agent;
|
||||
instrumentSchema(schema: GraphQLSchema): void;
|
||||
middleware(): (req: Request, res: Response, next?: any) => void;
|
||||
instrumentHapiServer(server: Server): void;
|
||||
context(req: Request): any;
|
||||
}
|
||||
|
||||
export function configureAgent(options: Options): Agent;
|
||||
export function instrumentSchema(schema: GraphQLSchema): void;
|
||||
export function middleware(): (req: Request, res: Response, next?: any) => void;
|
||||
export function instrumentHapiServer(server: Server): void;
|
||||
export function context(req: Request): any;
|
||||
|
||||
export default {
|
||||
configureAgent,
|
||||
instrumentSchema,
|
||||
middleware,
|
||||
instrumentHapiServer,
|
||||
context,
|
||||
Agent,
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
import OpticsAgent, {
|
||||
configureAgent,
|
||||
instrumentSchema,
|
||||
middleware,
|
||||
instrumentHapiServer,
|
||||
context,
|
||||
} from 'optics-agent';
|
||||
import { GraphQLSchema } from 'graphql';
|
||||
import * as express from 'express';
|
||||
import * as hapi from 'hapi';
|
||||
var OpticsAgentRequired = require('optics-agent');
|
||||
|
||||
const configOptions = {
|
||||
apiKey: "",
|
||||
reportTraces: false,
|
||||
reportVariables: false,
|
||||
printReports: false,
|
||||
normalizeQuery: (info: any) => "",
|
||||
endpointUrl: "",
|
||||
proxyUrl: "",
|
||||
reportIntervalMs: 1,
|
||||
};
|
||||
OpticsAgent.configureAgent(configOptions)
|
||||
|
||||
let expressServer = express();
|
||||
expressServer.use(OpticsAgent.middleware());
|
||||
|
||||
let hapiServer = new hapi.Server();
|
||||
OpticsAgent.instrumentHapiServer(hapiServer);
|
||||
|
||||
let req = {} as express.Request;
|
||||
OpticsAgent.context(req);
|
||||
|
||||
const agent = new OpticsAgent.Agent({ apiKey: '1234' });
|
||||
|
||||
let schema = {} as GraphQLSchema;
|
||||
agent.instrumentSchema(schema);
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"optics-agent-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user