Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform/dist/axios.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosRequestConfig } from "./index";
export declare function transformConfigForOauth(config: AxiosRequestConfig): {
method: string;
method: (string & {}) | import("axios").Method;
url: string;
};
declare function callAxios(step: any, config: AxiosRequestConfig, signConfig?: any): Promise<any>;
Expand Down
4 changes: 2 additions & 2 deletions platform/dist/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function callAxios(step, config, signConfig) {
if (config.debug) {
stepExport(step, config, "debug_config");
}
const response = await axios_1.default(config);
const response = await (0, axios_1.default)(config);
if (config.debug) {
stepExport(step, response.data, "debug_response");
}
Expand All @@ -124,7 +124,7 @@ async function callAxios(step, config, signConfig) {
}
}
function stepExport(step, message, key) {
message = utils_1.cloneSafe(message);
message = (0, utils_1.cloneSafe)(message);
if (step) {
if (step.export) {
step.export(key, message);
Expand Down
68 changes: 57 additions & 11 deletions platform/dist/file-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const mime = require("mime-types");
* @returns a Readable stream of the file content
*/
async function getFileStream(pathOrUrl) {
if (isUrl(pathOrUrl)) {
if (isDataUrl(pathOrUrl)) {
return getDataUrlStream(pathOrUrl);
}
else if (isUrl(pathOrUrl)) {
const response = await fetch(pathOrUrl);
if (!response.ok || !response.body) {
throw new Error(`Failed to fetch ${pathOrUrl}: ${response.status} ${response.statusText}`);
Expand All @@ -22,7 +25,7 @@ async function getFileStream(pathOrUrl) {
}
else {
await safeStat(pathOrUrl);
return fs_1.createReadStream(pathOrUrl);
return (0, fs_1.createReadStream)(pathOrUrl);
}
}
exports.getFileStream = getFileStream;
Expand All @@ -31,7 +34,10 @@ exports.getFileStream = getFileStream;
* @returns a Readable stream of the file content and its metadata
*/
async function getFileStreamAndMetadata(pathOrUrl) {
if (isUrl(pathOrUrl)) {
if (isDataUrl(pathOrUrl)) {
return getDataUrlStreamAndMetadata(pathOrUrl);
}
else if (isUrl(pathOrUrl)) {
return await getRemoteFileStreamAndMetadata(pathOrUrl);
}
else {
Expand All @@ -48,6 +54,46 @@ function isUrl(pathOrUrl) {
return false;
}
}
function isDataUrl(pathOrUrl) {
return pathOrUrl.startsWith("data:");
}
function parseDataUrl(dataUrl) {
// Format: data:[<mediatype>][;base64],<data>
const match = dataUrl.match(/^data:([^;,]*)?(?:;(base64))?,(.*)$/);
if (!match) {
throw new Error("Invalid data URL format");
}
const [, mediaType = "text/plain;charset=US-ASCII", base64Flag, data,] = match;
return {
mediaType,
isBase64: base64Flag === "base64",
data,
};
}
function getDataUrlStream(dataUrl) {
const parsed = parseDataUrl(dataUrl);
const buffer = parsed.isBase64
? Buffer.from(parsed.data, "base64")
: Buffer.from(decodeURIComponent(parsed.data), "utf-8");
return stream_1.Readable.from(buffer);
}
function getDataUrlStreamAndMetadata(dataUrl) {
const parsed = parseDataUrl(dataUrl);
const buffer = parsed.isBase64
? Buffer.from(parsed.data, "base64")
: Buffer.from(decodeURIComponent(parsed.data), "utf-8");
const ext = mime.extension(parsed.mediaType);
const name = ext ? `file.${ext}` : "file";
const metadata = {
size: buffer.length,
contentType: parsed.mediaType || undefined,
name,
};
return {
stream: stream_1.Readable.from(buffer),
metadata,
};
}
async function safeStat(path) {
try {
return await fs_1.promises.stat(path);
Expand All @@ -62,10 +108,10 @@ async function getLocalFileStreamAndMetadata(filePath) {
const metadata = {
size: stats.size,
lastModified: stats.mtime,
name: path_1.basename(filePath),
name: (0, path_1.basename)(filePath),
contentType,
};
const stream = fs_1.createReadStream(filePath);
const stream = (0, fs_1.createReadStream)(filePath);
return {
stream,
metadata,
Expand All @@ -83,7 +129,7 @@ async function getRemoteFileStreamAndMetadata(url) {
: undefined;
const etag = headers.get("etag") || undefined;
const urlObj = new URL(url);
const name = path_1.basename(urlObj.pathname);
const name = (0, path_1.basename)(urlObj.pathname);
const contentType = headers.get("content-type") || mime.lookup(urlObj.pathname) || undefined;
const baseMetadata = {
contentType,
Expand All @@ -108,19 +154,19 @@ async function getRemoteFileStreamAndMetadata(url) {
}
async function downloadToTemporaryFile(response, baseMetadata) {
// Generate unique temporary file path
const tempFileName = `file-stream-${uuid_1.v4()}`;
const tempFilePath = path_1.join(os_1.tmpdir(), tempFileName);
const tempFileName = `file-stream-${(0, uuid_1.v4)()}`;
const tempFilePath = (0, path_1.join)((0, os_1.tmpdir)(), tempFileName);
// Download to temporary file
const fileStream = fs_1.createWriteStream(tempFilePath);
const fileStream = (0, fs_1.createWriteStream)(tempFilePath);
const webStream = stream_1.Readable.fromWeb(response.body);
try {
await promises_1.pipeline(webStream, fileStream);
await (0, promises_1.pipeline)(webStream, fileStream);
const stats = await fs_1.promises.stat(tempFilePath);
const metadata = {
...baseMetadata,
size: stats.size,
};
const stream = fs_1.createReadStream(tempFilePath);
const stream = (0, fs_1.createReadStream)(tempFilePath);
const cleanup = async () => {
try {
await fs_1.promises.unlink(tempFilePath);
Expand Down
14 changes: 7 additions & 7 deletions platform/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export declare const SendConfigEmail: t.PartialC<{
subject: t.StringC;
text: t.StringC;
}>;
export declare type SendConfigEmail = t.TypeOf<typeof SendConfigEmail>;
export type SendConfigEmail = t.TypeOf<typeof SendConfigEmail>;
export declare const SendConfigEmit_required: t.ExactC<t.TypeC<{
raw_event: t.ObjectC;
}>>;
Expand All @@ -27,7 +27,7 @@ export declare const SendConfigEmit: t.IntersectionC<[t.ExactC<t.TypeC<{
}>>, t.PartialC<{
event: t.ObjectC;
}>]>;
export declare type SendConfigEmit = t.TypeOf<typeof SendConfigEmit>;
export type SendConfigEmit = t.TypeOf<typeof SendConfigEmit>;
export declare const HTTP_METHODS: string[];
export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC<t.TypeC<{
method: t.KeyofC<{}>;
Expand All @@ -41,18 +41,18 @@ export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC<t.TypeC<{
headers: t.ObjectC;
params: t.ObjectC;
}>]>;
export declare type SendConfigHTTP = t.TypeOf<typeof SendConfigHTTP>;
export type SendConfigHTTP = t.TypeOf<typeof SendConfigHTTP>;
export declare const SendConfigS3: t.ExactC<t.TypeC<{
bucket: t.StringC;
payload: t.UnionC<[t.StringC, t.ObjectC]>;
prefix: t.StringC;
}>>;
export declare type SendConfigS3 = t.TypeOf<typeof SendConfigS3>;
export type SendConfigS3 = t.TypeOf<typeof SendConfigS3>;
export declare const SendConfigSQL: t.ExactC<t.TypeC<{
payload: t.UnionC<[t.StringC, t.ObjectC]>;
table: t.StringC;
}>>;
export declare type SendConfigSQL = t.TypeOf<typeof SendConfigSQL>;
export type SendConfigSQL = t.TypeOf<typeof SendConfigSQL>;
export declare const SendConfigSnowflake: t.ExactC<t.TypeC<{
account: t.StringC;
database: t.StringC;
Expand All @@ -64,12 +64,12 @@ export declare const SendConfigSnowflake: t.ExactC<t.TypeC<{
stage_name: t.StringC;
user: t.StringC;
}>>;
export declare type SendConfigSnowflake = t.TypeOf<typeof SendConfigSnowflake>;
export type SendConfigSnowflake = t.TypeOf<typeof SendConfigSnowflake>;
export declare const SendConfigSSE: t.ExactC<t.TypeC<{
channel: t.StringC;
payload: t.UnionC<[t.StringC, t.ObjectC]>;
}>>;
export declare type SendConfigSSE = t.TypeOf<typeof SendConfigSSE>;
export type SendConfigSSE = t.TypeOf<typeof SendConfigSSE>;
interface SendFunctionsWrapper {
email: (config: SendConfigEmail) => void;
emit: (config: SendConfigEmit) => void;
Expand Down
2 changes: 1 addition & 1 deletion platform/dist/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.$sendConfigRuntimeTypeChecker = exports.$send = exports.$end = exports.END_NEEDLE = exports.$event = exports.sendTypeMap = exports.SendConfigSSE = exports.SendConfigSnowflake = exports.SendConfigSQL = exports.SendConfigS3 = exports.SendConfigHTTP = exports.HTTP_METHODS = exports.SendConfigEmit = exports.SendConfigEmit_optional = exports.SendConfigEmit_required = exports.SendConfigEmail = exports.transformConfigForOauth = exports.axios = void 0;
exports.$sendConfigRuntimeTypeChecker = exports.$send = exports.$end = exports.END_NEEDLE = exports.$event = exports.sendTypeMap = exports.SendConfigSSE = exports.SendConfigSnowflake = exports.SendConfigSQL = exports.SendConfigS3 = exports.SendConfigHTTP = exports.HTTP_METHODS = exports.SendConfigEmit = exports.SendConfigEmit_optional = exports.SendConfigEmit_required = exports.SendConfigEmail = exports.PD_OFFICIAL_GMAIL_OAUTH_CLIENT_ID = exports.DEFAULT_POLLING_SOURCE_TIMER_INTERVAL = exports.sqlProxy = exports.sqlProp = exports.ConfigurationError = exports.getFileStream = exports.getFileStreamAndMetadata = exports.jsonStringifySafe = exports.cloneSafe = exports.transformConfigForOauth = exports.axios = void 0;
const t = require("io-ts");
const axios_1 = require("./axios");
exports.axios = axios_1.default;
Expand Down
12 changes: 6 additions & 6 deletions platform/dist/sql-prop.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { JsonPrimitive } from "type-fest";
import { ExecuteQueryArgs } from "./sql";
export declare type ColumnSchema = {
export type ColumnSchema = {
columnDefault: JsonPrimitive;
dataType: string;
isNullable: boolean;
tableSchema?: string;
};
export declare type TableMetadata = {
export type TableMetadata = {
rowCount?: number;
};
export declare type TableSchema = {
export type TableSchema = {
[columnName: string]: ColumnSchema;
};
export declare type TableInfo = {
export type TableInfo = {
metadata: TableMetadata;
schema: TableSchema;
};
export declare type DbInfo = {
export type DbInfo = {
[tableName: string]: TableInfo;
};
export declare type SqlProp = {
export type SqlProp = {
query: string;
params?: string[];
};
Expand Down
6 changes: 3 additions & 3 deletions platform/dist/sql-proxy.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ExecuteQueryArgs } from "./sql";
export declare type ClientConfiguration = object;
export declare type ProxyArgs = {
export type ClientConfiguration = object;
export type ProxyArgs = {
query: string;
params?: unknown[];
};
export declare type Row = object;
export type Row = object;
declare const _default: {
methods: {
/**
Expand Down
2 changes: 1 addition & 1 deletion platform/dist/sql.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare type ExecuteQueryArgs = object | string;
export type ExecuteQueryArgs = object | string;
Loading