GithubHelp home page GithubHelp logo

ci7lus / ironpipe Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 133 KB

TypeScript typed helpers for pipedream.

Home Page: https://www.npmjs.com/package/ironpipe

License: MIT License

TypeScript 98.38% JavaScript 1.62%
pipedream typescript-definitions

ironpipe's Introduction

ironpipe

CI npm version

TypeScript typed helpers for pipedream.

Install

yarn add -D ironpipe

Usage

defineComponent

defineComponent is a function for defining type-safe component.

import { defineComponent } from "ironpipe"

module.exports = defineComponent({
  name: "componentname",
  version: "0.0.1",
  props: {
    url: {
      type: "string",
      label: "something url",
    },
    timer: {
      type: "$.interface.timer",
      default: {
        intervalSeconds: 60 * 15,
      },
    },
    db: "$.service.db",
    http: "$.interface.http",
  },
  methods: {
    random(n: number) {
      return Math.random() * n
    },
  },
  dedupe: "unique",
  async run() {
    // `this` will be typed whenever possible.
    this.db.set("random-value", this.random(100))
    this.db.set("something-url", this.url)

    this.http.respond({
      status: 200,
      headers: {},
      body: this.db.get<number>("random-value")?.toString() || this.url,
    })
  },
})

defineAction

defineAction is a function for defining type-safe action component.
Ref: Quickstart: Action Development

import { defineAction } from "ironpipe"

module.exports = defineAction({
  type: "action",
  name: "example-action",
  key: "example_action",
  version: "0.0.1",
  props: {
    url: {
      type: "string",
      label: "something url",
    },
    target: {
      type: "string",
      label: "replace target string",
      optional: true,
    },
  },
  async run() {
    return this.url.replace(this.target || "http", "https")
  },
})

Example Usage

Example: Use twitter extension
import { defineComponent } from "ironpipe"
const twitter = require("https://github.com/PipedreamHQ/pipedream/components/twitter/twitter.app.js")
import { AxiosResponse, AxiosRequestConfig } from "axios"
import { FullUser, Status } from "twitter-d"

module.exports = defineComponent({
  name: "tweet",
  version: "0.0.1",
  props: {
    url: {
      type: "string",
      label: "something url",
      optional: true,
    },
    timer: {
      type: "$.interface.timer",
      default: {
        intervalSeconds: 60 * 15,
      },
    },
    db: "$.service.db",
    twitter,
  },
  methods: {
    async random(n: number) {
      return Math.random() * n
    },
  },
  dedupe: "unique",
  async run(): Promise<any> {
    // this any to avoid unexplained break of this.methods type when `run` return something
    const rand = this.random(100)
    this.db.set("random-value", rand)
    this.db.set("something-url", this.url)

    const twit = this.twitter as TwitterAppJS

    const r = await twit._makeRequest({
      url: `https://api.twitter.com/1.1/statuses/update.json?status=${rand}`,
      method: "POST",
    })
    return r.data
  },
})

type TwitterAppJS = {
  _makeRequest: (
    opts: AxiosRequestConfig
  ) => Promise<AxiosResponse<{ statuses: (Status & { text: string })[] }>>
  verifyCredentials: () => Promise<FullUser>
  search: (opts: {
    q: string
    since_id?: string | number
    tweet_mode?: "extended"
    count?: number
    result_type?: "recent" | "polular" | "mixed"
    lang?: string
    locale?: string
    geocode?: string
    max_id?: string | number
  }) => Promise<AxiosResponse<{ statuses: (Status & { text: string })[] }>>
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.