Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add TypeScript typings file #926

Merged
merged 46 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ce48671
chore: add TypeScript typings file
watson Mar 16, 2019
1a4a5c1
fix: improve TypeScript thingys
watson Mar 16, 2019
b08ae17
fix: no need for enums I guess
watson Mar 16, 2019
59f379c
fix(typescript): fix the Logger interface
watson Mar 16, 2019
b03e257
refactor(typescript): tidy up
watson Mar 16, 2019
1b634c0
fix(typescript): correct export
watson Mar 17, 2019
a696aa5
fix(ts): filter functions don't need an explicit return
watson Mar 17, 2019
d55d3eb
fix(ts): fix agent.middleware.connect type
watson Mar 17, 2019
05b93c9
fix(ts): improve comments
watson Mar 17, 2019
9f96c6c
fix(ts): fix start.d.ts export
watson Mar 17, 2019
0e43bfc
fix(ts): work on TODOs
watson Mar 17, 2019
188ac2e
fix(ts): improve tag typing
watson Mar 17, 2019
81d3727
fix(ts): allow calling captureError(err, callback)
watson Mar 17, 2019
b8b4741
fix(ts): tidy up
watson Mar 18, 2019
f019574
fix(ts): resolve TODO
watson Mar 18, 2019
25eb4e6
feat(ts): export types and interfaces
watson Mar 20, 2019
f1b7df5
chore(ts): resolve TODO's
watson Mar 20, 2019
750eec8
chore(ts): styling
watson Mar 20, 2019
19a3051
chore(ts): remove trailing whitespace
watson Mar 20, 2019
528954f
chore(ts): simplify Logger interface
watson Mar 20, 2019
ed58e01
chore(ts): revert optimization for Logger interface
watson Mar 20, 2019
dddde1a
test(ts): test types
watson Mar 20, 2019
aecb399
fix(ts): allow flush callback to be optional
watson Mar 20, 2019
76bb22f
chore(ts): resolve TODO's
watson Mar 21, 2019
b0020e1
chore(ts): resolve TODO's
watson Mar 21, 2019
868d71c
chore(ts): resolve TODO's
watson Mar 21, 2019
9820aaf
test(ts): add CommonJS require test
watson Mar 21, 2019
b08be29
fix(ts): improve filtering function types
watson Mar 21, 2019
3149b3c
test(ts): fix style
watson Mar 21, 2019
bc12f77
fix(ts): allow transaction.end(null)
watson Mar 21, 2019
9627c87
test(ts): fix require path
watson Mar 21, 2019
4da895e
fix(ts): fix compatibility with CommonJS
watson Mar 21, 2019
e522c51
test(ts): better config options for running tests
watson Mar 21, 2019
0c7359b
test(ts): improve TypeScript tests
watson Mar 22, 2019
a1942fe
docs(ts): fix
watson Mar 22, 2019
8e57f30
Merge branch 'master' into typescript-typings
watson Mar 22, 2019
85d8d5b
test(ts): clean-up package.json
watson Mar 25, 2019
430c78f
test(esm): add tests for babel and esm exports
watson Mar 25, 2019
63c6c99
test(ts): fix esm tests
watson Mar 25, 2019
341daea
docs(ts): add custom TypeScript anchor
watson Mar 25, 2019
27c006b
fix(ts): inline used @types/connect + @types/aws-lambda types
watson Mar 25, 2019
9f3fc4f
fix(ts): remove unused devDependenies
watson Mar 25, 2019
1b72ef6
docs: don't list support for broken vers of apollo-server-express
watson Mar 25, 2019
1ea56e2
Merge branch 'master' into typescript-typings
watson Mar 25, 2019
41993e6
fix(ts): move inlined types into namespaces
watson Mar 25, 2019
cd091e6
fix(ts): add types for new patch functions
watson Mar 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 45 additions & 27 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,57 @@

import { IncomingMessage, ServerResponse } from 'http';

export declare const agent: Agent;
export default agent;
watson marked this conversation as resolved.
Show resolved Hide resolved

declare class Agent {
middleware: { connect: ConnectMiddlewareFn };
lambda: LambdaFn;
// logger: Logger // TODO: Is this an official API?

currentSpan: Span | null;
currentTransaction: Transaction | null;
declare const agent: Agent;

declare class Agent {
// Configuration
start (options: AgentConfigOptions): Agent;
isStarted (): boolean;

addFilter (fn: FilterFn): void;
addErrorFilter (fn: FilterFn): void;
addSpanFilter (fn: FilterFn): void;
addTransactionFilter (fn: FilterFn): void;
// Data collection hooks
middleware: { connect(): ConnectMiddlewareFn };
lambda: LambdaFn;
handleUncaughtExceptions (fn: UncaughtExceptionFn): void;

captureError (err: Error | string | ParameterizedMessageObject, options?: CaptureErrorOptions, callback?: CaptureErrorCallback): void;

// Errors
captureError (
err: Error | string | ParameterizedMessageObject,
callback?: CaptureErrorCallback
): void;
captureError (
err: Error | string | ParameterizedMessageObject,
options?: CaptureErrorOptions,
callback?: CaptureErrorCallback
): void;

// Transactions
startTransaction (name?: string, type?: string, options?: TransactionOptions): Transaction | null;
setTransactionName (name: string): void;
endTransaction: EndTransactionFn;

currentTransaction: Transaction | null;

// Spans
startSpan: StartSpanFn;
currentSpan: Span | null;

// Context
setTag: SetTagFn; // TODO: Is this how to add a declared function to a class?
addTags: AddTagsFn;
setUserContext (user: UserObject): void;
setCustomContext (custom: object): void;

// Transport
addFilter (fn: FilterFn): void;
addErrorFilter (fn: FilterFn): void;
addSpanFilter (fn: FilterFn): void;
addTransactionFilter (fn: FilterFn): void;
flush (callback: Function): void;
destroy (): void;

// Utils
logger: Logger; // TODO: Should we advertise this API?
watson marked this conversation as resolved.
Show resolved Hide resolved
}

declare class GenericSpan {
Expand Down Expand Up @@ -93,7 +110,7 @@ interface AgentConfigOptions {
logLevel?: LogLevel;
logger?: Logger;
metricsInterval?: string | number; // TODO: Do we officially want to support numbers?
payloadLogFile?: string; // TODO: Do we want to advertise this?
payloadLogFile?: string; // TODO: Should we advertise this API?
watson marked this conversation as resolved.
Show resolved Hide resolved
secretToken?: string;
serverTimeout?: string | number; // TODO: Do we officially want to support numbers?
serverUrl?: string;
Expand All @@ -115,24 +132,24 @@ interface CaptureErrorOptions {
timestamp?: number;
handled?: boolean; // TODO: Currently not documented - should we expose this?
user?: UserObject;
tags?: Tags; // TODO: currently not documented
tags?: Tags; // TODO: Currently not documented
custom?: object;
message?: string;
}

interface Tags {
[key: string]: any; // TODO: Can't we specify it a bit more than any?
[key: string]: TagValue;
}

interface UserObject {
id?: any; // TODO: Only string?
username?: string;
email?: string;
id?: string | number | null | undefined;
username?: string | null | undefined;
email?: string | null | undefined;
}

interface ParameterizedMessageObject {
message: string;
params: Array<any>; // TODO: Can we narrow it down a bit more any
params: Array<any>;
}

interface Logger {
watson marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -159,7 +176,7 @@ interface SpanOptions {
childOf?: Transaction | Span | string // TODO: This technically accepts other values, but we might not want to document these?
}

type SetTagFn = (name: string, value: any) => boolean;
type SetTagFn = (name: string, value: TagValue) => boolean;
type AddTagsFn = (tags: Tags) => boolean;
type StartSpanFn = (name?: string, type?: string, options?: SpanOptions) => Span | null;
type EndTransactionFn = (result?: string | null, endTime?: number) => void; // TODO: Should we allow number as well for result?
Expand All @@ -168,13 +185,13 @@ type UncaughtExceptionFn = (err: Error) => void;

type CaptureErrorCallback = (err: Error | null, id: string) => void;

type FilterFn = (payload: object) => object | Falsy;
type FilterFn = (payload: object) => object | Falsy | void;

type LambdaFn =
| ((handler: LambdaHandlerFn) => LambdaHandlerFn)
| ((type: string, handler: LambdaHandlerFn) => LambdaHandlerFn);
type LambdaHandlerFn = (event: object, context: object, callback: LambdaHandlerCallbackFn) => any;
type LambdaHandlerCallbackFn = (err?: Error | null | undefined, result?: any) => void;
type LambdaHandlerFn = (event: object, context: object, callback: LambdaHandlerCallbackFn) => any; // TODO: Is the `any` return type correct?
type LambdaHandlerCallbackFn = (err?: Error | null | undefined, result?: any) => void; // TODO: Can `result` really be `any`?
watson marked this conversation as resolved.
Show resolved Hide resolved

type ConnectMiddlewareFn = (err: Error, req: IncomingMessage, res: ServerResponse, next: ConnectMiddlewareNextFn) => void;
type ConnectMiddlewareNextFn = (err?: Error) => void;
Expand All @@ -183,4 +200,5 @@ type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
type CaptureErrorLogStackTraces = 'never' | 'messages' | 'always';
type CaptureBody = 'off' | 'errors' | 'transactions' | 'all';

type Falsy = false | 0 | "" | null | undefined // Not possible to define NaN
type TagValue = string | number | boolean | null | undefined;
type Falsy = false | 0 | "" | null | undefined; // Not possible to define NaN
4 changes: 2 additions & 2 deletions start.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as agent from './';
export = agent;
import agent from './';
watson marked this conversation as resolved.
Show resolved Hide resolved
watson marked this conversation as resolved.
Show resolved Hide resolved
export default agent;