@methodacting/actor-kit 0.47.0 → 0.47.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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@methodacting/actor-kit",
3
- "version": "0.47.0",
4
- "main": "./src/index.ts",
5
- "module": "./src/index.ts",
6
- "types": "./src/index.ts",
3
+ "version": "0.47.1",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
@@ -14,24 +14,24 @@
14
14
  "import": "./dist/browser.js"
15
15
  },
16
16
  "./server": {
17
- "types": "./src/server.ts",
18
- "import": "./src/server.ts"
17
+ "types": "./dist/src/server.d.ts",
18
+ "import": "./dist/src/server.js"
19
19
  },
20
20
  "./react": {
21
21
  "types": "./dist/react.d.ts",
22
22
  "import": "./dist/react.js"
23
23
  },
24
24
  "./storybook": {
25
- "types": "./src/storybook.ts",
26
- "import": "./src/storybook.ts"
25
+ "types": "./dist/src/storybook.d.ts",
26
+ "import": "./dist/src/storybook.js"
27
27
  },
28
28
  "./test": {
29
- "types": "./src/test.ts",
30
- "import": "./src/test.ts"
29
+ "types": "./dist/src/test.d.ts",
30
+ "import": "./dist/src/test.js"
31
31
  },
32
32
  "./worker": {
33
- "types": "./src/worker.ts",
34
- "import": "./src/worker.ts"
33
+ "types": "./dist/src/worker.d.ts",
34
+ "import": "./dist/src/worker.js"
35
35
  }
36
36
  },
37
37
  "files": [
@@ -40,6 +40,8 @@
40
40
  ],
41
41
  "scripts": {
42
42
  "build": "rollup -c --bundleConfigAsCjs",
43
+ "test": "vitest run",
44
+ "test:watch": "vitest",
43
45
  "prepublishOnly": "npm run build"
44
46
  },
45
47
  "keywords": [
@@ -52,9 +54,9 @@
52
54
  "license": "ISC",
53
55
  "peerDependencies": {
54
56
  "@cloudflare/workers-types": "^4.20240925.0",
55
- "react": "^17.0.0 || ^18.0.0",
57
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
56
58
  "xstate": "^5.18.0",
57
- "zod": "^3.23.0"
59
+ "zod": "^3.25.0 || ^4.0.0"
58
60
  },
59
61
  "dependencies": {
60
62
  "cloudflare": "^3.5.0",
@@ -77,8 +79,9 @@
77
79
  "rollup-plugin-preserve-directives": "^0.4.0",
78
80
  "rollup-plugin-typescript2": "^0.36.0",
79
81
  "typescript": "^5.6.2",
82
+ "vitest": "^3.2.4",
80
83
  "xstate": "^5.18.2",
81
- "zod": "^3.23.8"
84
+ "zod": "^4.3.5"
82
85
  },
83
86
  "type": "module",
84
87
  "imports": {
@@ -112,14 +112,17 @@ export const createActorKitRouter = <Env extends EnvWithDurableObjects>(
112
112
  }
113
113
 
114
114
  if (request.method === "GET") {
115
- const { waitForEvent, waitForState, timeout, errorOnWaitTimeout } =
116
- Object.fromEntries(new URL(request.url).searchParams);
117
-
115
+ const searchParams = new URL(request.url).searchParams;
116
+ const waitForEvent = searchParams.get("waitForEvent");
117
+ const waitForState = searchParams.get("waitForState");
118
+ const timeout = searchParams.get("timeout");
119
+ const errorOnWaitTimeout = searchParams.get("errorOnWaitTimeout");
120
+
118
121
  const result = await durableObjectStub.getSnapshot(caller, {
119
122
  waitForEvent: waitForEvent ? JSON.parse(waitForEvent) : undefined,
120
123
  waitForState: waitForState ? JSON.parse(waitForState) : undefined,
121
124
  timeout: timeout ? parseInt(timeout, 10) : undefined,
122
- errorOnWaitTimeout: errorOnWaitTimeout ? errorOnWaitTimeout === 'true' : undefined,
125
+ errorOnWaitTimeout: errorOnWaitTimeout ? errorOnWaitTimeout === "true" : undefined,
123
126
  });
124
127
  return new Response(JSON.stringify(result), {
125
128
  headers: { "Content-Type": "application/json" },
package/src/storage.ts CHANGED
@@ -109,7 +109,7 @@ export class ActorKitStorage {
109
109
  private initialized = false;
110
110
  private sql: DurableObjectStorage["sql"];
111
111
 
112
- constructor(private storage: DurableObjectStorage) {
112
+ constructor(private readonly storage: DurableObjectStorage) {
113
113
  this.sql = storage.sql;
114
114
  }
115
115
 
@@ -149,7 +149,7 @@ export class ActorKitStorage {
149
149
  await this.ensureInitialized();
150
150
  const result = await this.sql.exec(
151
151
  "SELECT id, type, scheduled_at, repeat_interval, payload, created_at FROM alarms WHERE scheduled_at <= ? ORDER BY scheduled_at ASC",
152
- [before]
152
+ before
153
153
  );
154
154
  return (await this.parseRows(result)) as AlarmRecord[];
155
155
  }
@@ -173,14 +173,12 @@ export class ActorKitStorage {
173
173
  await this.ensureInitialized();
174
174
  await this.sql.exec(
175
175
  "INSERT INTO alarms (id, type, scheduled_at, repeat_interval, payload, created_at) VALUES (?, ?, ?, ?, ?, ?)",
176
- [
177
- options.id,
178
- options.type,
179
- options.scheduledAt,
180
- options.repeatInterval ?? null,
181
- JSON.stringify(options.payload),
182
- Date.now(),
183
- ]
176
+ options.id,
177
+ options.type,
178
+ options.scheduledAt,
179
+ options.repeatInterval ?? null,
180
+ JSON.stringify(options.payload),
181
+ Date.now()
184
182
  );
185
183
  }
186
184
 
@@ -191,7 +189,10 @@ export class ActorKitStorage {
191
189
  await this.ensureInitialized();
192
190
  await this.sql.exec(
193
191
  "UPDATE alarms SET scheduled_at = ?, repeat_interval = ?, payload = ? WHERE id = ?",
194
- [options.scheduledAt, options.repeatInterval ?? null, JSON.stringify(options.payload), options.id]
192
+ options.scheduledAt,
193
+ options.repeatInterval ?? null,
194
+ JSON.stringify(options.payload),
195
+ options.id
195
196
  );
196
197
  }
197
198
 
@@ -200,7 +201,7 @@ export class ActorKitStorage {
200
201
  */
201
202
  async deleteAlarm(id: string): Promise<void> {
202
203
  await this.ensureInitialized();
203
- await this.sql.exec("DELETE FROM alarms WHERE id = ?", [id]);
204
+ await this.sql.exec("DELETE FROM alarms WHERE id = ?", id);
204
205
  }
205
206
 
206
207
  /**
@@ -208,7 +209,7 @@ export class ActorKitStorage {
208
209
  */
209
210
  async deleteAlarmsByType(type: string): Promise<void> {
210
211
  await this.ensureInitialized();
211
- await this.sql.exec("DELETE FROM alarms WHERE type = ?", [type]);
212
+ await this.sql.exec("DELETE FROM alarms WHERE type = ?", type);
212
213
  }
213
214
 
214
215
  // ==================== Actor Metadata ====================
@@ -238,7 +239,7 @@ export class ActorKitStorage {
238
239
 
239
240
  const result = await this.sql.exec(
240
241
  "SELECT actor_id, actor_type, initial_caller, input, created_at, updated_at FROM actor_meta WHERE actor_id = ?",
241
- [actorId]
242
+ actorId
242
243
  );
243
244
  const rows = (await this.parseRows(result)) as ActorMetaRecord[];
244
245
  if (rows.length === 0) return null;
@@ -266,14 +267,12 @@ export class ActorKitStorage {
266
267
  initial_caller = excluded.initial_caller,
267
268
  input = excluded.input,
268
269
  updated_at = excluded.updated_at`,
269
- [
270
- meta.actorId,
271
- meta.actorType,
272
- JSON.stringify(meta.initialCaller),
273
- JSON.stringify(meta.input),
274
- now,
275
- now,
276
- ]
270
+ meta.actorId,
271
+ meta.actorType,
272
+ JSON.stringify(meta.initialCaller),
273
+ JSON.stringify(meta.input),
274
+ now,
275
+ now
277
276
  );
278
277
  }
279
278
 
@@ -282,7 +281,7 @@ export class ActorKitStorage {
282
281
  */
283
282
  async deleteActorMeta(actorId: string): Promise<void> {
284
283
  await this.ensureInitialized();
285
- await this.sql.exec("DELETE FROM actor_meta WHERE actor_id = ?", [actorId]);
284
+ await this.sql.exec("DELETE FROM actor_meta WHERE actor_id = ?", actorId);
286
285
  }
287
286
 
288
287
  // ==================== Snapshots ====================
@@ -294,7 +293,7 @@ export class ActorKitStorage {
294
293
  await this.ensureInitialized();
295
294
  const result = await this.sql.exec(
296
295
  "SELECT actor_id, snapshot, checksum, updated_at FROM snapshots WHERE actor_id = ?",
297
- [actorId]
296
+ actorId
298
297
  );
299
298
  const rows = (await this.parseRows(result)) as SnapshotRecord[];
300
299
  if (rows.length === 0) return null;
@@ -319,7 +318,10 @@ export class ActorKitStorage {
319
318
  snapshot = excluded.snapshot,
320
319
  checksum = excluded.checksum,
321
320
  updated_at = excluded.updated_at`,
322
- [actorId, JSON.stringify(snapshot), checksum ?? null, Date.now()]
321
+ actorId,
322
+ JSON.stringify(snapshot),
323
+ checksum ?? null,
324
+ Date.now()
323
325
  );
324
326
  }
325
327
 
@@ -328,7 +330,7 @@ export class ActorKitStorage {
328
330
  */
329
331
  async deleteSnapshot(actorId: string): Promise<void> {
330
332
  await this.ensureInitialized();
331
- await this.sql.exec("DELETE FROM snapshots WHERE actor_id = ?", [actorId]);
333
+ await this.sql.exec("DELETE FROM snapshots WHERE actor_id = ?", actorId);
332
334
  }
333
335
 
334
336
  // ==================== Migration Helpers ====================
@@ -375,13 +377,13 @@ export class ActorKitStorage {
375
377
  if (result && typeof result[Symbol.asyncIterator] === "function") {
376
378
  const cursor = result as AsyncIterable<{ columns: string[]; results: (string | number | null)[][] }>;
377
379
  const rows: unknown[] = [];
378
- let columns: string[] = [];
380
+ let columns: string[] | null = null;
379
381
 
380
382
  for await (const batch of cursor) {
381
383
  if (!columns) columns = batch.columns;
382
384
  for (const row of batch.results) {
383
385
  const obj: Record<string, unknown> = {};
384
- columns.forEach((col, i) => {
386
+ (columns ?? []).forEach((col, i) => {
385
387
  obj[col] = row[i];
386
388
  });
387
389
  rows.push(obj);
@@ -390,9 +392,21 @@ export class ActorKitStorage {
390
392
  return rows;
391
393
  }
392
394
 
393
- // Handle array format
394
- if (Array.isArray(result) && result.length === 0) return [];
395
- const { columns, rows } = result[0];
395
+ // Handle row batches returned by sql.exec()
396
+ const batches = Array.isArray(result) ? result : result ? [result] : [];
397
+ if (batches.length === 0) return [];
398
+
399
+ const first = batches[0] as {
400
+ columns?: string[];
401
+ columnNames?: string[];
402
+ rows?: unknown[][];
403
+ results?: unknown[][];
404
+ };
405
+
406
+ const columns = first?.columns ?? first?.columnNames ?? [];
407
+ const rows = first?.rows ?? first?.results ?? [];
408
+ if (!columns.length || !rows.length) return [];
409
+
396
410
  return rows.map((row: unknown[]) => {
397
411
  const obj: Record<string, unknown> = {};
398
412
  columns.forEach((col: string, i: number) => {