absurd-sdk 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  TypeScript SDK for [Absurd](https://github.com/earendil-works/absurd): a PostgreSQL-based durable task execution system.
4
4
 
5
- Absurd is the simplest durable execution workflow system you can think of. It's entirely based on Postgres and nothing else. It's almost as easy to use as a queue, but it handles scheduling and retries, and it does all of that without needing any other services to run in addition to Postgres.
5
+ Absurd is the simplest durable execution workflow system you can think of. It's entirely based on Postgres and nothing else. It's almost as easy to use as a queue, but it handles scheduling and retries, and it does all of that without needing any other services to run in addition to Postgres.
6
6
 
7
- **Warning:** *this is an early experiment and should not be used in production.*
7
+ **Warning:** _this is an early experiment and should not be used in production._
8
8
 
9
9
  ## What is Durable Execution?
10
10
 
@@ -13,7 +13,7 @@ Durable execution (or durable workflows) is a way to run long-lived, reliable fu
13
13
  ## Installation
14
14
 
15
15
  ```bash
16
- npm install absurd-sdk
16
+ npm install absurd-sdk pg
17
17
  ```
18
18
 
19
19
  ## Prerequisites
@@ -29,28 +29,26 @@ absurdctl create-queue -d your-database-name default
29
29
  ## Quick Start
30
30
 
31
31
  ```typescript
32
- import { Absurd } from 'absurd-sdk';
32
+ import { Absurd } from "absurd-sdk";
33
33
 
34
- const app = new Absurd({
35
- connectionString: 'postgresql://localhost/mydb'
36
- });
34
+ const app = new Absurd({ db: "postgresql://localhost/mydb" });
37
35
 
38
36
  // Register a task
39
- app.registerTask({ name: 'order-fulfillment' }, async (params, ctx) => {
37
+ app.registerTask({ name: "order-fulfillment" }, async (params, ctx) => {
40
38
  // Each step is checkpointed, so if the process crashes, we resume
41
39
  // from the last completed step
42
- const payment = await ctx.step('process-payment', async () => {
40
+ const payment = await ctx.step("process-payment", async () => {
43
41
  return await processPayment(params.amount);
44
42
  });
45
43
 
46
- const inventory = await ctx.step('reserve-inventory', async () => {
44
+ const inventory = await ctx.step("reserve-inventory", async () => {
47
45
  return await reserveItems(params.items);
48
46
  });
49
47
 
50
48
  // Wait for an event - the task suspends until the event arrives
51
49
  const shipment = await ctx.awaitEvent(`shipment.packed:${params.orderId}`);
52
50
 
53
- await ctx.step('send-notification', async () => {
51
+ await ctx.step("send-notification", async () => {
54
52
  return await sendEmail(params.email, shipment);
55
53
  });
56
54
 
@@ -65,11 +63,11 @@ await app.startWorker();
65
63
 
66
64
  ```typescript
67
65
  // Spawn a task - it will be executed durably with automatic retries
68
- await app.spawn('order-fulfillment', {
69
- orderId: '42',
66
+ await app.spawn("order-fulfillment", {
67
+ orderId: "42",
70
68
  amount: 9999,
71
- items: ['widget-1', 'gadget-2'],
72
- email: 'customer@example.com'
69
+ items: ["widget-1", "gadget-2"],
70
+ email: "customer@example.com",
73
71
  });
74
72
  ```
75
73
 
@@ -77,8 +75,8 @@ await app.spawn('order-fulfillment', {
77
75
 
78
76
  ```typescript
79
77
  // Emit an event that a suspended task might be waiting for
80
- await app.emitEvent('shipment.packed:42', {
81
- trackingNumber: 'TRACK123'
78
+ await app.emitEvent("shipment.packed:42", {
79
+ trackingNumber: "TRACK123",
82
80
  });
83
81
  ```
84
82
 
@@ -87,7 +85,7 @@ await app.emitEvent('shipment.packed:42', {
87
85
  Use the task ID to derive idempotency keys for external APIs:
88
86
 
89
87
  ```typescript
90
- const payment = await ctx.step('process-payment', async () => {
88
+ const payment = await ctx.step("process-payment", async () => {
91
89
  const idempotencyKey = `${ctx.taskID}:payment`;
92
90
  return await stripe.charges.create({
93
91
  amount: params.amount,