Skip to content

Commit 7e2d6a2

Browse files
committed
fix: add two type definitions to SCM and fix their parameters
It seems that `tsc` doesn't recognize when a class or function has a single `options` parameter that is required but properties within it are not. This corrects the output from `tsc` type definition generation and adds the two files affected by this to repo. Fixes: #188
1 parent daf945c commit 7e2d6a2

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

lib/bindings/http/http_emitter.d.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
export = HTTPEmitter;
2+
/**
3+
* A class which is capable of sending binary and structured events using
4+
* the CloudEvents HTTP Protocol Binding specification.
5+
*
6+
* @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md
7+
* @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md#13-content-modes
8+
*/
9+
declare class HTTPEmitter {
10+
/**
11+
* Creates a new instance of {HTTPEmitter}. The default emitter uses the 1.0
12+
* protocol specification in binary mode.
13+
*
14+
* @param {Object} [options] The configuration options for this event emitter
15+
* @param {URL} options.url The endpoint that will receive the sent events.
16+
* @param {string} [options.version] The HTTP binding specification version. Default: "1.0"
17+
* @throws {TypeError} if no options.url is provided or an unknown specification version is provided.
18+
*/
19+
constructor({ url, version }?: {
20+
url: URL;
21+
version?: string;
22+
});
23+
binary: import("./emitter_binary.js");
24+
structured: import("./emitter_structured.js");
25+
url: URL;
26+
/**
27+
* Sends the {CloudEvent} to an event receiver over HTTP POST
28+
*
29+
* @param {CloudEvent} event the CloudEvent to be sent
30+
* @param {Object} [options] The configuration options for this event. Options
31+
* provided will be passed along to Node.js `http.request()`.
32+
* https://nodejs.org/api/http.html#http_http_request_options_callback
33+
* @param {URL} [options.url] The HTTP/S url that should receive this event.
34+
* The URL is optional if one was provided when this emitter was constructed.
35+
* In that case, it will be used as the recipient endpoint. The endpoint can
36+
* be overridden by providing a URL here.
37+
* @param {string} [options.mode] the message mode for sending this event.
38+
* Possible values are "binary" and "structured". Default: structured
39+
* @returns {Promise} Promise with an eventual response from the receiver
40+
*/
41+
send(event: CloudEvent, { url, mode, ...httpOpts }?: {
42+
url: URL;
43+
mode: string;
44+
}): Promise<any>;
45+
/**
46+
* Returns the HTTP headers that will be sent for this event when the HTTP transmission
47+
* mode is "binary". Events sent over HTTP in structured mode only have a single CE header
48+
* and that is "ce-id", corresponding to the event ID.
49+
* @param {CloudEvent} event a CloudEvent
50+
* @returns {Object} the headers that will be sent for the event
51+
*/
52+
headers(event: CloudEvent): any;
53+
}
54+
declare namespace HTTPEmitter {
55+
export { CloudEvent };
56+
}
57+
type CloudEvent = import("../../cloudevent.js");

lib/cloudevent.d.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
export = CloudEvent;
2+
/**
3+
* An CloudEvent describes event data in common formats to provide
4+
* interopability across services, platforms and systems.
5+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
6+
*/
7+
declare class CloudEvent {
8+
/**
9+
* Creates a new CloudEvent instance
10+
* @param {object} options CloudEvent properties as a simple object
11+
* @param {string} options.source Identifies the context in which an event happened as a URI reference
12+
* @param {string} options.type Describes the type of event related to the originating occurrence
13+
* @param {string} [options.id] A unique ID for this event - if not supplied, will be autogenerated
14+
* @param {string} [options.time] A timestamp for this event. May also be provided as a Date
15+
* @param {string} [options.subject] Describes the subject of the event in the context of the event producer
16+
* @param {string} [options.dataContentType] The mime content type for the event data
17+
* @param {string} [options.dataSchema] The URI of the schema that the event data adheres to (v1.0 events)
18+
* @param {string} [options.schemaURL] The URI of the schema that the event data adheres to (v0.3 events)
19+
* @param {string} [options.dataContentEncoding] The content encoding for the event data (v0.3 events)
20+
* @param {string} [options.specversion] The CloudEvent specification version for this event - default: 1.0
21+
* @param {*} [options.data] The event payload
22+
*/
23+
constructor({ id, source, type, dataContentType, time, subject, dataSchema, schemaURL, dataContentEncoding, data, specversion }: {
24+
source: string;
25+
type: string;
26+
id?: string;
27+
time?: string;
28+
subject?: string;
29+
dataContentType?: string;
30+
dataSchema?: string;
31+
schemaURL?: string;
32+
dataContentEncoding?: string;
33+
specversion?: string;
34+
data?: any;
35+
});
36+
spec: import("./bindings/http/v1/spec_1.js") | import("./bindings/http/v03/spec_0_3.js");
37+
set source(arg: string);
38+
/**
39+
* Gets or sets the origination source of this event as a URI.
40+
* @type {string}
41+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
42+
*/
43+
get source(): string;
44+
set type(arg: string);
45+
/**
46+
* Gets or sets the event type
47+
* @type {string}
48+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
49+
*/
50+
get type(): string;
51+
set dataContentType(arg: string);
52+
/**
53+
* Gets or sets the content type of the data value for this event
54+
* @type {string}
55+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
56+
*/
57+
get dataContentType(): string;
58+
set data(arg: any);
59+
/**
60+
* Gets or sets the data for this event
61+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
62+
* @type {*}
63+
*/
64+
get data(): any;
65+
set subject(arg: string);
66+
/**
67+
* Gets or sets the event subject
68+
* @type {string}
69+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
70+
*/
71+
get subject(): string;
72+
set dataSchema(arg: string);
73+
/**
74+
* Gets or sets the event's data schema
75+
* @type {string}
76+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema
77+
*/
78+
get dataSchema(): string;
79+
set dataContentEncoding(arg: string);
80+
/**
81+
* Gets or sets the event's data content encoding
82+
* @type {string}
83+
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding
84+
*/
85+
get dataContentEncoding(): string;
86+
set schemaURL(arg: string);
87+
/**
88+
* DEPRECATED: Gets or sets the schema URL for this event. Throws {TypeError}
89+
* if this is a version 1.0 event.
90+
* @type {string}
91+
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl
92+
*/
93+
get schemaURL(): string;
94+
set id(arg: string);
95+
/**
96+
* Gets or sets the event id. Source + id must be unique for each distinct event.
97+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#id
98+
* @type {string}
99+
*/
100+
get id(): string;
101+
set time(arg: string);
102+
/**
103+
* Gets or sets the timestamp for this event as an ISO formatted date string
104+
* @type {string}
105+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
106+
*/
107+
get time(): string;
108+
formatter: import("./formats/json/formatter.js");
109+
/**
110+
* Gets the CloudEvent specification version
111+
* @type {string}
112+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion
113+
*/
114+
get specversion(): string;
115+
/**
116+
* Formats the CloudEvent as JSON. Validates the event according
117+
* to the CloudEvent specification and throws an exception if
118+
* it's invalid.
119+
* @returns {JSON} the CloudEvent in JSON form
120+
* @throws {ValidationError} if this event cannot be validated against the specification
121+
*/
122+
format(): JSON;
123+
/**
124+
* Formats the CloudEvent as JSON. No specification validation is performed.
125+
* @returns {string} the CloudEvent as a JSON string
126+
*/
127+
toString(): string;
128+
/**
129+
* Adds an extension attribute to this CloudEvent
130+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
131+
* @param {string} key the name of the extension attribute
132+
* @param {*} value the value of the extension attribute
133+
* @returns {void}
134+
*/
135+
addExtension(key: string, value: any): void;
136+
extensions: any;
137+
/**
138+
* Gets the extension attributes, if any, associated with this event
139+
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
140+
* @returns {Object} the extensions attributes - if none exist will will be {}
141+
*/
142+
getExtensions(): any;
143+
}

tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
},
1313
"files": [
1414
"index.js"
15+
],
16+
"exclude": [
17+
"lib/cloudevent.js",
18+
"lib/bindings/http/http_emitter.js"
1519
]
1620
}

0 commit comments

Comments
 (0)