Skip to content

CloudEvent constructor should accept inline extensions #209

Closed

Description

@lance

There is no way to create a CloudEvent instance using the constructor and have the extensions initialized there. For example, this is not valid, but should work.

const ce = new CloudEvent({
  type: 'ex',
  source: '/path',
  extensions: {
    extension1: 'some data'
  }
});

Activity

  1. changed the title [-]CloudEvent constructor should accept extensions inline[/-] [+]CloudEvent constructor should accept inline extensions[/+] on Jun 4, 2020
  2. lholmquist commented on Jun 8, 2020

    @lholmquist
    Contributor

    @lance should the extensions property in your example, be an array of key:value pairs?

  3. lholmquist commented on Jun 8, 2020

    @lholmquist
    Contributor

    The reason I ask is because if you take a look at what is created after doing const ce = new CloudEvent(...)

    The extensions property is a blank array

    CloudEvent {
      spec: Spec1 {
        payload: {
          specversion: '1.0',
          id: '2b306349-ad39-4cd6-bb4e-1cddb02ecd0a',
          time: '2020-06-08T16:55:19.845Z',
          source: '/source',
          type: 'type',
          datacontenttype: undefined,
          data: undefined,
          subject: undefined
        }
      },
      formatter: JSONFormatter {},
      extensions: []
    }
    

    As soon as you call addExtension(key, value), the value of thta property actually turns into an object:

    CloudEvent {
      spec: Spec1 {
        payload: {
          specversion: '1.0',
          id: 'd1acd94e-aaec-4287-80f0-85fa4a57748b',
          time: '2020-06-08T16:57:45.721Z',
          source: '/source',
          type: 'type',
          datacontenttype: undefined,
          data: undefined,
          subject: undefined,
          'extension-key': 'extension-value',
          'extension-key1': 'extension-value1'
        }
      },
      formatter: JSONFormatter {},
      extensions: {
        'extension-key1': 'extension-value1',
        'extension-key': 'extension-value'
      }
    }
    

    Not sure what the correct answer should be here

  4. lance commented on Jun 8, 2020

    @lance
    MemberAuthor

    @lholmquist that was a bug that was fixed at the end of last week https://github.com/cloudevents/sdk-javascript/pull/202/files#diff-695048fccf8efadd88b77db776a94d06L84. It should be an object.

  5. lholmquist commented on Jun 8, 2020

    @lholmquist
    Contributor

    @lance yea, i was just looking in the code and couldn't find that array, and just realized my example was using the version on npm. 🤦

  6. added 3 commits that reference this issue on Jun 8, 2020
    bb807a2
    bfa8cdd
    a62221a
  7. added a commit that references this issue on Jun 9, 2020
    0378f4c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions