@pipedream/types
Advanced tools
Comparing version
{ | ||
"name": "@pipedream/types", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Pipedream TypeScript types", | ||
@@ -22,5 +22,9 @@ "main": "dist/index.js", | ||
}, | ||
"dependencies": { | ||
"typescript": "^4.6.4" | ||
}, | ||
"scripts": { | ||
"test": "dtslint src" | ||
"test": "dtslint src", | ||
"build": "tsc" | ||
} | ||
} |
@@ -7,5 +7,16 @@ # `@pipedream/types` | ||
TO DO | ||
```bash | ||
npm install | ||
``` | ||
- `npm link` | ||
- (in this directory) `npm run dev` | ||
Run tests, which use `dtslint`: | ||
```bash | ||
npm run test | ||
``` | ||
Build: | ||
```bash | ||
npm run build | ||
``` |
@@ -107,8 +107,16 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
page?: number; | ||
prevContext?: string; | ||
prevContext?; // XXX could be typed using context from OptionalOptsFn ReturnValue? | ||
[key: string]; // XXX properties in the return value of OptionalOptsFn can be included. Strictly type this instead? | ||
} | ||
// https://pipedream.com/docs/components/api/#referencing-values-from-previous-props | ||
export interface OptionalOptsFn { | ||
(configuredProps: { [key: string]; }): object; // XXX strictly type configuredProps | ||
} | ||
export type PropDefinition = [App<M, P>, string] | [App<M, P>, string, OptionalOptsFn]; | ||
// https://pipedream.com/docs/components/api/#prop-definitions-example | ||
export interface PropDefinitionReference { | ||
propDefinition: [App, string]; | ||
propDefinition: PropDefinition; | ||
} | ||
@@ -119,9 +127,22 @@ | ||
// for more information on this technique | ||
export interface App { | ||
export interface App< | ||
Methods, | ||
PropDefinitions extends AppPropDefinitions = {} | ||
> { | ||
type: "app"; | ||
app: string; | ||
propDefinitions?: AppPropDefinitions | undefined; | ||
methods?: (Methods | undefined) & ThisType<any>; | ||
propDefinitions?: PropDefinitions; | ||
methods?: Methods & ThisType<Methods & PropDefinitions>; | ||
} | ||
export function defineApp< | ||
M, | ||
P, | ||
> | ||
(app: App<M, P>): App<M, P> { | ||
return { | ||
...app, | ||
}; | ||
} | ||
// Props | ||
@@ -134,2 +155,29 @@ | ||
export interface Field { | ||
name: string; | ||
value: string; | ||
} | ||
export interface HttpAuth { | ||
type?: "basic" | "bearer" | "none"; | ||
username?: string; | ||
password?: string; | ||
token?: string; | ||
} | ||
export interface HttpBody { | ||
type?: "fields" | "raw"; | ||
contentType?: string; | ||
fields?: Field[]; | ||
mode?: "fields" | "raw"; | ||
raw?: string; | ||
} | ||
export interface DefaultHttpRequestPropConfig { | ||
auth?: HttpAuth; | ||
body?: HttpBody; | ||
headers?: Field[]; | ||
params?: Field[]; | ||
tab?: string; | ||
method?: string; | ||
url?: string; | ||
} | ||
export interface BasePropInterface { | ||
@@ -145,3 +193,3 @@ label?: string; | ||
type: "boolean" | "boolean[]" | "integer" | "integer[]" | "string" | "string[]" | "object" | "any"; | ||
options?: PropOptions | ((opts: OptionsMethodArgs) => Promise<PropOptions>); | ||
options?: PropOptions | ((this: any, opts: OptionsMethodArgs) => Promise<PropOptions>); | ||
optional?: boolean; | ||
@@ -170,19 +218,23 @@ default?: JSONValue; | ||
export interface HttpRequestProp extends BasePropInterface { | ||
type: "http_request"; | ||
default?: DefaultHttpRequestPropConfig; | ||
} | ||
export interface SourcePropDefinitions { | ||
[name: string]: PropDefinitionReference | | ||
App | UserProp | InterfaceProp | ServiceDBProp; | ||
[name: string]: PropDefinitionReference | App<M, P> | UserProp | InterfaceProp | ServiceDBProp | HttpRequestProp; | ||
} | ||
export interface ActionPropDefinitions { | ||
[name: string]: PropDefinitionReference | App | UserProp | DataStoreProp; | ||
[name: string]: PropDefinitionReference | App<M, P> | UserProp | DataStoreProp | HttpRequestProp; | ||
} | ||
export interface AppPropDefinitions { | ||
[name: string]: PropDefinitionReference | App | UserProp; | ||
[name: string]: PropDefinitionReference | App<M, P> | UserProp; | ||
} | ||
export interface Hooks { | ||
deploy?: (this: any) => Promise<void>; | ||
activate?: (this: any) => Promise<void>; | ||
deactivate?: (this: any) => Promise<void>; | ||
deploy?: () => Promise<void>; | ||
activate?: () => Promise<void>; | ||
deactivate?: () => Promise<void>; | ||
} | ||
@@ -205,8 +257,15 @@ | ||
} | ||
export interface EmitConfig { | ||
event: JSONValue; | ||
metadata?: EmitMetadata; | ||
} | ||
export interface Source { | ||
type EmitFunction = { | ||
$emit: (event: JSONValue, metadata: EmitMetadata) => Promise<void>; | ||
}; | ||
type PropThis<Props> = { | ||
[Prop in keyof Props]: Props[Prop] extends App<M, P> ? any : any | ||
}; | ||
export interface Source< | ||
Methods, | ||
Props extends SourcePropDefinitions = {} | ||
> { | ||
key: string; | ||
@@ -217,16 +276,24 @@ name?: string; | ||
type: "source"; | ||
// XXX should be something like methods?: Methods & ThisType<PropKeys<SourcePropDefinitions> & Methods> | ||
methods?: Methods & ThisType<any>; | ||
hooks?: Hooks & ThisType<any>; | ||
props?: SourcePropDefinitions; | ||
methods?: Methods & ThisType<PropThis<Props> & Methods & EmitFunction>; | ||
hooks?: Hooks & ThisType<PropThis<Props> & Methods & EmitFunction>; | ||
props?: Props; | ||
dedupe?: "last" | "greatest" | "unique"; | ||
additionalProps?: ( | ||
previousPropDefs: SourcePropDefinitions | ||
) => Promise<SourcePropDefinitions>; | ||
// XXX `this` should be strictly typed. For some reason the approach I took above | ||
// did not work here. | ||
run: (this: any, options?: SourceRunOptions) => void | Promise<void>; | ||
previousPropDefs: Props | ||
) => Promise<Props>; | ||
run: (this: PropThis<Props> & Methods & EmitFunction, options?: SourceRunOptions) => void | Promise<void>; | ||
} | ||
export interface Action { | ||
export function defineSource< | ||
M, | ||
P, | ||
> | ||
(component: Source<M, P>): Source { | ||
return Object.assign(...component, {}); | ||
} | ||
export interface Action< | ||
Methods, | ||
Props extends ActionPropDefinitions = {} | ||
> { | ||
key: string; | ||
@@ -237,10 +304,16 @@ name?: string; | ||
type: "action"; | ||
methods?: Methods & ThisType<any>; | ||
props?: ActionPropDefinitions & ThisType<any>; | ||
methods?: Methods & ThisType<PropThis<Props> & Methods>; | ||
props?: Props; | ||
additionalProps?: ( | ||
previousPropDefs: ActionPropDefinitions | ||
) => Promise<ActionPropDefinitions>; | ||
// XXX `this` should be strictly typed. For some reason the approach I took above | ||
// did not work here. | ||
run: (this: any, options?: ActionRunOptions) => any; | ||
run: (this: PropThis<Props> & Methods, options?: ActionRunOptions) => any; | ||
} | ||
export function defineAction< | ||
M, | ||
P, | ||
> | ||
(component: Action<M, P>): Action { | ||
return Object.assign(...component, {}); | ||
} |
@@ -12,3 +12,3 @@ { | ||
"noEmit": true, | ||
"lib": ["es6"], | ||
"lib": ["es6", "dom"], | ||
"strictFunctionTypes": true, | ||
@@ -15,0 +15,0 @@ "noImplicitAny": true, |
@@ -195,2 +195,40 @@ /* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */ | ||
const httpRequestProp: Pipedream.HttpRequestProp = { | ||
type: "http_request", | ||
default: { | ||
auth: { | ||
type: "basic", | ||
username: "u", | ||
password: "p", | ||
token: "t", | ||
}, | ||
body: { | ||
contentType: "application/json", | ||
fields: [ | ||
{ | ||
name: "n", | ||
value: "v", | ||
}, | ||
], | ||
mode: "fields", | ||
raw: "r", | ||
}, | ||
headers: [ | ||
{ | ||
name: "n", | ||
value: "v", | ||
}, | ||
], | ||
method: "POST", | ||
params: [ | ||
{ | ||
name: "n", | ||
value: "v", | ||
}, | ||
], | ||
tab: "Params", | ||
url: "example.com", | ||
}, | ||
}; | ||
const hooks: Pipedream.Hooks = { | ||
@@ -248,3 +286,3 @@ deploy: async () => { return; }, | ||
// @ts-expect-error $ExpectError - Missing type | ||
const sourceMissingVersion: Pipedream.Source = { | ||
const sourceMissingType: Pipedream.Source = { | ||
key: "foo", | ||
@@ -319,3 +357,3 @@ version: "0.0.1", | ||
// @ts-expect-error $ExpectError - Missing type | ||
const actionMissingVersion: Pipedream.Action = { | ||
const actionMissingType: Pipedream.Action = { | ||
key: "foo", | ||
@@ -322,0 +360,0 @@ version: "0.0.1", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24133
6.38%822
7.73%21
110%0
-100%1
Infinity%+ Added
+ Added