Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@workflowai/code-generator

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@workflowai/code-generator - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

5

dist/cjs/playground.d.ts
import { JsonSchemaObject } from '@workflowai/schema';
export type FileDataProvider = 'fs-promise' | 'fetch' | 'axios';
type GeneratedCode = {

@@ -17,2 +18,3 @@ language: 'bash' | 'typescript';

input: Record<string, unknown>;
output: Record<string, unknown>;
};

@@ -23,4 +25,6 @@ api?: {

};
fileDataProvider?: FileDataProvider;
};
type GetPlaygroundSnippetsResult = {
isUsingFileDataProvider: boolean;
installSdk: GeneratedCode;

@@ -30,4 +34,5 @@ initializeClient: GeneratedCode;

runTask: GeneratedCode;
importTaskRun: GeneratedCode;
};
export declare const getPlaygroundSnippets: (config: GetPlaygroundSnippetsConfig) => Promise<GetPlaygroundSnippetsResult>;
export {};

47

dist/cjs/playground.js

@@ -23,6 +23,24 @@ "use strict";

};
const base64DataToFileDataProvider = (str, fileDataProvider) => {
return str.replace(/"[-A-Za-z0-9+/]{50,}={0,3}"/g, {
'fs-promise': 'readFile("/path/to/file")',
fetch: '(await fetch("http://url.to/file")).arrayBuffer()',
axios: '(await axios.get("http://url.to/file", { responseType: "arraybuffer" })).data',
}[fileDataProvider]);
};
const getPlaygroundSnippets = async (config) => {
const { taskId, taskName, schema, groupId, example, api } = config;
const { taskId, taskName, schema, groupId, example, api, fileDataProvider = 'fs-promise', } = {
...config,
};
const taskFunctionName = validVarName(taskName || taskId);
const _stringifiedInput = JSON.stringify(example.input, null, 2);
const beautifiedInput = base64DataToFileDataProvider(_stringifiedInput, fileDataProvider);
const isUsingFileDataProvider = beautifiedInput !== _stringifiedInput;
const fileProviderImport = {
'fs-promise': 'import { readFile } from "fs/promises"\n',
fetch: '',
axios: 'import axios from "axios"\n',
}[fileDataProvider];
return {
isUsingFileDataProvider,
installSdk: {

@@ -73,11 +91,34 @@ language: 'bash',

code: `
import { TaskInput } from "@workflowai/workflowai"
${[
'import { TaskInput } from "@workflowai/workflowai"',
isUsingFileDataProvider && fileProviderImport,
]
.filter(Boolean)
.join('\n')}
${`const input: TaskInput<typeof ${taskFunctionName}> = ${(0, beautify_1.beautifyTypescript)(JSON.stringify(example.input))}`}
const input: TaskInput<typeof ${taskFunctionName}> = ${beautifiedInput}
const output = await ${taskFunctionName}(input)
console.log(output)
`.trim(),
},
importTaskRun: {
language: 'typescript',
code: `
${[
'import { TaskInput, TaskOutput } from "@workflowai/workflowai"',
isUsingFileDataProvider && fileProviderImport,
]
.filter(Boolean)
.join('\n')}
const input: TaskInput<typeof ${taskFunctionName}> = ${beautifiedInput}
const ouput: TaskOutput<typeof ${taskFunctionName}> = ${(0, beautify_1.beautifyTypescript)(JSON.stringify(example.output))}
await ${taskFunctionName}.importRun(input, output)
`.trim(),
},
};
};
exports.getPlaygroundSnippets = getPlaygroundSnippets;

@@ -20,6 +20,24 @@ import { inputSchemaToZod, outputSchemaToZod, } from '@workflowai/schema';

};
const base64DataToFileDataProvider = (str, fileDataProvider) => {
return str.replace(/"[-A-Za-z0-9+/]{50,}={0,3}"/g, {
'fs-promise': 'readFile("/path/to/file")',
fetch: '(await fetch("http://url.to/file")).arrayBuffer()',
axios: '(await axios.get("http://url.to/file", { responseType: "arraybuffer" })).data',
}[fileDataProvider]);
};
export const getPlaygroundSnippets = async (config) => {
const { taskId, taskName, schema, groupId, example, api } = config;
const { taskId, taskName, schema, groupId, example, api, fileDataProvider = 'fs-promise', } = {
...config,
};
const taskFunctionName = validVarName(taskName || taskId);
const _stringifiedInput = JSON.stringify(example.input, null, 2);
const beautifiedInput = base64DataToFileDataProvider(_stringifiedInput, fileDataProvider);
const isUsingFileDataProvider = beautifiedInput !== _stringifiedInput;
const fileProviderImport = {
'fs-promise': 'import { readFile } from "fs/promises"\n',
fetch: '',
axios: 'import axios from "axios"\n',
}[fileDataProvider];
return {
isUsingFileDataProvider,
installSdk: {

@@ -70,10 +88,33 @@ language: 'bash',

code: `
import { TaskInput } from "@workflowai/workflowai"
${[
'import { TaskInput } from "@workflowai/workflowai"',
isUsingFileDataProvider && fileProviderImport,
]
.filter(Boolean)
.join('\n')}
${`const input: TaskInput<typeof ${taskFunctionName}> = ${beautifyTypescript(JSON.stringify(example.input))}`}
const input: TaskInput<typeof ${taskFunctionName}> = ${beautifiedInput}
const output = await ${taskFunctionName}(input)
console.log(output)
`.trim(),
},
importTaskRun: {
language: 'typescript',
code: `
${[
'import { TaskInput, TaskOutput } from "@workflowai/workflowai"',
isUsingFileDataProvider && fileProviderImport,
]
.filter(Boolean)
.join('\n')}
const input: TaskInput<typeof ${taskFunctionName}> = ${beautifiedInput}
const ouput: TaskOutput<typeof ${taskFunctionName}> = ${beautifyTypescript(JSON.stringify(example.output))}
await ${taskFunctionName}.importRun(input, output)
`.trim(),
},
};
};
import { JsonSchemaObject } from '@workflowai/schema';
export type FileDataProvider = 'fs-promise' | 'fetch' | 'axios';
type GeneratedCode = {

@@ -17,2 +18,3 @@ language: 'bash' | 'typescript';

input: Record<string, unknown>;
output: Record<string, unknown>;
};

@@ -23,4 +25,6 @@ api?: {

};
fileDataProvider?: FileDataProvider;
};
type GetPlaygroundSnippetsResult = {
isUsingFileDataProvider: boolean;
installSdk: GeneratedCode;

@@ -30,2 +34,3 @@ initializeClient: GeneratedCode;

runTask: GeneratedCode;
importTaskRun: GeneratedCode;
};

@@ -32,0 +37,0 @@ export declare const getPlaygroundSnippets: (config: GetPlaygroundSnippetsConfig) => Promise<GetPlaygroundSnippetsResult>;

2

package.json
{
"name": "@workflowai/code-generator",
"version": "1.0.5",
"version": "1.0.6",
"description": "workflowAI code-generator",

@@ -5,0 +5,0 @@ "author": "workflowAI",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc