Skip to content

Commit 133b864

Browse files
committed
Merge remote-tracking branch 'upstream/master' into master
2 parents 145775b + 129ec48 commit 133b864

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+603
-624
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Bug Report
3+
about: Create a report to help us improve this module
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the Bug**
11+
A clear and concise description of what the bug is.
12+
13+
**Steps to Reproduce**
14+
1.
15+
2.
16+
3.
17+
18+
**Expected Behavior**
19+
A clear and concise description of what you expected to happen.
20+
21+
22+
23+
**Additional context**
24+
Add any other context about the problem here. If applicable, add screenshots to help explain your problem.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Feature Request
3+
about: Suggest an idea for this module
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is.
12+
13+
**Describe the solution you would like to see**
14+
A clear and concise description of what you want to happen.
15+
16+
**Additional context**
17+
Add any other context or screenshots about the feature request here.

.github/pull-request-template.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- General PR guidelines:
2+
3+
Most PRs should be opened against the master branch.
4+
5+
-->
6+
7+
## Proposed Changes
8+
9+
-
10+
-
11+
-
12+
13+
## Description
14+
- Fixes Issue #
15+
- Version:

.vscode/tasks.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "build",
7+
"group": "build",
8+
"problemMatcher": [],
9+
"label": "npm: build",
10+
"detail": "tsc --project tsconfig.json && tsc --project tsconfig.browser.json && webpack"
11+
},
12+
{
13+
"type": "npm",
14+
"script": "watch",
15+
"group": "build",
16+
"problemMatcher": [],
17+
"label": "npm: watch",
18+
"detail": "tsc --project tsconfig.json --watch"
19+
},
20+
{
21+
"type": "npm",
22+
"script": "lint",
23+
"group": "build",
24+
"problemMatcher": [],
25+
"label": "npm: lint",
26+
"detail": "eslint 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'"
27+
},
28+
{
29+
"type": "npm",
30+
"script": "test",
31+
"group": "test",
32+
"problemMatcher": [],
33+
"label": "npm: test",
34+
"detail": "mocha --require ts-node/register ./test/integration/**/*.ts"
35+
},
36+
]
37+
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The CloudEvents SDK requires a current LTS version of Node.js. At the moment
2222
those are Node.js 10.x and Node.js 12.x. To install in your Node.js project:
2323

2424
```console
25-
npm install cloudevents-sdk
25+
npm install cloudevents
2626
```
2727

2828
### Receiving and Emitting Events
@@ -37,7 +37,7 @@ binary and structured events in either the 1.0 or 0.3 protocol formats.
3737
const {
3838
CloudEvent,
3939
Receiver
40-
} = require("cloudevents-sdk");
40+
} = require("cloudevents");
4141

4242
// Create a receiver to accept events over HTTP
4343
const receiver = new Receiver();
@@ -58,7 +58,7 @@ structured events, add `Protocol.HTTPStructured` as a parameter to
5858
`emitter.send()`.
5959

6060
```js
61-
const { CloudEvent, Emitter, Protocol, Version } = require("cloudevents-sdk");
61+
const { CloudEvent, Emitter, Protocol, Version } = require("cloudevents");
6262

6363
// With only an endpoint URL, this creates a v1 emitter
6464
const emitter = new Emitter({
@@ -101,7 +101,7 @@ All created `CloudEvent` objects are read-only. If you need to update a propert
101101
```js
102102
const {
103103
CloudEvent,
104-
} = require("cloudevents-sdk");
104+
} = require("cloudevents");
105105

106106
// Create a new CloudEvent
107107
const ce = new CloudEvent({...});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "cloudevents-sdk",
2+
"name": "cloudevents",
33
"version": "2.0.2",
44
"description": "CloudEvents SDK for JavaScript",
55
"main": "dist/index.js",

plugins/ignore-typedef.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/event/cloudevent.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { v4 as uuidv4 } from "uuid";
22

3-
import { CloudEventV1, validateV1, CloudEventV1Attributes, CloudEventV1OptionalAttributes } from "./v1";
4-
import { CloudEventV03, validateV03, CloudEventV03Attributes, CloudEventV03OptionalAttributes } from "./v03";
3+
import {
4+
CloudEventV03,
5+
CloudEventV03Attributes,
6+
CloudEventV03OptionalAttributes,
7+
CloudEventV1,
8+
CloudEventV1Attributes,
9+
CloudEventV1OptionalAttributes,
10+
} from "./interfaces";
11+
import { validateV1, validateV03 } from "./spec";
512
import { ValidationError, isBinary, asBase64 } from "./validation";
613
import CONSTANTS from "../constants";
714
import { isString } from "util";

src/event/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/event/v03/cloudevent.ts renamed to src/event/interfaces.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,141 @@
1+
/**
2+
* The object interface for CloudEvents 1.0.
3+
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
4+
*/
5+
export interface CloudEventV1 extends CloudEventV1Attributes {
6+
// REQUIRED Attributes
7+
/**
8+
* [REQUIRED] Identifies the event. Producers MUST ensure that `source` + `id`
9+
* is unique for each distinct event. If a duplicate event is re-sent (e.g. due
10+
* to a network error) it MAY have the same `id`. Consumers MAY assume that
11+
* Events with identical `source` and `id` are duplicates.
12+
* @required Non-empty string. Unique within producer.
13+
* @example An event counter maintained by the producer
14+
* @example A UUID
15+
*/
16+
id: string;
17+
18+
/**
19+
* [REQUIRED] The version of the CloudEvents specification which the event
20+
* uses. This enables the interpretation of the context. Compliant event
21+
* producers MUST use a value of `1.0` when referring to this version of the
22+
* specification.
23+
* @required MUST be a non-empty string.
24+
*/
25+
specversion: string;
26+
}
27+
28+
export interface CloudEventV1Attributes extends CloudEventV1OptionalAttributes {
29+
/**
30+
* [REQUIRED] Identifies the context in which an event happened. Often this
31+
* will include information such as the type of the event source, the
32+
* organization publishing the event or the process that produced the event. The
33+
* exact syntax and semantics behind the data encoded in the URI is defined by
34+
* the event producer.
35+
* Producers MUST ensure that `source` + `id` is unique for each distinct event.
36+
* An application MAY assign a unique `source` to each distinct producer, which
37+
* makes it easy to produce unique IDs since no other producer will have the same
38+
* source. The application MAY use UUIDs, URNs, DNS authorities or an
39+
* application-specific scheme to create unique `source` identifiers.
40+
* A source MAY include more than one producer. In that case the producers MUST
41+
* collaborate to ensure that `source` + `id` is unique for each distinct event.
42+
* @required Non-empty URI-reference
43+
*/
44+
source: string;
45+
46+
/**
47+
* [REQUIRED] This attribute contains a value describing the type of event
48+
* related to the originating occurrence. Often this attribute is used for
49+
* routing, observability, policy enforcement, etc. The format of this is
50+
* producer defined and might include information such as the version of the
51+
* `type` - see
52+
* [Versioning of Attributes in the Primer](primer.md#versioning-of-attributes)
53+
* for more information.
54+
* @required MUST be a non-empty string
55+
* @should SHOULD be prefixed with a reverse-DNS name. The prefixed domain dictates the
56+
* organization which defines the semantics of this event type.
57+
* @example com.github.pull.create
58+
* @example com.example.object.delete.v2
59+
*/
60+
type: string;
61+
}
62+
63+
export interface CloudEventV1OptionalAttributes {
64+
/**
65+
* The following fields are optional.
66+
*/
67+
68+
/**
69+
* [OPTIONAL] Content type of `data` value. This attribute enables `data` to
70+
* carry any type of content, whereby format and encoding might differ from that
71+
* of the chosen event format. For example, an event rendered using the
72+
* [JSON envelope](./json-format.md#3-envelope) format might carry an XML payload
73+
* in `data`, and the consumer is informed by this attribute being set to
74+
* "application/xml". The rules for how `data` content is rendered for different
75+
* `datacontenttype` values are defined in the event format specifications; for
76+
* example, the JSON event format defines the relationship in
77+
* [section 3.1](./json-format.md#31-handling-of-data).
78+
*/
79+
datacontenttype?: string;
80+
/**
81+
* [OPTIONAL] Identifies the schema that `data` adheres to. Incompatible
82+
* changes to the schema SHOULD be reflected by a different URI. See
83+
* [Versioning of Attributes in the Primer](primer.md#versioning-of-attributes)
84+
* for more information.
85+
* If present, MUST be a non-empty URI.
86+
*/
87+
dataschema?: string;
88+
/**
89+
* [OPTIONAL] This describes the subject of the event in the context of the
90+
* event producer (identified by `source`). In publish-subscribe scenarios, a
91+
* subscriber will typically subscribe to events emitted by a `source`, but the
92+
* `source` identifier alone might not be sufficient as a qualifier for any
93+
* specific event if the `source` context has internal sub-structure.
94+
*
95+
* Identifying the subject of the event in context metadata (opposed to only in
96+
* the `data` payload) is particularly helpful in generic subscription filtering
97+
* scenarios where middleware is unable to interpret the `data` content. In the
98+
* above example, the subscriber might only be interested in blobs with names
99+
* ending with '.jpg' or '.jpeg' and the `subject` attribute allows for
100+
* constructing a simple and efficient string-suffix filter for that subset of
101+
* events.
102+
*
103+
* If present, MUST be a non-empty string.
104+
* @example "https://example.com/storage/tenant/container"
105+
* @example "mynewfile.jpg"
106+
*/
107+
subject?: string;
108+
/**
109+
* [OPTIONAL] Timestamp of when the occurrence happened. If the time of the
110+
* occurrence cannot be determined then this attribute MAY be set to some other
111+
* time (such as the current time) by the CloudEvents producer, however all
112+
* producers for the same `source` MUST be consistent in this respect. In other
113+
* words, either they all use the actual time of the occurrence or they all use
114+
* the same algorithm to determine the value used.
115+
* @example "2020-08-08T14:48:09.769Z"
116+
*/
117+
time?: Date | string;
118+
/**
119+
* [OPTIONAL] The event payload. This specification does not place any restriction
120+
* on the type of this information. It is encoded into a media format which is
121+
* specified by the datacontenttype attribute (e.g. application/json), and adheres
122+
* to the dataschema format when those respective attributes are present.
123+
*/
124+
data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown;
125+
126+
/**
127+
* [OPTIONAL] The event payload encoded as base64 data. This is used when the
128+
* data is in binary form.
129+
* @see https://github.com/cloudevents/spec/blob/v1.0/json-format.md#31-handling-of-data
130+
*/
131+
data_base64?: string;
132+
133+
/**
134+
* [OPTIONAL] CloudEvents extension attributes.
135+
*/
136+
[key: string]: unknown;
137+
}
138+
1139
/**
2140
* The object interface for CloudEvents 0.3.
3141
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md

0 commit comments

Comments
 (0)