Skip to content
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

CloudEvent constructor should accept inline extensions #209

Closed
lance opened this issue Jun 4, 2020 · 4 comments · Fixed by #214
Closed

CloudEvent constructor should accept inline extensions #209

lance opened this issue Jun 4, 2020 · 4 comments · Fixed by #214
Assignees
Labels
good first issue Good for newcomers type/enhancement New feature or request

Comments

@lance
Copy link
Member

lance commented Jun 4, 2020

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'
  }
});
@lance lance added the type/enhancement New feature or request label Jun 4, 2020
@lance lance changed the title CloudEvent constructor should accept extensions inline CloudEvent constructor should accept inline extensions Jun 4, 2020
@lance lance added the good first issue Good for newcomers label Jun 4, 2020
@lholmquist
Copy link
Contributor

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

@lholmquist
Copy link
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

@lance
Copy link
Member Author

lance commented Jun 8, 2020

@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.

@lholmquist
Copy link
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. 🤦

lholmquist added a commit to lholmquist/sdk-javascript that referenced this issue Jun 8, 2020
* This allows someone to pass an extension/extensions into the CloudEvent contructor when creating a CloudEvent.

fixes cloudevents#209

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
lholmquist added a commit to lholmquist/sdk-javascript that referenced this issue Jun 8, 2020
* This allows someone to pass an extension/extensions into the CloudEvent contructor when creating a CloudEvent.

fixes cloudevents#209

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
lholmquist added a commit to lholmquist/sdk-javascript that referenced this issue Jun 9, 2020
* This allows someone to pass an extension/extensions into the CloudEvent contructor when creating a CloudEvent.

fixes cloudevents#209

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
@lance lance closed this as completed in #214 Jun 9, 2020
lance pushed a commit that referenced this issue Jun 9, 2020
* feat!: pass extension into the constructor.

* This allows someone to pass an extension/extensions into the CloudEvent contructor when creating a CloudEvent.

fixes #209

Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants