Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
🏷️ Updating types
Browse files Browse the repository at this point in the history
  • Loading branch information
ci7lus committed Aug 5, 2020
1 parent 5cbb78f commit 5be09d8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironpipe",
"version": "0.0.1",
"version": "0.0.2",
"author": "ci7lus <7887955+ci7lus@users.noreply.github.com>",
"description": "TypeScript typed helpers for pipedream.",
"repository": {
Expand Down
6 changes: 4 additions & 2 deletions src/component/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MethodOptions } from "./methods"
import { ExtractPropTypes, ComponentPropsOptions } from "./props"
import { ObjectLiteral } from "../types"
import { ArgEventTypes } from "./pipedream"

export type ComponentOptions<
PropsOptions = ComponentPropsOptions,
Expand All @@ -16,13 +17,14 @@ type ComponentInstance = {
version: string
description?: string
dedupe?: string
run: (event?: any) => any | Function
run: (event?: ArgEventTypes | any) => any
hooks?: { [key: string]: Function }
}

type ComponentThis<Props, Methods> = ThisType<
{
$props: Props
$emit: (data: ObjectLiteral, data2?: ObjectLiteral) => void
$emit: (data: ObjectLiteral, metadata?: ObjectLiteral) => void
} & Props &
Methods &
ObjectLiteral
Expand Down
32 changes: 25 additions & 7 deletions src/component/pipedream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,42 @@ import { ObjectLiteral } from "../types"

// https://github.com/PipedreamHQ/pipedream/blob/master/COMPONENT-API.md

export type ArgEventTypes = ArgEventBase | ArgEventInterval | ArgEventHttp

export type ArgEventBase = { timestamp: number }
export type ArgEventInterval = ArgEventBase & { interval_seconds: number }
export type ArgEventHttp = {
method: "POST" | "GET" | String
path: string
query: ObjectLiteral
headers: ObjectLiteral
bodyRaw: string
body: any
}

export type PipedreamPropTypes =
| "$.interface.timer"
| "$.interface.http"
| "$.service.db"

export type PropReturnDInterfaceTimer = {}

export type PropDefaultDInterfaceTimer = {
intervalSeconds: number
export type PropReturnDInterfaceTimer = {
type: "$.interface.timer"
}

export type PropDefaultDInterfaceTimer =
| {
intervalSeconds: number
}
| { cron: string }

export type PropReturnDInterfaceHttp = {
respond(options: {
status: number
headers: ObjectLiteral
body: string | object | Buffer
status?: number
headers?: ObjectLiteral
body?: any
[key: string]: any
}): void
endpoint: string
}

export type PropReturnDServiceDB = {
Expand Down
18 changes: 13 additions & 5 deletions src/component/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import {
PropDefaultDInterfaceTimer,
} from "./pipedream"

type PropTypes = "string" | "number" | PipedreamPropTypes
type PropTypes = "string" | "number" | "boolean" | PipedreamPropTypes

type Prop<T> = PropOptions<T> | PropTypes

type PropTypesDefault = PropDefaultDInterfaceTimer | { [key: string]: any }
type PropTypesDefault = PropDefaultDInterfaceTimer

type PropOptions<T = any> = {
type?: PropTypes | String
label?: string
description?: string
default?: PropTypesDefault | null
propDefinition?: T[]
default?: PropTypesDefault | { [key: string]: any } | string | null
propDefinition?: [any, string]
optional?: boolean
options?: any[]
}

type ConvertPropTypes<T> = T extends null
Expand All @@ -26,6 +28,8 @@ type ConvertPropTypes<T> = T extends null
? string
: T extends { type: "number" } | "number"
? number
: T extends { type: "boolean" } | "boolean"
? boolean
: T extends { type: "$.interface.timer" } | "$.interface.timer"
? PropReturnDInterfaceTimer
: T extends { type: "$.interface.http" } | "$.interface.http"
Expand All @@ -34,8 +38,12 @@ type ConvertPropTypes<T> = T extends null
? PropReturnDServiceDB
: any

type PropOptionalCheck<T> = T extends { optional: true }
? ConvertPropTypes<T> | undefined
: ConvertPropTypes<T>

export type ExtractPropTypes<P> = P extends object
? { [K in keyof P]: ConvertPropTypes<P[K]> }
? { [K in keyof P]: PropOptionalCheck<P[K]> }
: { [K in string]: any }

export type ComponentPropsOptions<P = Record<string, unknown>> =
Expand Down

0 comments on commit 5be09d8

Please sign in to comment.