diff --git a/packages/db/package.json b/packages/db/package.json index 584d63217..5567dda56 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -5,7 +5,7 @@ "dependencies": { "@standard-schema/spec": "^1.0.0", "@tanstack/db-ivm": "workspace:*", - "@tanstack/pacer": "^0.1.0" + "@tanstack/pacer": "^0.16.2" }, "devDependencies": { "@vitest/coverage-istanbul": "^3.2.4", diff --git a/packages/db/src/strategies/queueStrategy.ts b/packages/db/src/strategies/queueStrategy.ts index a0dafac9f..10c8669db 100644 --- a/packages/db/src/strategies/queueStrategy.ts +++ b/packages/db/src/strategies/queueStrategy.ts @@ -44,14 +44,22 @@ import type { Transaction } from "../transactions" * ``` */ export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy { - const queuer = new AsyncQueuer({ - concurrency: 1, // Process one at a time to ensure serialization - wait: options?.wait, - maxSize: options?.maxSize, - addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back - getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front - started: true, // Start processing immediately - }) + const queuer = new AsyncQueuer<() => Transaction>( + async (fn) => { + const transaction = fn() + // Wait for the transaction to be persisted before processing next item + // Note: fn() already calls commit(), we just wait for it to complete + await transaction.isPersisted.promise + }, + { + concurrency: 1, // Process one at a time to ensure serialization + wait: options?.wait, + maxSize: options?.maxSize, + addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back + getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front + started: true, // Start processing immediately + } + ) return { _type: `queue`, @@ -59,13 +67,8 @@ export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy { execute: >( fn: () => Transaction ) => { - // Wrap the callback in an async function that waits for persistence - queuer.addItem(async () => { - const transaction = fn() - // Wait for the transaction to be persisted before processing next item - // Note: fn() already calls commit(), we just wait for it to complete - await transaction.isPersisted.promise - }) + // Add the transaction-creating function to the queue + queuer.addItem(fn as () => Transaction) }, cleanup: () => { queuer.stop() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7ccb1116..5b8da3aaf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -603,7 +603,7 @@ importers: version: 0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7) drizzle-zod: specifier: ^0.8.3 - version: 0.8.3(drizzle-orm@0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7))(zod@4.1.11) + version: 0.8.3(drizzle-orm@0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7))(zod@3.25.76) express: specifier: ^4.21.2 version: 4.21.2 @@ -718,8 +718,8 @@ importers: specifier: workspace:* version: link:../db-ivm '@tanstack/pacer': - specifier: ^0.1.0 - version: 0.1.0 + specifier: ^0.16.2 + version: 0.16.2 typescript: specifier: '>=4.7' version: 5.9.3 @@ -3647,6 +3647,10 @@ packages: resolution: {integrity: sha512-7Wwfw6wBv2Kc+OBNIJQzBSJ6q7GABtwVT+VOQ/7/Gl7z8z1rtEYUZrxUrNvbbrHY+J5/WNZNZjJjTWDf8nTUBw==} engines: {node: '>=18'} + '@tanstack/devtools-event-client@0.3.5': + resolution: {integrity: sha512-RL1f5ZlfZMpghrCIdzl6mLOFLTuhqmPNblZgBaeKfdtk5rfbjykurv+VfYydOFXj0vxVIoA2d/zT7xfD7Ph8fw==} + engines: {node: '>=18'} + '@tanstack/directive-functions-plugin@1.133.19': resolution: {integrity: sha512-U6nBlxxc624Q7Yta3UUe805WJfi0R029N/vUOVNxggZ432nt+0Hx7gLQO2P9zIUt+N6VYPuyKLKq047bxCJWOw==} engines: {node: '>=12'} @@ -3661,8 +3665,8 @@ packages: resolution: {integrity: sha512-B7+x7eP2FFvi3fgd3rNH9o/Eixt+pp0zCIdGhnQbAJjFrlwIKGjGnwyJjhWJ5fMQlGks/E2LdDTqEV4W9Plx7g==} engines: {node: '>=12'} - '@tanstack/pacer@0.1.0': - resolution: {integrity: sha512-QVzkGO5clvGj/qdX8H2wUj0QCXCLZ/pwPMnfSqhoYfpzDRkRHDj+3D+VzdcehBIVnE+GCd1D/P1tGMzfjmfrzQ==} + '@tanstack/pacer@0.16.2': + resolution: {integrity: sha512-u7K87OPuoABu4QFOnxwsmR+/aU97JBSA5BpujD73r+A4Lhk0w2WUuY0NggECaOINrA/0nqLUHunO5gNV7EI5YA==} engines: {node: '>=18'} '@tanstack/publish-config@0.2.1': @@ -11676,6 +11680,8 @@ snapshots: - typescript - vite + '@tanstack/devtools-event-client@0.3.5': {} + '@tanstack/directive-functions-plugin@1.133.19(vite@6.4.1(@types/node@24.7.0)(jiti@2.6.1)(lightningcss@1.30.2)(sass@1.90.0)(terser@5.44.0)(tsx@4.20.6)(yaml@2.8.1))': dependencies: '@babel/code-frame': 7.27.1 @@ -11722,7 +11728,10 @@ snapshots: '@tanstack/history@1.133.28': {} - '@tanstack/pacer@0.1.0': {} + '@tanstack/pacer@0.16.2': + dependencies: + '@tanstack/devtools-event-client': 0.3.5 + '@tanstack/store': 0.8.0 '@tanstack/publish-config@0.2.1': dependencies: @@ -13799,6 +13808,11 @@ snapshots: pg: 8.16.3 postgres: 3.4.7 + drizzle-zod@0.8.3(drizzle-orm@0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7))(zod@3.25.76): + dependencies: + drizzle-orm: 0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7) + zod: 3.25.76 + drizzle-zod@0.8.3(drizzle-orm@0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7))(zod@4.1.11): dependencies: drizzle-orm: 0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.5)(gel@2.1.1)(kysely@0.28.5)(pg@8.16.3)(postgres@3.4.7)