forked from octokit/webhooks.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
62 lines (51 loc) · 1.57 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { RequestError } from "@octokit/request-error";
import { EventNames } from "./generated/event-names";
export interface WebhookEvent<T = any> {
id: string;
name: EventNames.StringNames;
payload: T;
}
export interface Options<T extends WebhookEvent> {
path?: string;
secret?: string;
transform?: TransformMethod<T>;
}
type TransformMethod<T extends WebhookEvent> = (
event: WebhookEvent
) => T | PromiseLike<T>;
type Hooks = {
[key: string]: Function[];
};
export interface State extends Options<any> {
eventHandler?: any;
hooks: Hooks;
}
/**
* Error object with optional poperties coming from `octokit.request` errors
*/
export type OctokitError = Error &
Partial<RequestError> & {
/**
* @deprecated `error.event` is deprecated. Use the `.event` property on the aggregated error instance
*/
event: WebhookEvent;
};
export interface WebhookEventHandlerError extends AggregateError<OctokitError> {
event: WebhookEvent;
/**
* @deprecated `error.errors` is deprecated. Use `Array.from(error)`. See https://npm.im/aggregate-error
*/
errors: OctokitError[];
}
// temporary using a custom AggregateError type.
// Replace with `import AggregateError from "aggregate-error"` once
// https://github.com/gr2m/aggregate-error/pull/1 is merged or resolved
/**
Create an error from multiple errors.
*/
declare class AggregateError<T extends Error = Error> extends Error
implements Iterable<T> {
readonly name: "AggregateError";
constructor(errors: ReadonlyArray<T | { [key: string]: any } | string>);
[Symbol.iterator](): IterableIterator<T>;
}