TypeScript types for Pipedream components (sources and actions)
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core interfaces and types for defining Pipedream components, including the main component interface, app definitions, and lifecycle hooks.
The main interface for defining a Pipedream component with all required and optional properties.
/**
* Main interface for defining a Pipedream component
*/
interface PipedreamComponent {
/** Unique identifier for the component (optional) */
key?: string;
/** Display name for the component (required) */
name: string;
/** Semantic version of the component (required) */
version: string;
/** Description of what the component does (optional) */
description?: string;
/** Component properties configuration (required) */
props: ComponentProps;
/** Helper methods available in the component (optional) */
methods?: ComponentMethods;
/** Lifecycle hooks for component activation/deactivation (optional) */
hooks?: ComponentHooks;
/** Event deduplication strategy (optional) */
dedupe?: DedupeStrategy;
/** Main execution method called when component is triggered (required) */
run: (event: any) => Promise<void> | void;
}Usage Example:
import { PipedreamComponent } from "@pipedream/types";
const myComponent: PipedreamComponent = {
key: "my-custom-component",
name: "My Custom Component",
version: "1.0.0",
description: "A custom component that processes data",
props: {
timer: {
type: "$.interface.timer",
default: { intervalSeconds: 300 }
},
message: {
type: "string",
label: "Message",
description: "Message to process"
}
},
async run(event) {
console.log("Processing:", this.message);
this.$emit({ processed: true });
}
};Interface for defining app integrations that provide authentication and shared functionality.
/**
* Interface for defining app integrations with authentication and shared methods
*/
interface PipedreamApp {
/** Always "app" for app definitions */
type: "app";
/** App identifier slug */
app: string;
/** Reusable property definitions for components using this app */
propDefinitions?: PropDefinitions;
/** App-specific helper methods */
methods?: AppMethods;
}Usage Example:
import { PipedreamApp } from "@pipedream/types";
const myApp: PipedreamApp = {
type: "app",
app: "my_service",
propDefinitions: {
userId: {
type: "string",
label: "User ID",
description: "The ID of the user to process"
}
},
methods: {
async getUser(id: string) {
// App-specific method implementation
return await this.makeRequest(`/users/${id}`);
}
}
};Type definition for component helper methods.
/**
* Interface for component helper methods
*/
interface ComponentMethods {
[methodName: string]: (...args: any[]) => any;
}Type definition for app-specific methods.
/**
* Interface for app-specific methods available to components using the app
*/
interface AppMethods {
[methodName: string]: (...args: any[]) => any;
}Lifecycle hooks for component activation and deactivation.
/**
* Lifecycle hooks for component activation and deactivation
*/
interface ComponentHooks {
/** Called when component is activated (optional) */
activate?: () => Promise<void> | void;
/** Called when component is deactivated (optional) */
deactivate?: () => Promise<void> | void;
}Usage Example:
const componentWithHooks: PipedreamComponent = {
name: "Component with Hooks",
version: "1.0.0",
props: { /* props */ },
hooks: {
async activate() {
console.log("Component activated");
// Setup resources, create webhooks, etc.
},
async deactivate() {
console.log("Component deactivated");
// Cleanup resources, remove webhooks, etc.
}
},
async run(event) {
// Component logic
}
};Enum for event deduplication strategies.
/**
* Event deduplication strategy options
*/
type DedupeStrategy =
| "unique" // Dedupe by event ID
| "greatest" // Keep event with greatest ID
| "last"; // Keep most recent eventUsage Example:
const componentWithDedupe: PipedreamComponent = {
name: "Deduped Component",
version: "1.0.0",
dedupe: "unique", // Events will be deduped by their ID
props: { /* props */ },
async run(event) {
// Emit event with ID for deduplication
this.$emit(event, { id: event.id });
}
};Interface for reusable property definitions in apps.
/**
* Reusable property definitions for apps
*/
interface PropDefinitions {
[propName: string]: UserInputProp;
}Container type for all component properties.
/**
* Container for all component properties including user inputs, interfaces, and services
*/
interface ComponentProps {
[propName: string]:
| UserInputProp
| TimerInterface
| HttpInterface
| AppHookInterface
| "$.service.db"
| PipedreamApp;
}import { PipedreamComponent, TimerInterface } from "@pipedream/types";
const timerComponent: PipedreamComponent = {
name: "Timer Component",
version: "1.0.0",
props: {
timer: {
type: "$.interface.timer",
default: { intervalSeconds: 60 }
} as TimerInterface,
db: "$.service.db"
},
async run(event) {
// Timer-based logic
}
};import { PipedreamComponent, HttpInterface } from "@pipedream/types";
const httpComponent: PipedreamComponent = {
name: "HTTP Component",
version: "1.0.0",
props: {
http: {
type: "$.interface.http",
customResponse: true
} as HttpInterface
},
async run(event) {
this.http.respond({
status: 200,
body: { success: true }
});
}
};import { PipedreamComponent, PipedreamApp } from "@pipedream/types";
const appComponent: PipedreamComponent = {
name: "App Integration Component",
version: "1.0.0",
props: {
myApp: {
type: "app",
app: "my_service"
} as PipedreamApp,
userId: {
type: "string",
propDefinition: ["myApp", "userId"]
}
},
async run(event) {
const user = await this.myApp.getUser(this.userId);
this.$emit(user);
}
};Install with Tessl CLI
npx tessl i tessl/npm-pipedream--types