Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions docs/guide/activity-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ export const activities = declareActivitiesHandler({
contract: orderContract,
// logging wraps timing wraps the implementation
middleware: composeActivityMiddleware(logging, timing),
activities: {
/* ... */
},
activities: {/* ... */},
});
```

Expand Down
21 changes: 6 additions & 15 deletions docs/guide/client-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ await client.executeWorkflow("processOrder", {
// ❌ Error - Wrong workflow name
await client.executeWorkflow("invalidWorkflow", {
workflowId: "order-123",
args: {
/* ... */
},
args: {/* ... */},
});
```

Expand Down Expand Up @@ -328,9 +326,8 @@ const logging: ClientInterceptor = (args, next) =>

// Retry a transient failure once
const retryOnce: ClientInterceptor = (args, next) =>
next().flatMapErr(
(error): ReturnType<typeof next> =>
error instanceof RuntimeClientError ? next() : Err(error).toAsync(),
next().flatMapErr((error): ReturnType<typeof next> =>
error instanceof RuntimeClientError ? next() : Err(error).toAsync(),
);

const client = await TypedClient.create({
Expand Down Expand Up @@ -413,15 +410,9 @@ const inventoryClient = await TypedClient.create({
}).getOrThrow();

// Each client is typed to its contract
await orderClient.executeWorkflow("processOrder", {
/* ... */
});
await paymentClient.executeWorkflow("processPayment", {
/* ... */
});
await inventoryClient.executeWorkflow("updateStock", {
/* ... */
});
await orderClient.executeWorkflow("processOrder", {/* ... */});
await paymentClient.executeWorkflow("processPayment", {/* ... */});
await inventoryClient.executeWorkflow("updateStock", {/* ... */});
```

## Testing
Expand Down
48 changes: 12 additions & 36 deletions docs/guide/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ const contract = defineContract({
taskQueue: "my-queue",
workflows: {
myWorkflow: {
input: z.object({
/* ... */
}),
output: z.object({
/* ... */
}),
activities: {
/* ... */
},
input: z.object({/* ... */}),
output: z.object({/* ... */}),
activities: {/* ... */},
},
},
});
Expand Down Expand Up @@ -90,9 +84,7 @@ const contract = defineContract({
success: z.boolean(),
transactionId: z.string(),
}),
activities: {
/* ... */
},
activities: {/* ... */},
},
},
});
Expand Down Expand Up @@ -177,9 +169,7 @@ const contract = defineContract({
},
},

workflows: {
/* ... */
},
workflows: {/* ... */},
});
```

Expand Down Expand Up @@ -287,18 +277,14 @@ const emailActivities = {
const ordersContract = defineContract({
taskQueue: "orders",
activities: emailActivities,
workflows: {
/* ... */
},
workflows: {/* ... */},
});

// Contract 2 (reusing activities)
const shipmentsContract = defineContract({
taskQueue: "shipments",
activities: emailActivities,
workflows: {
/* ... */
},
workflows: {/* ... */},
});
```

Expand All @@ -313,28 +299,18 @@ Define focused contracts for specific domains:
const ordersContract = defineContract({
taskQueue: "orders",
workflows: {
processOrder: {
/* ... */
},
cancelOrder: {
/* ... */
},
processOrder: {/* ... */},
cancelOrder: {/* ... */},
},
});

// ❌ Avoid - too broad
const everythingContract = defineContract({
taskQueue: "everything",
workflows: {
processOrder: {
/* ... */
},
sendEmail: {
/* ... */
},
updateInventory: {
/* ... */
},
processOrder: {/* ... */},
sendEmail: {/* ... */},
updateInventory: {/* ... */},
// ... 50 more workflows
},
});
Expand Down
36 changes: 9 additions & 27 deletions docs/guide/defining-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,23 +312,17 @@ export const ecommerceContract = defineContract({
processOrder: {
input: z.object({ orderId: z.string() }),
output: z.object({ success: z.boolean() }),
activities: {
/* ... */
},
activities: {/* ... */},
},
processRefund: {
input: z.object({ orderId: z.string(), reason: z.string() }),
output: z.object({ refunded: z.boolean() }),
activities: {
/* ... */
},
activities: {/* ... */},
},
updateInventory: {
input: z.object({ productId: z.string(), delta: z.number() }),
output: z.object({ newQuantity: z.number() }),
activities: {
/* ... */
},
activities: {/* ... */},
},
},
});
Expand All @@ -345,31 +339,19 @@ Group related workflows in the same contract:
export const orderContract = defineContract({
taskQueue: "orders",
workflows: {
createOrder: {
/* ... */
},
cancelOrder: {
/* ... */
},
updateOrder: {
/* ... */
},
createOrder: {/* ... */},
cancelOrder: {/* ... */},
updateOrder: {/* ... */},
},
});

// ❌ Avoid - mixing unrelated workflows
export const contract = defineContract({
taskQueue: "everything",
workflows: {
processOrder: {
/* ... */
},
sendEmail: {
/* ... */
},
generateReport: {
/* ... */
},
processOrder: {/* ... */},
sendEmail: {/* ... */},
generateReport: {/* ... */},
},
});
```
Expand Down
4 changes: 1 addition & 3 deletions packages/contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export const myContract = defineContract({
processOrder: {
input: z.object({ orderId: z.string() }),
output: z.object({ success: z.boolean() }),
activities: {
/* ... */
},
activities: {/* ... */},
},
},
});
Expand Down
Loading
Loading