@fabricate-tools/client
v1.4.0
Published
The official Fabricate client
Readme
Fabricate Client
The official Fabricate client package for TypeScript/JavaScript.
Installation
npm install @fabricate-tools/clientUsage
Generate and Download Data
To generate and download data from Fabricate:
import { generate } from '@fabricate-tools/client'
await generate({
// The workspace to use
workspace: 'Default',
// The name of the database to generate
database: 'ecommerce',
// The format to generate. Should be one of:
// - 'sql'
// - 'sqlite'
// - 'csv'
// - 'jsonl'
format: 'sql',
// The destination to save the data
dest: './data',
// Optional: Overwrite the destination if it exists
overwrite: true,
// Optional: Generate a single table
// entity: 'Customers',
})Push Data to a Database
To push generated data directly to an existing database:
import { generate } from '@fabricate-tools/client'
await generate({
// The workspace to use
workspace: 'Default',
// The name of the database in Fabricate
database: 'ecommerce',
// The connection details for the target database
connection: {
// The host of the target database
host: 'host.example.com',
// The port of the target database
port: 5432,
// The name of the target database
database_name: 'ecommerce',
// The username for the target database
username: process.env.FABRICATE_DATABASE_USERNAME,
// The password for the target database
password: process.env.FABRICATE_DATABASE_PASSWORD,
// Whether to use TLS for the connection
tls: true,
},
})Run a Workflow
To run a workflow and get the result:
import { runWorkflow } from '@fabricate-tools/client'
const { result, task, downloadFile, downloadAllFiles } = await runWorkflow({
// The workspace containing the database
workspace: 'Default',
// The name of the database
database: 'my_database',
// The name of the workflow to run
workflow: 'my_workflow',
// Parameters to pass to the workflow
params: {
startDate: '2024-01-01',
endDate: '2024-12-31',
},
// Optional: Receive progress updates
onProgress: ({ status, message }) => {
console.log(`[${status}] ${message}`)
},
})
// The result contains whatever was passed to sendResult() in the workflow
console.log(result)
// Download any files generated by the workflow
if (task.files && task.files.length > 0) {
// Download all files to a directory
await downloadAllFiles('./output')
// Or download a specific file
const file = task.files[0]
await downloadFile(file.id, `./output/${file.name}`)
}TypeScript Support
This package includes TypeScript definitions. You can import types for better IDE support:
import { generate, runWorkflow } from '@fabricate-tools/client'
import type {
GenerateOptions,
RunWorkflowOptions,
WorkflowTask
} from '@fabricate-tools/client'