Typescript examples
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
a1955b793d
commit
b4b04963b9
|
@ -0,0 +1,19 @@
|
|||
# Typescript Example
|
||||
|
||||
The types are available since v1.0.0
|
||||
|
||||
## How To Start
|
||||
|
||||
Install and transpile:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
Then, start
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
See your event payload [here](https://enu90y24i64jp.x.pipedream.net/)
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "typescript-ex",
|
||||
"version": "1.0.0",
|
||||
"description": "Simple typescript example using CloudEvents types",
|
||||
"repository": "https://github.com/cloudevents/sdk-javascript.git",
|
||||
"main": "build/src/index.js",
|
||||
"types": "build/src/index.d.ts",
|
||||
"files": [
|
||||
"build/src"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [],
|
||||
"scripts": {
|
||||
"start": "node build/src/index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"check": "gts check",
|
||||
"clean": "gts clean",
|
||||
"compile": "tsc -p .",
|
||||
"fix": "gts fix",
|
||||
"prepare": "npm run compile",
|
||||
"pretest": "npm run compile",
|
||||
"posttest": "npm run check"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gts": "^1.1.0",
|
||||
"typescript": "~3.5.0",
|
||||
"@types/node": "^8.9.0",
|
||||
"cloudevents-sdk": "cloudevents/sdk-javascript#v1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
singleQuote: true,
|
||||
trailingComma: 'es5',
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
import Cloudevent, { event, StructuredHTTPEmitter } from 'cloudevents-sdk/v1';
|
||||
|
||||
export function doSomeStuff() {
|
||||
|
||||
const myevent: Cloudevent = event()
|
||||
.source('/source')
|
||||
.type('type')
|
||||
.dataContentType('text/plain')
|
||||
.dataschema('http://d.schema.com/my.json')
|
||||
.subject('cha.json')
|
||||
.data('my-data');
|
||||
|
||||
console.log(myevent.format());
|
||||
|
||||
let config = {
|
||||
method: "POST",
|
||||
url : "https://enu90y24i64jp.x.pipedream.net/"
|
||||
};
|
||||
|
||||
let emitter = new StructuredHTTPEmitter(config);
|
||||
emitter.emit(myevent).then(res => {
|
||||
// success
|
||||
console.log("Success!")
|
||||
})
|
||||
.catch(err => {
|
||||
// error
|
||||
console.error(err);
|
||||
})
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
doSomeStuff();
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"extends": "./node_modules/gts/tsconfig-google.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"outDir": "build",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"test/**/*.ts"
|
||||
],
|
||||
"allowJs": true
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "gts/tslint.json",
|
||||
"linterOptions": {
|
||||
"exclude": [
|
||||
"**/*.json"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue