Skip to content

Commit f30a366

Browse files
committed
feat: add other interfaces from the spec for discovery
Signed-off-by: Remi Cattiau <remi@cattiau.com>
1 parent 765b81c commit f30a366

File tree

2 files changed

+168
-5
lines changed

2 files changed

+168
-5
lines changed

src/event/interfaces.ts

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,170 @@ export interface CloudEventV03OptionalAttributes {
271271
*/
272272
[key: string]: unknown;
273273
}
274+
275+
/**
276+
* Definition of a CloudEvents Service
277+
*/
278+
export interface CloudEventV1Service {
279+
/**
280+
* [REQUIRED] A URL that references this Service. This value MUST
281+
* be usable in subsequent requests, by authorized clients, to retrieve this
282+
* Service entity.
283+
* @required MUST be a non-empty URL
284+
* @required MUST end with `fsegments` (per RFC1738) of: `/services/{name}` where
285+
* `name` is the Service's `name` attribute.
286+
* @example `http://example.com/services/storage`
287+
* @example `http://discovery.github.com/services/github`
288+
*/
289+
url: string;
290+
291+
/**
292+
* [REQUIRED] A unique identifier for this Service. This value MUST be unique within the scope of this Discovery Endpoint.
293+
* @required MUST be a valid `fsegment` per RFC1738.
294+
* @example storage
295+
* @example github
296+
*/
297+
name: string;
298+
299+
/**
300+
* [OPTIONAL] Human readable description.
301+
* If present, MUST be a non-empty string
302+
*/
303+
description?: string;
304+
/**
305+
* Absolute URL that provides a link to additional documentation
306+
* about the service. This is intended for a developer to
307+
* use in order to learn more about this service's events produced.
308+
*
309+
* If present, MUST be a non-empty absolute URI
310+
*
311+
* @example http://cloud.example.com/docs/blobstorage
312+
*/
313+
docsurl?: string;
314+
/**
315+
* [REQUIRED] CloudEvents [`specversions`](https://github.com/cloudevents/spec/blob/master/spec.md#specversion)
316+
* that can be used for events published for this service.
317+
*
318+
* @required MUST be a non-empty array or non-empty strings.
319+
* @required strings define per [RFC 2046](https://tools.ietf.org/html/rfc2046)
320+
*/
321+
specversions: string[];
322+
/**
323+
* [REQUIRED] An absolute URL indicating where CloudSubscriptions `subscribe`
324+
* API calls MUST be sent to.
325+
*/
326+
subscriptionurl: string;
327+
/**
328+
* A map indicating supported options for the `config` parameter
329+
* for the CloudSubscriptions subscribe() API call. Keys are the name of keys
330+
* in the allowed config map, the values indicate the type of that parameter,
331+
* confirming to the CloudEvents [type system](https://github.com/cloudevents/spec/blob/master/spec.md#type-system).
332+
* TODO: Needs resolution with CloudSubscriptions API
333+
*/
334+
subscriptionconfig?: { [key: string]: string };
335+
/**
336+
* Authorization scope needed for creating subscriptions.
337+
* The actual meaning of this field is determined on a per-service basis.
338+
* @example storage.read
339+
*/
340+
authscope?: string;
341+
/**
342+
* [REQUIRED] This field describes the different values that might be passed
343+
* in the `protocol` field of the CloudSubscriptions API. The protocols with
344+
* existing CloudEvents bindings are identified as AMQP, MQTT3, MQTT5, HTTP,
345+
* KAFKA, and NATS. An implementation MAY add support for further
346+
* protocols. All services MUST support at least one delivery protocol, and MAY
347+
* support additional protocols.
348+
* @example [ "HTTP" ]
349+
* @example [ "HTTP", "AMQP", "KAFKA" ]
350+
*/
351+
protocols: string[];
352+
/**
353+
* [REQUIRED] CloudEvent types produced by the service
354+
*/
355+
types: CloudEventV1Type[];
356+
}
357+
358+
/**
359+
* Definition of a CloudEvents Type Extension
360+
*/
361+
export interface CloudEventV1TypeExtension {
362+
/**
363+
* [REQUIRED] the CloudEvents context attribute name used by this extension.
364+
* It MUST adhere to the CloudEvents context attrbibute naming rules
365+
* @example dataref
366+
*/
367+
name: string;
368+
/**
369+
* [REQUIRED] the data type of the extension attribute. It MUST adhere to the
370+
* CloudEvents [type system](./spec.md#type-system)
371+
* @example URI-reference
372+
*/
373+
type: string;
374+
/**
375+
* an attribute pointing to the specification that defines the extension
376+
* @example https://github.com/cloudevents/spec/blob/master/extensions/dataref.md
377+
*/
378+
specurl?: string;
379+
}
380+
381+
/**
382+
* Definition of a CloudEvents Type
383+
*/
384+
export interface CloudEventV1Type {
385+
/**
386+
* [REQUIRED] CloudEvents
387+
* [`type`](https://github.com/cloudevents/spec/blob/master/spec.md#type)
388+
* attribute.
389+
* @required MUST be a non-empty string, following the constraints as defined in the
390+
* CloudEvents spec.
391+
* @example com.github.pull.create
392+
* @example com.example.object.delete.v2
393+
*/
394+
type: string;
395+
/**
396+
* Human readable description.
397+
* If present, MUST be a non-empty string
398+
*/
399+
description?: string;
400+
/**
401+
* CloudEvents [`datacontenttype`](https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype)
402+
* attribute. Indicating how the `data` attribute of subscribed events will be
403+
* encoded.
404+
*
405+
* If present, MUST adhere to the format specified in [RFC 2046](https://tools.ietf.org/html/rfc2046)
406+
*/
407+
datacontenttype?: string;
408+
/**
409+
* CloudEvents [`datacontenttype`](https://github.com/cloudevents/spec/blob/master/spec.md#dataschema)
410+
* attribute. This identifies the canonical storage location of the schema of
411+
* the `data` attribute of subscribed events.
412+
*
413+
* If present, MUST be a non-empty URI
414+
*/
415+
dataschema?: string;
416+
/**
417+
* If using `dataschemacontent` for inline schema storage, the
418+
* `dataschematype` indicates the type of schema represented there.
419+
*
420+
* If present, MUST adhere to the format specified in [RFC 2046](https://tools.ietf.org/html/rfc2046)
421+
* @example application/json
422+
*/
423+
dataschematype?: string;
424+
/**
425+
* An inline representation of the schema of the `data` attribute
426+
* encoding mechanism. This is an alternative to using the `dataschema`
427+
* attribute.
428+
*
429+
* If present, MUST be a non-empty string containing a schema compatible with
430+
* the `datacontenttype`.
431+
* If `dataschama` is present, this field MUST NOT be present.
432+
*/
433+
dataschemacontent?: string;
434+
/**
435+
* An array or CloudEvents
436+
* [Extension Context Attributes](https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes)
437+
* that are used for this event `type`.
438+
*/
439+
extensions?: CloudEventV1TypeExtension[];
440+
}

src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CloudEvent, Version } from "./event/cloudevent";
22
import { ValidationError } from "./event/validation";
3-
import { CloudEventV03, CloudEventV03Attributes, CloudEventV1, CloudEventV1Attributes } from "./event/interfaces";
3+
export * from "./event/interfaces";
44

55
import {
66
Emitter,
@@ -19,10 +19,6 @@ import CONSTANTS from "./constants";
1919
export {
2020
// From event
2121
CloudEvent,
22-
CloudEventV03,
23-
CloudEventV03Attributes,
24-
CloudEventV1,
25-
CloudEventV1Attributes,
2622
Version,
2723
ValidationError,
2824
// From message

0 commit comments

Comments
 (0)