Skip to content

Commit 704278b

Browse files
committed
build: add tsc type checking in the ci/test pipeline
This commit introduces TypeScript checks and generates type declarations for the existing JavaScript codebase using `tsc` prior to running the linter task. Ref: #9 Signed-off-by: Lance Ball <[email protected]>
1 parent 09b0c76 commit 704278b

24 files changed

+495
-5
lines changed

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const CloudEvent: typeof import("./lib/cloudevent.js");
2+
export const HTTPReceiver: typeof import("./lib/bindings/http/http_receiver.js");

lib/bindings/http/commons.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export function sanityAndClone(headers: any): {};
2+
export function sanityContentType(contentType: any): any;

lib/bindings/http/constants.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
declare const _exports: {
2+
readonly HEADERS: string;
3+
readonly CHARSET_DEFAULT: string;
4+
readonly SPEC_V03: string;
5+
readonly SPEC_V1: string;
6+
readonly DEFAULT_SPEC_VERSION_HEADER: string;
7+
readonly ENCODING_BASE64: string;
8+
readonly DATA_ATTRIBUTE: string;
9+
readonly MIME_JSON: string;
10+
readonly MIME_OCTET_STREAM: string;
11+
readonly MIME_CE: string;
12+
readonly MIME_CE_JSON: string;
13+
readonly HEADER_CONTENT_TYPE: string;
14+
readonly DEFAULT_CONTENT_TYPE: string;
15+
readonly DEFAULT_CE_CONTENT_TYPE: string;
16+
readonly BINARY_HEADERS_03: {
17+
TYPE: string;
18+
SPEC_VERSION: string;
19+
SOURCE: string;
20+
ID: string;
21+
TIME: string;
22+
SCHEMA_URL: string;
23+
CONTENT_ENCONDING: string;
24+
SUBJECT: string;
25+
EXTENSIONS_PREFIX: string;
26+
};
27+
readonly STRUCTURED_ATTRS_03: {
28+
TYPE: string;
29+
SPEC_VERSION: string;
30+
SOURCE: string;
31+
ID: string;
32+
TIME: string;
33+
SCHEMA_URL: string;
34+
CONTENT_ENCONDING: string;
35+
CONTENT_TYPE: string;
36+
SUBJECT: string;
37+
DATA: string;
38+
};
39+
readonly BINARY_HEADERS_1: {
40+
TYPE: string;
41+
SPEC_VERSION: string;
42+
SOURCE: string;
43+
ID: string;
44+
TIME: string;
45+
DATA_SCHEMA: string;
46+
SUBJECT: string;
47+
EXTENSIONS_PREFIX: string;
48+
};
49+
readonly STRUCTURED_ATTRS_1: {
50+
TYPE: string;
51+
SPEC_VERSION: string;
52+
SOURCE: string;
53+
ID: string;
54+
TIME: string;
55+
DATA_SCHEMA: string;
56+
CONTENT_TYPE: string;
57+
SUBJECT: string;
58+
DATA: string;
59+
DATA_BASE64: string;
60+
};
61+
};
62+
export = _exports;

lib/bindings/http/http_receiver.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export = HTTPReceiver;
2+
/**
3+
* A class to receive a CloudEvent from an HTTP POST request.
4+
*/
5+
declare class HTTPReceiver {
6+
receivers: {
7+
v1: {
8+
structured: import("./receiver_structured_1.js");
9+
binary: import("./receiver_binary_1.js");
10+
};
11+
v03: {
12+
structured: import("./receiver_structured_0_3.js");
13+
binary: import("./receiver_binary_0_3.js");
14+
};
15+
};
16+
/**
17+
* Acceptor for an incoming HTTP CloudEvent POST. Can process
18+
* binary and structured incoming CloudEvents.
19+
*
20+
* @param {Object} headers HTTP headers keyed by header name ("Content-Type")
21+
* @param {Object|JSON} body The body of the HTTP request
22+
// @ts-ignore tsc can't find CloudEvent - is that because it's not imported?
23+
* @return {CloudEvent} A new {CloudEvent} instance
24+
*/
25+
accept(headers: any, body: any): any;
26+
}

lib/bindings/http/http_receiver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class HTTPReceiver {
3838
*
3939
* @param {Object} headers HTTP headers keyed by header name ("Content-Type")
4040
* @param {Object|JSON} body The body of the HTTP request
41+
// @ts-ignore tsc can't find CloudEvent - is that because it's not imported?
4142
* @return {CloudEvent} A new {CloudEvent} instance
4243
*/
4344
accept(headers, body) {
@@ -76,8 +77,7 @@ function getVersion(mode, headers, body) {
7677
if (versionHeader) { version = versionHeader; }
7778
} else {
7879
// structured mode - the version is in the body
79-
version = body instanceof String
80-
? JSON.parse(body).specversion : body.specversion;
80+
version = (typeof body == "string") ? JSON.parse(body).specversion : body.specversion;
8181
}
8282
return version;
8383
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export = BinaryHTTPReceiver;
2+
declare function BinaryHTTPReceiver(parsersByEncoding: any, setterByHeader: any, allowedContentTypes: any, requiredHeaders: any, Spec: any, specversion: any, extensionsPrefix: any, checkDecorator: any): void;
3+
declare class BinaryHTTPReceiver {
4+
constructor(parsersByEncoding: any, setterByHeader: any, allowedContentTypes: any, requiredHeaders: any, Spec: any, specversion: any, extensionsPrefix: any, checkDecorator: any);
5+
parsersByEncoding: any;
6+
setterByHeader: any;
7+
allowedContentTypes: any;
8+
requiredHeaders: any;
9+
Spec: any;
10+
spec: any;
11+
specversion: any;
12+
extensionsPrefix: any;
13+
checkDecorator: any;
14+
check(payload: any, headers: any): void;
15+
parse(payload: any, headers: any): import("../../cloudevent.js");
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export = Receiver;
2+
declare function Receiver(configuration: any): void;
3+
declare class Receiver {
4+
constructor(configuration: any);
5+
receiver: import("./receiver_binary.js");
6+
check(payload: any, headers: any): void;
7+
parse(payload: any, headers: any): import("../../cloudevent.js");
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export = Receiver;
2+
declare function Receiver(configuration: any): void;
3+
declare class Receiver {
4+
constructor(configuration: any);
5+
receiver: import("./receiver_binary.js");
6+
check(payload: any, headers: any): void;
7+
parse(payload: any, headers: any): import("../../cloudevent.js");
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export = StructuredHTTPReceiver;
2+
declare function StructuredHTTPReceiver(parserByMime: any, parserMap: any, allowedContentTypes: any, Spec: any): void;
3+
declare class StructuredHTTPReceiver {
4+
constructor(parserByMime: any, parserMap: any, allowedContentTypes: any, Spec: any);
5+
parserByMime: any;
6+
parserMap: any;
7+
allowedContentTypes: any;
8+
Spec: any;
9+
spec: any;
10+
check(payload: any, headers: any): void;
11+
parse(payload: any, headers: any): import("../../cloudevent.js");
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export = Receiver;
2+
declare function Receiver(configuration: any): void;
3+
declare class Receiver {
4+
constructor(configuration: any);
5+
receiver: import("./receiver_structured.js");
6+
check(payload: any, headers: any): void;
7+
parse(payload: any, headers: any): import("../../cloudevent.js");
8+
}

0 commit comments

Comments
 (0)