mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
add cloudevents-sdk/v03 types (#38067)
* add cloudevents-sdk/v03 types ignore no-single-declare-module because cloudevents-sdk/v03 is the documented way to import the cloudevent builder add cloudevents-sdk header module warning ignore * move CloudEvent interface into module, use named export for event() * use default export with event() as a prop to fix 'no default export' TS warning * allowSyntheticImports for cloudevents-sdk
This commit is contained in:
parent
0db40cd545
commit
540cea2e2b
14
types/cloudevents-sdk/cloudevents-sdk-tests.ts
Normal file
14
types/cloudevents-sdk/cloudevents-sdk-tests.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import Cloudevent from 'cloudevents-sdk/v03';
|
||||
|
||||
function testEventBuilder() {
|
||||
const event = Cloudevent.event()
|
||||
.dataContentType('application/json')
|
||||
.id('43')
|
||||
.time(new Date())
|
||||
.type('pull_request')
|
||||
.source('github')
|
||||
.data({ action: 'created' })
|
||||
.format();
|
||||
|
||||
const { id, datacontenttype, time, type, source, data } = event;
|
||||
}
|
||||
36
types/cloudevents-sdk/index.d.ts
vendored
Normal file
36
types/cloudevents-sdk/index.d.ts
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
// Type definitions for cloudevents-sdk 0.3
|
||||
// Project: https://github.com/cloudevents/sdk-javascript (Does not have to be to GitHub, but prefer linking to a source code repository rather than to a project website.)
|
||||
// Definitions by: Andy Cunningham <https://github.com/andycmaj>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// tslint:disable-next-line no-declare-current-package no-single-declare-module cloudevents-sdk/v03 is the documented way to import the cloudevent builder
|
||||
declare module 'cloudevents-sdk/v03' {
|
||||
// v03 CloudEvent payload
|
||||
// https://github.com/cloudevents/sdk-javascript/blob/master/lib/specs/spec_0_3.js#L11
|
||||
interface CloudEvent {
|
||||
id: string;
|
||||
datacontenttype: 'application/json';
|
||||
time: string;
|
||||
type: string;
|
||||
source: string;
|
||||
data: {};
|
||||
}
|
||||
|
||||
// Cloudevent fluent builder
|
||||
// https://github.com/cloudevents/sdk-javascript/blob/master/lib/cloudevent.js
|
||||
interface CloudEventBuilder {
|
||||
type: (type: string) => CloudEventBuilder;
|
||||
dataContentType: (contentType: string) => CloudEventBuilder;
|
||||
id: (id: string) => CloudEventBuilder;
|
||||
time: (timestamp: Date) => CloudEventBuilder;
|
||||
source: (source: string) => CloudEventBuilder;
|
||||
data: (data: any) => CloudEventBuilder;
|
||||
|
||||
format: () => CloudEvent;
|
||||
toString: () => string;
|
||||
}
|
||||
|
||||
// Cloudevent.event() static constructor
|
||||
// https://github.com/cloudevents/sdk-javascript#an-easy-way-to-create-events
|
||||
function event(): CloudEventBuilder;
|
||||
}
|
||||
22
types/cloudevents-sdk/tsconfig.json
Normal file
22
types/cloudevents-sdk/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"cloudevents-sdk-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/cloudevents-sdk/tslint.json
Normal file
3
types/cloudevents-sdk/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user