fix: make useServerAction accept void-returning actions and remove dead queryCount
Local Build and Deploy / deploy (push) Successful in 53s
Local Build and Deploy / deploy (push) Successful in 53s
- Type run()'s action param as Promise<unknown> and cast result (Biome strips void from unions) - Remove unused queryCount field increment in DbService (dead code) - Reformat theme-contrast test pair assertions
This commit is contained in:
1 parent
1908136071
commit
2455a4850e
4 files changed
+12
-835
No files matched your search
Generated
+2
-820
File diff suppressed because it is too large.
Load diff
@@ -36,10 +36,7 @@ export function useServerAction(options: UseServerActionOptions = {}) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const router = useRouter();
|
||||
|
||||
function run(
|
||||
action: () => Promise<ActionResult | undefined | void>,
|
||||
opts: RunOptions = {},
|
||||
) {
|
||||
function run(action: () => Promise<unknown>, opts: RunOptions = {}) {
|
||||
const {
|
||||
successMessage = "Saved successfully.",
|
||||
errorMessage = "An error occurred.",
|
||||
@@ -49,7 +46,7 @@ export function useServerAction(options: UseServerActionOptions = {}) {
|
||||
|
||||
startTransition(async () => {
|
||||
try {
|
||||
const result = await action();
|
||||
const result = (await action()) as ActionResult | undefined;
|
||||
|
||||
if (!result || result.ok) {
|
||||
toast.success(successMessage);
|
||||
|
||||
@@ -19,7 +19,6 @@ export class DbService {
|
||||
private readonly client: PrismaClient;
|
||||
private lastHealthCheck = 0;
|
||||
private healthCache: HealthStatus | null = null;
|
||||
private queryCount = 0;
|
||||
private readonly healthTtlMs = 10_000;
|
||||
|
||||
constructor() {
|
||||
@@ -106,7 +105,6 @@ export class DbService {
|
||||
}
|
||||
|
||||
async execute<T>(fn: (client: PrismaClient) => Promise<T>): Promise<T> {
|
||||
this.queryCount++;
|
||||
try {
|
||||
return await fn(this.client);
|
||||
} catch (cause) {
|
||||
|
||||
@@ -166,14 +166,14 @@ describe("derivePublicForegrounds", () => {
|
||||
for (const palette of [preset.light, preset.dark]) {
|
||||
const result = derivePublicForegrounds(palette);
|
||||
for (const name of required) {
|
||||
const pair = result.pairs.find(
|
||||
(candidate) => candidate.name === name,
|
||||
);
|
||||
expect(pair, `missing ${name}`).toBeDefined();
|
||||
expect(
|
||||
contrastRatio(pair!.foreground, pair!.background),
|
||||
name,
|
||||
).toBeGreaterThanOrEqual(4.5);
|
||||
const pair = result.pairs.find(
|
||||
(candidate) => candidate.name === name,
|
||||
);
|
||||
expect(pair, `missing ${name}`).toBeDefined();
|
||||
expect(
|
||||
contrastRatio(pair?.foreground, pair?.background),
|
||||
name,
|
||||
).toBeGreaterThanOrEqual(4.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user