@ai-workflow-pack/adapters
v1.0.1
Published
Infrastructure adapters (database, cache, queue, storage) for AI Workflow services
Downloads
206
Maintainers
Readme
@ai-workflow-pack/adapters
Infrastructure adapters providing unified interfaces for databases, caching, queues, and storage across AI Workflow microservices.
Installation
npm install @ai-workflow-pack/adaptersFeatures
- 🗄️ Database Adapters: TypeORM, Sequelize, MongoDB
- ⚡ Cache Adapters: Redis, Memcached, In-Memory
- 📬 Queue Adapters: RabbitMQ, Kafka, AWS SQS, NATS
- 💾 Storage Adapters: AWS S3, Azure Blob, Local File System
Usage
Database Adapter
import { TypeORMAdapter, DatabaseConfig } from '@ai-workflow-pack/adapters';
const dbAdapter = new TypeORMAdapter({
type: 'postgres',
host: 'localhost',
port: 5432,
database: 'mydb',
username: 'user',
password: 'pass',
});
await dbAdapter.connect();
const results = await dbAdapter.query('SELECT * FROM users');
await dbAdapter.disconnect();Cache Adapter
import { RedisAdapter } from '@ai-workflow-pack/adapters';
const cacheAdapter = new RedisAdapter({
host: 'localhost',
port: 6379,
});
await cacheAdapter.set('key', 'value', 3600); // TTL in seconds
const value = await cacheAdapter.get('key');
await cacheAdapter.delete('key');Queue Adapter
RabbitMQ
import { RabbitMQAdapter } from '@ai-workflow-pack/adapters';
const queueAdapter = new RabbitMQAdapter({
url: 'amqp://localhost:5672',
});
await queueAdapter.connect();
await queueAdapter.publish('my-queue', { data: 'message' });
await queueAdapter.subscribe('my-queue', async (message) => {
console.log('Received:', message);
});NATS (Real-time Communication)
import { NatsAdapter } from '@ai-workflow-pack/adapters';
const natsAdapter = new NatsAdapter({
servers: 'nats://localhost:4222',
});
await natsAdapter.connect();
// Pub/Sub
await natsAdapter.publish('workflow.event', { workflowId: 123 });
await natsAdapter.subscribe('workflow.event', async (message) => {
console.log('Received:', message.data);
});
// Request-Reply
await natsAdapter.reply('workflow.status', async (data) => {
return { status: 'active' };
});
const response = await natsAdapter.request('workflow.status', { workflowId: 123 });See NATS_QUICK_START.md for more details.
Storage Adapter
import { S3Adapter } from '@ai-workflow-pack/adapters';
const storageAdapter = new S3Adapter({
accessKeyId: 'key',
secretAccessKey: 'secret',
region: 'us-east-1',
bucket: 'my-bucket',
});
await storageAdapter.upload('file.txt', buffer);
const file = await storageAdapter.download('file.txt');
await storageAdapter.delete('file.txt');Switching Implementations
All adapters implement common interfaces, making it easy to switch implementations:
// Development: Use in-memory cache
const cache = new InMemoryCacheAdapter();
// Production: Use Redis
const cache = new RedisAdapter({ host: 'redis', port: 6379 });
// Same interface for both!
await cache.set('key', 'value');
const value = await cache.get('key');License
MIT
