Skip to content

fix: add two type definitions to SCM and fix their parameters #189

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions lib/bindings/http/http_emitter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export = HTTPEmitter;
/**
* A class which is capable of sending binary and structured events using
* the CloudEvents HTTP Protocol Binding specification.
*
* @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md
* @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md#13-content-modes
*/
declare class HTTPEmitter {
/**
* Creates a new instance of {HTTPEmitter}. The default emitter uses the 1.0
* protocol specification in binary mode.
*
* @param {Object} [options] The configuration options for this event emitter
* @param {URL} options.url The endpoint that will receive the sent events.
* @param {string} [options.version] The HTTP binding specification version. Default: "1.0"
* @throws {TypeError} if no options.url is provided or an unknown specification version is provided.
*/
constructor({ url, version }?: {
url: URL;
version?: string;
});
binary: import("./emitter_binary.js");
structured: import("./emitter_structured.js");
url: URL;
/**
* Sends the {CloudEvent} to an event receiver over HTTP POST
*
* @param {CloudEvent} event the CloudEvent to be sent
* @param {Object} [options] The configuration options for this event. Options
* provided will be passed along to Node.js `http.request()`.
* https://nodejs.org/api/http.html#http_http_request_options_callback
* @param {URL} [options.url] The HTTP/S url that should receive this event.
* The URL is optional if one was provided when this emitter was constructed.
* In that case, it will be used as the recipient endpoint. The endpoint can
* be overridden by providing a URL here.
* @param {string} [options.mode] the message mode for sending this event.
* Possible values are "binary" and "structured". Default: structured
* @returns {Promise} Promise with an eventual response from the receiver
*/
send(event: CloudEvent, { url, mode, ...httpOpts }?: {
url: URL;
mode: string;
}): Promise<any>;
/**
* Returns the HTTP headers that will be sent for this event when the HTTP transmission
* mode is "binary". Events sent over HTTP in structured mode only have a single CE header
* and that is "ce-id", corresponding to the event ID.
* @param {CloudEvent} event a CloudEvent
* @returns {Object} the headers that will be sent for the event
*/
headers(event: CloudEvent): any;
}
declare namespace HTTPEmitter {
export { CloudEvent };
}
type CloudEvent = import("../../cloudevent.js");
143 changes: 143 additions & 0 deletions lib/cloudevent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
export = CloudEvent;
/**
* An CloudEvent describes event data in common formats to provide
* interopability across services, platforms and systems.
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
*/
declare class CloudEvent {
/**
* Creates a new CloudEvent instance
* @param {object} options CloudEvent properties as a simple object
* @param {string} options.source Identifies the context in which an event happened as a URI reference
* @param {string} options.type Describes the type of event related to the originating occurrence
* @param {string} [options.id] A unique ID for this event - if not supplied, will be autogenerated
* @param {string} [options.time] A timestamp for this event. May also be provided as a Date
* @param {string} [options.subject] Describes the subject of the event in the context of the event producer
* @param {string} [options.dataContentType] The mime content type for the event data
* @param {string} [options.dataSchema] The URI of the schema that the event data adheres to (v1.0 events)
* @param {string} [options.schemaURL] The URI of the schema that the event data adheres to (v0.3 events)
* @param {string} [options.dataContentEncoding] The content encoding for the event data (v0.3 events)
* @param {string} [options.specversion] The CloudEvent specification version for this event - default: 1.0
* @param {*} [options.data] The event payload
*/
constructor({ id, source, type, dataContentType, time, subject, dataSchema, schemaURL, dataContentEncoding, data, specversion }: {
source: string;
type: string;
id?: string;
time?: string;
subject?: string;
dataContentType?: string;
dataSchema?: string;
schemaURL?: string;
dataContentEncoding?: string;
specversion?: string;
data?: any;
});
spec: import("./bindings/http/v1/spec_1.js") | import("./bindings/http/v03/spec_0_3.js");
set source(arg: string);
/**
* Gets or sets the origination source of this event as a URI.
* @type {string}
* @see https://github.com/cloudevents/spec/blob/master/spec.md#source-1
*/
get source(): string;
set type(arg: string);
/**
* Gets or sets the event type
* @type {string}
* @see https://github.com/cloudevents/spec/blob/master/spec.md#type
*/
get type(): string;
set dataContentType(arg: string);
/**
* Gets or sets the content type of the data value for this event
* @type {string}
* @see https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype
*/
get dataContentType(): string;
set data(arg: any);
/**
* Gets or sets the data for this event
* @see https://github.com/cloudevents/spec/blob/master/spec.md#event-data
* @type {*}
*/
get data(): any;
set subject(arg: string);
/**
* Gets or sets the event subject
* @type {string}
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject
*/
get subject(): string;
set dataSchema(arg: string);
/**
* Gets or sets the event's data schema
* @type {string}
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema
*/
get dataSchema(): string;
set dataContentEncoding(arg: string);
/**
* Gets or sets the event's data content encoding
* @type {string}
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding
*/
get dataContentEncoding(): string;
set schemaURL(arg: string);
/**
* DEPRECATED: Gets or sets the schema URL for this event. Throws {TypeError}
* if this is a version 1.0 event.
* @type {string}
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl
*/
get schemaURL(): string;
set id(arg: string);
/**
* Gets or sets the event id. Source + id must be unique for each distinct event.
* @see https://github.com/cloudevents/spec/blob/master/spec.md#id
* @type {string}
*/
get id(): string;
set time(arg: string);
/**
* Gets or sets the timestamp for this event as an ISO formatted date string
* @type {string}
* @see https://github.com/cloudevents/spec/blob/master/spec.md#time
*/
get time(): string;
formatter: import("./formats/json/formatter.js");
/**
* Gets the CloudEvent specification version
* @type {string}
* @see https://github.com/cloudevents/spec/blob/master/spec.md#specversion
*/
get specversion(): string;
/**
* Formats the CloudEvent as JSON. Validates the event according
* to the CloudEvent specification and throws an exception if
* it's invalid.
* @returns {JSON} the CloudEvent in JSON form
* @throws {ValidationError} if this event cannot be validated against the specification
*/
format(): JSON;
/**
* Formats the CloudEvent as JSON. No specification validation is performed.
* @returns {string} the CloudEvent as a JSON string
*/
toString(): string;
/**
* Adds an extension attribute to this CloudEvent
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
* @param {string} key the name of the extension attribute
* @param {*} value the value of the extension attribute
* @returns {void}
*/
addExtension(key: string, value: any): void;
extensions: any;
/**
* Gets the extension attributes, if any, associated with this event
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
* @returns {Object} the extensions attributes - if none exist will will be {}
*/
getExtensions(): any;
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
},
"files": [
"index.js"
],
"exclude": [
"lib/cloudevent.js",
"lib/bindings/http/http_emitter.js"
]
}