feat: add native logging with headers and body to CloudEvent
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
This commit is contained in:
parent
2dc846c659
commit
d2a43ea0cb
|
|
@ -9,6 +9,7 @@ import { Emitter } from "..";
|
|||
import { CloudEventV1, CloudEventV1Attributes, CloudEventV1OptionalAttributes } from "./interfaces";
|
||||
import { validateCloudEvent } from "./spec";
|
||||
import { ValidationError, isBinary, asBase64, isValidType } from "./validation";
|
||||
import * as util from 'util';
|
||||
|
||||
/**
|
||||
* An enum representing the CloudEvent specification version
|
||||
|
|
@ -195,4 +196,11 @@ See: https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system`);
|
|||
): CloudEvent {
|
||||
return new CloudEvent(Object.assign({}, this.toJSON(), options) as CloudEvent, strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* The native `console.log` value of the CloudEvent.
|
||||
*/
|
||||
[util.inspect.custom](depth: any, opts: any) {
|
||||
return this.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,11 @@ describe("A CloudEvent", () => {
|
|||
expect(new CloudEvent(JSON.parse(JSON.stringify(ce)))).to.deep.equal(ce);
|
||||
});
|
||||
|
||||
it("serializes as JSON with raw log", () => {
|
||||
const ce = new CloudEvent({ ...fixture, data: { lunch: "tacos" } });
|
||||
expect(ce.toString()).to.deep.equal(JSON.stringify(ce));
|
||||
});
|
||||
|
||||
it("Throw a validation error for invalid extension names", () => {
|
||||
expect(() => {
|
||||
new CloudEvent({ "ext-1": "extension1", ...fixture });
|
||||
|
|
|
|||
Loading…
Reference in New Issue