A lightweight TypeScript framework providing lambda-like DX on top of Temporal's durable execution engine
npm install @astami/temporal-functionsA lightweight TypeScript framework that provides a lambda-like developer experience on top of Temporal's durable execution engine.
Write only function bodies and trigger bindings — the framework handles all Temporal boilerplate (workers, activities, workflows, serialization).
| Aspect | Lambda/Serverless | Raw Temporal | Temporal Functions |
|--------|-------------------|--------------|-------------------|
| Function definition | Simple | Verbose | Simple |
| Durable execution | No | Yes | Yes |
| Retries/timeouts | Limited | Powerful | Powerful |
| Worker management | Managed | Manual | Abstracted |
| Type safety | Varies | Yes | Yes |
``typescript
import { tfn } from 'temporal-functions';
// Define functions (activities)
export const validateOrder = tfn.fn('validateOrder', async (order: Order) => {
// validation logic
});
export const chargePayment = tfn.fn('chargePayment', async (order: ValidatedOrder) => {
// payment logic
});
// Define workflow
export const processOrder = tfn.workflow('processOrder', async (ctx, order: Order) => {
const validated = await ctx.run(validateOrder, order);
const paid = await ctx.run(chargePayment, validated);
return { orderId: paid.id, status: 'complete' };
});
`
That's it. No worker setup, no activity proxies, no boilerplate.
1. Lambda-like DX — Write functions, not infrastructure
2. Temporal underneath — Get durability, retries, exactly-once semantics for free
3. TypeScript native — Full type safety, great IDE support
4. Client-Worker separation — Scale triggers and executors independently
5. Minimal abstraction — Thin layer, not a new platform
`bash`
npm install temporal-functions
`typescript
import { tfn } from 'temporal-functions';
export const sendEmail = tfn.fn(
'sendEmail',
async (params: EmailParams): Promise
return await emailService.send(params);
},
{
timeout: '30s',
retries: 3,
}
);
`
`typescript
export const processOrder = tfn.workflow(
'processOrder',
async (ctx, order: Order) => {
const validated = await ctx.run(validateOrder, order);
// Parallel execution
const [inventory, pricing] = await Promise.all([
ctx.run(checkInventory, validated.items),
ctx.run(calculatePricing, validated.items),
]);
// Durable sleep
await ctx.sleep('5 minutes');
const payment = await ctx.run(processPayment, {
amount: pricing.total,
orderId: order.id,
});
return { orderId: order.id, status: 'complete' };
}
);
`
`typescript
import { tfn } from 'temporal-functions/client';
import { processOrder } from '@myproject/functions';
const client = tfn.client({
temporal: {
address: 'localhost:7233',
namespace: 'default',
},
taskQueue: 'orders',
});
// Fire and wait
const result = await client.invoke(processOrder, order);
// Fire and forget
const handle = await client.start(processOrder, order, {
workflowId: order-${order.id},`
});
`typescript
import { tfn } from 'temporal-functions/worker';
import { validateOrder, chargePayment, processOrder } from '@myproject/functions';
const worker = tfn.worker({
temporal: {
address: 'localhost:7233',
namespace: 'default',
},
taskQueue: 'orders',
});
worker.register(validateOrder);
worker.register(chargePayment);
worker.register(processOrder);
await worker.start();
`
`typescript
// HTTP
tfn.http('POST', '/api/orders', processOrder);
// Cron
tfn.cron('0 9 *', dailyReport);
// Signal
tfn.signal('order.cancel', handleCancellation);
`
``
my-project/
├── packages/
│ ├── functions/ # Shared function definitions
│ │ └── src/
│ │ ├── orders/
│ │ └── notifications/
│ ├── worker/ # Worker service
│ │ └── src/index.ts
│ └── api/ # API/Client service
│ └── src/index.ts
└── package.json
```
┌─────────────────────────────────────────────────────────────┐
│ TEMPORAL FUNCTIONS │
├─────────────────────────────────────────────────────────────┤
│ │
│ SHARED: Function Definitions │
│ tfn.fn() tfn.workflow() Types & Interfaces │
│ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ CLIENT │ │ WORKER │ │
│ │ Lightweight │ │ Full SDK │ │
│ │ ~20KB │ │ ~2MB │ │
│ │ │ │ │ │
│ │ • start() │ │ • register()│ │
│ │ • invoke() │ │ • start() │ │
│ │ • signal() │ │ │ │
│ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │
│ └───────────┬───────────────┘ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ TEMPORAL CLUSTER │ │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
See docs/ARCHITECTURE.md for the full architecture document.
Design Phase — This project is currently in the design and early implementation phase.
MIT