@absurd-sqlite/bun-worker 0.2.2-alpha.2 → 0.3.0-alpha.1

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/test/setup.ts CHANGED
@@ -6,9 +6,10 @@ import { join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import {
8
8
  Absurd,
9
+ Temporal,
9
10
  type AbsurdHooks,
10
11
  type JsonValue,
11
- } from "absurd-sdk";
12
+ } from "@absurd-sqlite/sdk";
12
13
 
13
14
  import { BunSqliteConnection } from "../src/sqlite";
14
15
 
@@ -23,8 +24,8 @@ export interface TaskRow {
23
24
  retry_strategy: JsonValue | null;
24
25
  max_attempts: number | null;
25
26
  cancellation: JsonValue | null;
26
- enqueue_at: Date;
27
- first_started_at: Date | null;
27
+ enqueue_at: Temporal.Instant;
28
+ first_started_at: Temporal.Instant | null;
28
29
  state:
29
30
  | "pending"
30
31
  | "running"
@@ -35,7 +36,7 @@ export interface TaskRow {
35
36
  attempts: number;
36
37
  last_attempt_run: string | null;
37
38
  completed_payload: JsonValue | null;
38
- cancelled_at: Date | null;
39
+ cancelled_at: Temporal.Instant | null;
39
40
  }
40
41
 
41
42
  export interface RunRow {
@@ -50,16 +51,16 @@ export interface RunRow {
50
51
  | "failed"
51
52
  | "cancelled";
52
53
  claimed_by: string | null;
53
- claim_expires_at: Date | null;
54
- available_at: Date;
54
+ claim_expires_at: Temporal.Instant | null;
55
+ available_at: Temporal.Instant;
55
56
  wake_event: string | null;
56
57
  event_payload: JsonValue | null;
57
- started_at: Date | null;
58
- completed_at: Date | null;
59
- failed_at: Date | null;
58
+ started_at: Temporal.Instant | null;
59
+ completed_at: Temporal.Instant | null;
60
+ failed_at: Temporal.Instant | null;
60
61
  result: JsonValue | null;
61
62
  failure_reason: JsonValue | null;
62
- created_at: Date;
63
+ created_at: Temporal.Instant;
63
64
  }
64
65
 
65
66
  interface SqliteFixture {
@@ -263,10 +264,7 @@ export async function createTestAbsurd(
263
264
  queueName: string = "default"
264
265
  ): Promise<TestContext> {
265
266
  const fixture = createFixture();
266
- const absurd = new Absurd({
267
- db: fixture.conn,
268
- queueName,
269
- });
267
+ const absurd = new Absurd(fixture.conn, { queueName });
270
268
 
271
269
  await absurd.createQueue(queueName);
272
270
 
@@ -335,8 +333,7 @@ export async function createTestAbsurd(
335
333
  expectCancelledError: (promise: Promise<unknown>) =>
336
334
  expectCancelledError(promise),
337
335
  createClient: (options) => {
338
- const client = new Absurd({
339
- db: fixture.conn,
336
+ const client = new Absurd(fixture.conn, {
340
337
  queueName: options?.queueName ?? queueName,
341
338
  hooks: options?.hooks,
342
339
  });
@@ -5,6 +5,7 @@ import { join } from "node:path";
5
5
  import { tmpdir } from "node:os";
6
6
 
7
7
  import { BunSqliteConnection } from "../src/sqlite";
8
+ import { Temporal } from "@absurd-sqlite/sdk";
8
9
 
9
10
  describe("BunSqliteConnection", () => {
10
11
  it("rewrites postgres-style params and absurd schema names", async () => {
@@ -26,12 +27,14 @@ describe("BunSqliteConnection", () => {
26
27
  db.close();
27
28
  });
28
29
 
29
- it("returns empty rows for non-reader statements", async () => {
30
+ it("throws when query is used for non-reader statements", async () => {
30
31
  const db = new Database(":memory:");
31
32
  const conn = new BunSqliteConnection(db);
32
33
 
33
- const { rows } = await conn.query("CREATE TABLE t (id)");
34
- expect(rows).toEqual([]);
34
+ await expect(conn.query("CREATE TABLE t (id)")).rejects.toThrow(
35
+ "only statements that return data"
36
+ );
37
+ await conn.exec("CREATE TABLE t (id)");
35
38
 
36
39
  await conn.exec("INSERT INTO t (id) VALUES ($1)", [1]);
37
40
  const { rows: inserted } = await conn.query<{ id: number }>(
@@ -73,7 +76,7 @@ describe("BunSqliteConnection", () => {
73
76
  db.close();
74
77
  });
75
78
 
76
- it("decodes datetime columns into Date objects", async () => {
79
+ it("decodes datetime columns into Temporal.Instant objects", async () => {
77
80
  const db = new Database(":memory:");
78
81
  const conn = new BunSqliteConnection(db);
79
82
  const now = Date.now();
@@ -81,12 +84,12 @@ describe("BunSqliteConnection", () => {
81
84
  await conn.exec("CREATE TABLE t_date (created_at DATETIME)");
82
85
  await conn.exec("INSERT INTO t_date (created_at) VALUES ($1)", [now]);
83
86
 
84
- const { rows } = await conn.query<{ created_at: Date }>(
87
+ const { rows } = await conn.query<{ created_at: Temporal.Instant }>(
85
88
  "SELECT created_at FROM t_date"
86
89
  );
87
90
 
88
- expect(rows[0]?.created_at).toBeInstanceOf(Date);
89
- expect(rows[0]?.created_at.getTime()).toBe(now);
91
+ expect(rows[0]?.created_at).toBeInstanceOf(Temporal.Instant);
92
+ expect(rows[0]?.created_at.epochMilliseconds).toBe(now);
90
93
  db.close();
91
94
  });
92
95
 
@@ -146,14 +149,14 @@ describe("BunSqliteConnection", () => {
146
149
  }),
147
150
  };
148
151
 
149
- const querySpy = jest.fn().mockReturnValue(statement as any);
150
- const db = { query: querySpy } as unknown as Database;
152
+ const prepareSpy = jest.fn().mockReturnValue(statement as any);
153
+ const db = { prepare: prepareSpy } as unknown as Database;
151
154
  const conn = new BunSqliteConnection(db);
152
155
 
153
156
  await expect(
154
157
  conn.exec("UPDATE locked_table SET value = $1 WHERE id = $2", [1, 1])
155
158
  ).resolves.toBeUndefined();
156
159
  expect(statement.run).toHaveBeenCalledTimes(2);
157
- expect(querySpy).toHaveBeenCalledTimes(1);
160
+ expect(prepareSpy).toHaveBeenCalledTimes(1);
158
161
  });
159
162
  });
package/test/step.test.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { describe, test, expect, beforeAll, afterEach, jest } from "bun:test";
2
- import type { Absurd } from "absurd-sdk";
2
+ import { Temporal, type Absurd } from "@absurd-sqlite/sdk";
3
3
  import { createTestAbsurd, randomName, type TestContext } from "./setup";
4
4
 
5
5
  describe("Step functionality", () => {
@@ -193,7 +193,10 @@ describe("Step functionality", () => {
193
193
 
194
194
  const durationSeconds = 60;
195
195
  absurd.registerTask({ name: "sleep-for" }, async (_params, ctx) => {
196
- await ctx.sleepFor("wait-for", durationSeconds);
196
+ await ctx.sleepFor(
197
+ "wait-for",
198
+ Temporal.Duration.from({ seconds: durationSeconds }),
199
+ );
197
200
  return { resumed: true };
198
201
  });
199
202
 
@@ -205,7 +208,9 @@ describe("Step functionality", () => {
205
208
  state: "sleeping",
206
209
  });
207
210
  const wakeTime = new Date(base.getTime() + durationSeconds * 1000);
208
- expect(sleepingRun?.available_at?.getTime()).toBe(wakeTime.getTime());
211
+ expect(sleepingRun?.available_at?.epochMilliseconds).toBe(
212
+ wakeTime.getTime(),
213
+ );
209
214
 
210
215
  const resumeTime = new Date(wakeTime.getTime() + 5 * 1000);
211
216
  jest.setSystemTime(resumeTime);
@@ -225,11 +230,14 @@ describe("Step functionality", () => {
225
230
  await ctx.setFakeNow(base);
226
231
 
227
232
  const wakeTime = new Date(base.getTime() + 5 * 60 * 1000);
233
+ const wakeInstant = Temporal.Instant.fromEpochMilliseconds(
234
+ wakeTime.getTime(),
235
+ );
228
236
  let executions = 0;
229
237
 
230
238
  absurd.registerTask({ name: "sleep-until" }, async (_params, ctx) => {
231
239
  executions++;
232
- await ctx.sleepUntil("sleep-step", wakeTime);
240
+ await ctx.sleepUntil("sleep-step", wakeInstant);
233
241
  return { executions };
234
242
  });
235
243
 
@@ -240,7 +248,7 @@ describe("Step functionality", () => {
240
248
  expect(checkpointRow).toMatchObject({
241
249
  checkpoint_name: "sleep-step",
242
250
  owner_run_id: runID,
243
- state: wakeTime.toISOString(),
251
+ state: wakeInstant.toString(),
244
252
  });
245
253
 
246
254
  const sleepingRun = await ctx.getRun(runID);
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeAll, afterEach, jest } from "bun:test";
2
2
  import { EventEmitter, once } from "events";
3
3
  import type { TestContext } from "./setup";
4
4
  import { createTestAbsurd, randomName } from "./setup";
5
- import type { Absurd } from "absurd-sdk";
5
+ import type { Absurd } from "@absurd-sqlite/sdk";
6
6
  import { waitFor } from "./wait-for";
7
7
 
8
8
  describe("Worker", () => {