diff --git a/platform/.gitignore b/platform/.gitignore index 3c3629e647f5d..28fd18b208d8d 100644 --- a/platform/.gitignore +++ b/platform/.gitignore @@ -1 +1,2 @@ +!*.d.ts node_modules diff --git a/platform/dist/axios.d.ts b/platform/dist/axios.d.ts new file mode 100644 index 0000000000000..b6c1207240536 --- /dev/null +++ b/platform/dist/axios.d.ts @@ -0,0 +1,10 @@ +import { AxiosRequestConfig } from "./index"; +export declare function transformConfigForOauth(config: AxiosRequestConfig): { + method: string; + url: string; +}; +declare function callAxios(step: any, config: AxiosRequestConfig, signConfig?: any): Promise; +declare namespace callAxios { + var create: (config?: AxiosRequestConfig | undefined, signConfig?: any) => import("axios").AxiosInstance; +} +export default callAxios; diff --git a/platform/dist/constants.d.ts b/platform/dist/constants.d.ts new file mode 100644 index 0000000000000..910b1e26e132b --- /dev/null +++ b/platform/dist/constants.d.ts @@ -0,0 +1 @@ +export declare const DEFAULT_POLLING_SOURCE_TIMER_INTERVAL: number; diff --git a/platform/dist/errors.d.ts b/platform/dist/errors.d.ts new file mode 100644 index 0000000000000..932c557422a19 --- /dev/null +++ b/platform/dist/errors.d.ts @@ -0,0 +1,4 @@ +export declare class ConfigurationError extends Error { + exposeStack: boolean; + constructor(message: string, exposeStack?: boolean); +} diff --git a/platform/dist/index.d.ts b/platform/dist/index.d.ts new file mode 100644 index 0000000000000..cf4a6c4c2f69a --- /dev/null +++ b/platform/dist/index.d.ts @@ -0,0 +1,136 @@ +import * as t from "io-ts"; +import axios, { transformConfigForOauth } from "./axios"; +import { AxiosRequestConfig as AxiosConfig } from "axios"; +export { axios, transformConfigForOauth, }; +export { cloneSafe, jsonStringifySafe, } from "./utils"; +export { ConfigurationError, } from "./errors"; +export { default as sqlProp, } from "./sql-prop"; +export { default as sqlProxy, } from "./sql-proxy"; +export { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, } from "./constants"; +export declare const SendConfigEmail: t.PartialC<{ + html: t.StringC; + subject: t.StringC; + text: t.StringC; +}>; +export declare type SendConfigEmail = t.TypeOf; +export declare const SendConfigEmit_required: t.ExactC>; +export declare const SendConfigEmit_optional: t.PartialC<{ + event: t.ObjectC; +}>; +export declare const SendConfigEmit: t.IntersectionC<[t.ExactC>, t.PartialC<{ + event: t.ObjectC; +}>]>; +export declare type SendConfigEmit = t.TypeOf; +export declare const HTTP_METHODS: string[]; +export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC; + url: t.StringC; +}>>, t.PartialC<{ + auth: t.ExactC>; + data: t.UnionC<[t.StringC, t.ObjectC]>; + headers: t.ObjectC; + params: t.ObjectC; +}>]>; +export declare type SendConfigHTTP = t.TypeOf; +export declare const SendConfigS3: t.ExactC; + prefix: t.StringC; +}>>; +export declare type SendConfigS3 = t.TypeOf; +export declare const SendConfigSQL: t.ExactC; + table: t.StringC; +}>>; +export declare type SendConfigSQL = t.TypeOf; +export declare const SendConfigSnowflake: t.ExactC; + pipe_name: t.StringC; + private_key: t.StringC; + schema: t.StringC; + stage_name: t.StringC; + user: t.StringC; +}>>; +export declare type SendConfigSnowflake = t.TypeOf; +export declare const SendConfigSSE: t.ExactC; +}>>; +export declare type SendConfigSSE = t.TypeOf; +interface SendFunctionsWrapper { + email: (config: SendConfigEmail) => void; + emit: (config: SendConfigEmit) => void; + http: (config: SendConfigHTTP) => void; + s3: (config: SendConfigS3) => void; + sql: (config: SendConfigSQL) => void; + snowflake: (config: SendConfigSnowflake) => void; + sse: (config: SendConfigSSE) => void; +} +export declare const sendTypeMap: { + email: t.PartialC<{ + html: t.StringC; + subject: t.StringC; + text: t.StringC; + }>; + emit: t.IntersectionC<[t.ExactC>, t.PartialC<{ + event: t.ObjectC; + }>]>; + http: t.IntersectionC<[t.ExactC; + url: t.StringC; + }>>, t.PartialC<{ + auth: t.ExactC>; + data: t.UnionC<[t.StringC, t.ObjectC]>; + headers: t.ObjectC; + params: t.ObjectC; + }>]>; + s3: t.ExactC; + prefix: t.StringC; + }>>; + sql: t.ExactC; + table: t.StringC; + }>>; + snowflake: t.ExactC; + pipe_name: t.StringC; + private_key: t.StringC; + schema: t.StringC; + stage_name: t.StringC; + user: t.StringC; + }>>; + sse: t.ExactC; + }>>; +}; +export declare let $event: any; +export declare const END_NEEDLE = "__pd_end"; +export declare function $end(message?: string): void; +export declare let $send: SendFunctionsWrapper; +export declare const $sendConfigRuntimeTypeChecker: {}; +export interface AxiosRequestConfig extends AxiosConfig { + debug?: boolean; + body?: any; + returnFullResponse?: boolean; +} diff --git a/platform/dist/sql-prop.d.ts b/platform/dist/sql-prop.d.ts new file mode 100644 index 0000000000000..1c5ed8855d9d6 --- /dev/null +++ b/platform/dist/sql-prop.d.ts @@ -0,0 +1,31 @@ +import { JsonPrimitive } from "type-fest"; +export declare type DbSchema = { + [tableName: string]: { + [columnName: string]: { + columnDefault: JsonPrimitive; + dataType: string; + isNullable: boolean; + tableSchema?: string; + }; + }; +}; +export declare type RowCount = { + [tableName: string]: { + _rowCount?: number; + }; +}; +declare const _default: { + methods: { + /** + * A helper method to get the schema of the database. Used by other features + * (like the `sql` prop) to enrich the code editor and provide the user with + * auto-complete and fields suggestion. + * + * @returns {DbSchema} The schema of the database, which is a + * JSON-serializable object. + * @throws {ConfigurationError} If the method is not implemented. + */ + getSchema(): DbSchema | RowCount; + }; +}; +export default _default; diff --git a/platform/dist/sql-proxy.d.ts b/platform/dist/sql-proxy.d.ts new file mode 100644 index 0000000000000..5aefc77d81803 --- /dev/null +++ b/platform/dist/sql-proxy.d.ts @@ -0,0 +1,45 @@ +export declare type ClientConfiguration = object; +export declare type ProxyArgs = { + query: string; + params?: unknown[]; +}; +export declare type ExecuteQueryArgs = object | string; +export declare type Row = object; +declare const _default: { + methods: { + /** + * A helper method to get the configuration object that's directly fed to + * the DB client constructor. Used by other features (like SQL proxy) to + * initialize their client in an identical way. + * + * @returns The configuration object for the DB client + */ + getClientConfiguration(): ClientConfiguration; + /** + * Executes a query against the database. This method takes care of + * connecting to the database, executing the query, and closing the + * connection. + * + * @param args - The query string or object to be sent to the DB. SQL query. + * @returns The rows returned by the DB as a result of the query. + */ + executeQuery(args: ExecuteQueryArgs): Row[]; + /** + * Adapts the arguments to `executeQuery` so that they can be consumed by + * the SQL proxy (when applicable). Note that this method is not intended to + * be used by the component directly. + * + * @param args - The query string or object to be sent to the DB. + * @returns The adapted query and parameters. + */ + proxyAdapter(args: ExecuteQueryArgs): ProxyArgs; + /** + * A method that performs the inverse transformation of `proxyAdapter`. + * + * @param args - The output of `proxyAdapter`. + * @returns The query string or object to be sent to the DB. + */ + executeQueryAdapter(args: ProxyArgs): ExecuteQueryArgs; + }; +}; +export default _default; diff --git a/platform/dist/utils.d.ts b/platform/dist/utils.d.ts new file mode 100644 index 0000000000000..6885d9171eb16 --- /dev/null +++ b/platform/dist/utils.d.ts @@ -0,0 +1,2 @@ +export declare function cloneSafe(o: any): any; +export declare function jsonStringifySafe(v: any, set?: Set): string | undefined; diff --git a/platform/lib/sql-prop.ts b/platform/lib/sql-prop.ts index 7be2155b0f81e..adaed94d19d7d 100644 --- a/platform/lib/sql-prop.ts +++ b/platform/lib/sql-prop.ts @@ -1,7 +1,22 @@ import { ConfigurationError } from "./errors"; -import { JsonValue } from "type-fest"; +import { JsonPrimitive } from "type-fest"; -export type DbSchema = JsonValue; +export type DbSchema = { + [tableName: string]: { + [columnName: string]: { + columnDefault: JsonPrimitive; + dataType: string; + isNullable: boolean; + tableSchema?: string; + }; + }; +}; + +export type RowCount = { + [tableName: string]: { + _rowCount?: number; + }; +}; export default { methods: { @@ -14,7 +29,7 @@ export default { * JSON-serializable object. * @throws {ConfigurationError} If the method is not implemented. */ - getSchema(): DbSchema { + getSchema(): DbSchema | RowCount { throw new ConfigurationError("getSchema not implemented"); }, }, diff --git a/platform/package.json b/platform/package.json index 28a999ec8927f..44747ec392a80 100644 --- a/platform/package.json +++ b/platform/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/platform", - "version": "1.6.4", + "version": "1.6.5", "description": "Pipedream platform globals (typing and runtime type checking)", "homepage": "https://pipedream.com", "main": "dist/index.js",