From aa75d61ba881dbeda1829fb1aae14d4e4fcdb1a0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 16 Nov 2025 18:33:03 +0000 Subject: [PATCH 1/2] Upgrade @tanstack/pacer to v0.16.2 and fix AsyncQueuer API usage The pacer package API changed significantly from v0.1.0 to v0.16.2: - AsyncQueuer constructor now takes the function as first parameter - Items are passed to addItem() instead of functions being passed to addItem() - Updated queueStrategy to use new API pattern This fixes the build errors in packages/db/src/strategies/queueStrategy.ts --- packages/db/package.json | 2 +- packages/db/src/strategies/queueStrategy.ts | 33 +++++++++++---------- pnpm-lock.yaml | 26 ++++++++++++---- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/db/package.json b/packages/db/package.json index 584d632175..5567dda56f 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 a0dafac9ff..228cc29048 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) }, cleanup: () => { queuer.stop() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7ccb11160..5b8da3aafb 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) From de67969d3d2a00881a7c51242e6bec9dc9e59264 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 16 Nov 2025 20:11:01 +0000 Subject: [PATCH 2/2] Improve type safety in queueStrategy by avoiding 'any' Replace Transaction with Transaction to match the pattern used in debounceStrategy and throttleStrategy. This maintains type safety while allowing the queuer to handle transactions with different generic types. - Changed AsyncQueuer<() => Transaction> to AsyncQueuer<() => Transaction> - Added type cast in addItem call: fn as () => Transaction - Consistent with existing strategy implementations --- packages/db/src/strategies/queueStrategy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/db/src/strategies/queueStrategy.ts b/packages/db/src/strategies/queueStrategy.ts index 228cc29048..10c8669dbb 100644 --- a/packages/db/src/strategies/queueStrategy.ts +++ b/packages/db/src/strategies/queueStrategy.ts @@ -44,7 +44,7 @@ import type { Transaction } from "../transactions" * ``` */ export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy { - const queuer = new AsyncQueuer<() => Transaction>( + const queuer = new AsyncQueuer<() => Transaction>( async (fn) => { const transaction = fn() // Wait for the transaction to be persisted before processing next item @@ -68,7 +68,7 @@ export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy { fn: () => Transaction ) => { // Add the transaction-creating function to the queue - queuer.addItem(fn) + queuer.addItem(fn as () => Transaction) }, cleanup: () => { queuer.stop()