question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rethink Versioning

See original GitHub issue

When a developer wants to use CloudEvents, they think about an event, not which version they’re using. The way this module is written is highly segmented towards the version of CloudEvent.

Rather than this:

const v1 = require("cloudevents-sdk/v1");

Where const v1 doesn’t make much sense.

We should have

const CloudEvents = require("cloudevents-sdk");

It should be easy to create a CloudEvent:

let myevent= new CloudEvent({
  specversion: '1.0',
  source: '/source',
  type: 'type',
  dataContentType: 'text/plain',
  dataschema: 'http://d.schema.com/my.json',
  subject: 'cha.json',
  data: 'my-data',
  addExtension: ["my-ext", "0x600"]
});

let myevent2= new CloudEvent({
  specversion: '0.3',
  source: '/source',
  type: 'type',
  dataContentType: 'text/plain',
  dataschema: 'http://d.schema.com/my.json',
  subject: 'cha.json',
  data: 'my-data',
  addExtension: ["my-ext", "0x600"]
});

We should remove the v03 and v1 folders in the repo and just have one CloudEvent that can support multiple versions.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
lancecommented, May 7, 2020

That’s in some ways what this pull request that landed yesterday was about.

const { CloudEvent, HTTPReceiver } = require('cloudevent-sdk');
const ce = new CloudEvent();
// Produces
// CloudEvent {
//  spec:
//   Spec1 {
//     payload:
//      { specversion: '1.0',
//        id: '888798a5-0a22-463a-b2d5-bd9a443c736b' },
//     caller: [Function: CloudEvent] },
//  formatter: JSONFormatter {},
//  extensions: {} }

And you can see the HTTPReceiver usage in the test here: https://github.com/cloudevents/sdk-javascript/blob/master/test/bindings/http/promiscuous_receiver_test.js#L13

Once a CloudEvent has been created, that instance cannot be changed to a different version by just setting the specversion property. You can see here, that was a conscious choice by @fabiojose and I think it makes sense. Converting from one specification version to another is more than just changing the version number.

With the changes that landed yesterday, when a CloudEvent is created using the constructor from the top level default export, it’s defaulting to an event conforming to the 1.0 spec. You can create a 0.3 event by reaching down into the v3 exports as before.

I think your direct object notation could be a nice change. But that’s already covered by https://github.com/cloudevents/sdk-javascript/issues/65 isn’t it?

0reactions
lancecommented, May 12, 2020

Closing this, as I think we have come to resolution. If not, feel free to reopen and we can discuss further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Downloads - Rethink DNS
Rethink DNS + Firewall is a free and open source project, released under Apache License, Version 2.0. iOS? A lot of our users...
Read more >
rethinking package - RDocumentation
This R package accompanies a course and book on Bayesian data analysis (McElreath 2016. Statistical Rethinking. CRC Press.). It contains tools ...
Read more >
RethinkDB: the open-source database for the realtime web
When your app polls for data, it becomes slow, unscalable, and cumbersome to maintain. RethinkDB is the open-source, scalable database that makes building ......
Read more >
ReThink - Steam Community
ReThink. 27. 3. Game won't launch at all on new version, and old version crashes within a ... ReThink 100% - All puzzles,...
Read more >
"Rachael Ray" Rethink Your Ink/Rethink Your Status Update (TV ...
Rethink Your Ink/Rethink Your Status Update (2013). Alternate Versions (0). It looks like there are no Alternate Versions for this title.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found