Skip to content

CloudEvent JSON Autocompletion without Class Wrapper #184

Closed
@grant

Description

@grant

As a developer, I want to be able to have autocompletion for objects without having a wrapper class such as CloudEvent.

JavaScript objects are normal in Node development, and are preferred over classes.

image

EXPECTED:

import {CloudEvent} from 'cloudevents/v1';
const ce = {
    "specversion" : "1.0",
    "type" : "com.github.pull.create",
    "source" : "https://github.com/cloudevents/spec/pull",
    "subject" : "123",
    "id" : "A234-1234-1234",
    "time" : "2018-04-05T17:31:00Z",
    "comexampleextension1" : "value",
    "comexampleothervalue" : 5,
    "datacontenttype" : "text/xml",
    "data" : "<much wow=\"xml\"/>"
}: CloudEvent;
ce.

ACTUAL:

import {CloudEvent} from 'cloudevents/v1';
const ce = new CloudEvent({
    "specversion" : "1.0",
    "type" : "com.github.pull.create",
    "source" : "https://github.com/cloudevents/spec/pull",
    "subject" : "123",
    "id" : "A234-1234-1234",
    "time" : "2018-04-05T17:31:00Z",
    "comexampleextension1" : "value",
    "comexampleothervalue" : 5,
    "datacontenttype" : "text/xml",
    "data" : "<much wow=\"xml\"/>"
});
ce.

Note: The : CloudEvent can be dropped off from user code and be inferred with normal usage if the developer doesn't like TypeScript.

Advantages

  • Minus one level of indirection (no required Classes/Objects).
  • Better devX: Creating new CloudEvent(), new CloudEvent(), over and over is tedious and one more level of indirection. It's much easier to use JSON. I think most Node developers would agree.
  • Support common JS features: You can't combine 2 CloudEvent JSON payloads easily, but you can with 2 JavaScript objects ({ ...ce1, ...ce2}).
  • Performance: JS Class wrappers for JSON creates unnecessary constructors to be called. Simply not requiring a class can help.
  • Use raw JSON over JS Classes. (It's easier to copy/paste a CloudEvent into source code without wrapping it.

Disadvantages

  • Requires 1 .ts file in the source code of this repo. We generate all the other .ts files, but we can't generate this one no matter how hard we try.

How can we add this feature?

Related but not the same: #169

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions