Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ package-lock.json

# Jetbrains IDE directories
.idea

# TypeScript incremental build info
*.tsbuildinfo
3 changes: 3 additions & 0 deletions examples/typescript-ex/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json'),
};
16 changes: 16 additions & 0 deletions examples/typescript-ex/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = [
{
ignores: ['build/'],
},
...require('gts'),
{
languageOptions: {
globals: {
console: 'readonly',
module: 'writable',
exports: 'writable',
require: 'readonly',
},
},
},
];
8 changes: 4 additions & 4 deletions examples/typescript-ex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"posttest": "npm run check"
},
"devDependencies": {
"@types/node": "^14.14.10",
"gts": "^3.0.3",
"typescript": "~4.1.3"
"@types/node": "^22.0.0",
"gts": "^7.0.0",
"typescript": "~5.9.0"
},
"dependencies": {
"cloudevents": "~4.0.0"
"cloudevents": "^10.0.0"
}
}
56 changes: 32 additions & 24 deletions examples/typescript-ex/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
/* eslint-disable no-console */
import { CloudEvent, HTTP } from "cloudevents";
import {CloudEvent, HTTP} from 'cloudevents';

export function doSomeStuff(): void {
const myevent: CloudEvent = new CloudEvent({
source: "/source",
type: "type",
datacontenttype: "text/plain",
dataschema: "https://d.schema.com/my.json",
subject: "cha.json",
data: "my-data",
extension1: "some extension data",
const myevent = new CloudEvent({
source: '/source',
type: 'type',
datacontenttype: 'text/plain',
dataschema: 'https://d.schema.com/my.json',
subject: 'cha.json',
data: 'my-data',
extension1: 'some extension data',
});

console.log("My structured event:", myevent);
console.log('My structured event:', myevent);

// ------ receiver structured
// The header names should be standarized to use lowercase
const headers = {
"content-type": "application/cloudevents+json",
'content-type': 'application/cloudevents+json',
};

// Typically used with an incoming HTTP request where myevent.format() is the actual
// body of the HTTP
console.log("Received structured event:", HTTP.toEvent({ headers, body: myevent }));
console.log(
'Received structured event:',
HTTP.toEvent({headers, body: myevent}),
);

// ------ receiver binary
const data = {
data: "dataString",
data: 'dataString',
};
const attributes = {
"ce-type": "type",
"ce-specversion": "1.0",
"ce-source": "source",
"ce-id": "id",
"ce-time": "2019-06-16T11:42:00Z",
"ce-dataschema": "http://schema.registry/v1",
"Content-Type": "application/json",
"ce-extension1": "extension1",
'ce-type': 'type',
'ce-specversion': '1.0',
'ce-source': 'source',
'ce-id': 'id',
'ce-time': '2019-06-16T11:42:00Z',
'ce-dataschema': 'http://schema.registry/v1',
'Content-Type': 'application/json',
'ce-extension1': 'extension1',
};

console.log("My binary event:", HTTP.toEvent({ headers: attributes, body: data }));
console.log("My binary event extensions:", HTTP.toEvent({ headers: attributes, body: data }));
console.log(
'My binary event:',
HTTP.toEvent({headers: attributes, body: data}),
);
console.log(
'My binary event extensions:',
HTTP.toEvent({headers: attributes, body: data}),
);
}

doSomeStuff();
8 changes: 0 additions & 8 deletions examples/typescript-ex/tslint.json

This file was deleted.

Loading
Loading