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 [isPending, startTransition] = useTransition();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
function run(
|
function run(action: () => Promise<unknown>, opts: RunOptions = {}) {
|
||||||
action: () => Promise<ActionResult | undefined | void>,
|
|
||||||
opts: RunOptions = {},
|
|
||||||
) {
|
|
||||||
const {
|
const {
|
||||||
successMessage = "Saved successfully.",
|
successMessage = "Saved successfully.",
|
||||||
errorMessage = "An error occurred.",
|
errorMessage = "An error occurred.",
|
||||||
@@ -49,7 +46,7 @@ export function useServerAction(options: UseServerActionOptions = {}) {
|
|||||||
|
|
||||||
startTransition(async () => {
|
startTransition(async () => {
|
||||||
try {
|
try {
|
||||||
const result = await action();
|
const result = (await action()) as ActionResult | undefined;
|
||||||
|
|
||||||
if (!result || result.ok) {
|
if (!result || result.ok) {
|
||||||
toast.success(successMessage);
|
toast.success(successMessage);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export class DbService {
|
|||||||
private readonly client: PrismaClient;
|
private readonly client: PrismaClient;
|
||||||
private lastHealthCheck = 0;
|
private lastHealthCheck = 0;
|
||||||
private healthCache: HealthStatus | null = null;
|
private healthCache: HealthStatus | null = null;
|
||||||
private queryCount = 0;
|
|
||||||
private readonly healthTtlMs = 10_000;
|
private readonly healthTtlMs = 10_000;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -106,7 +105,6 @@ export class DbService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async execute<T>(fn: (client: PrismaClient) => Promise<T>): Promise<T> {
|
async execute<T>(fn: (client: PrismaClient) => Promise<T>): Promise<T> {
|
||||||
this.queryCount++;
|
|
||||||
try {
|
try {
|
||||||
return await fn(this.client);
|
return await fn(this.client);
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
|
|||||||
@@ -166,14 +166,14 @@ describe("derivePublicForegrounds", () => {
|
|||||||
for (const palette of [preset.light, preset.dark]) {
|
for (const palette of [preset.light, preset.dark]) {
|
||||||
const result = derivePublicForegrounds(palette);
|
const result = derivePublicForegrounds(palette);
|
||||||
for (const name of required) {
|
for (const name of required) {
|
||||||
const pair = result.pairs.find(
|
const pair = result.pairs.find(
|
||||||
(candidate) => candidate.name === name,
|
(candidate) => candidate.name === name,
|
||||||
);
|
);
|
||||||
expect(pair, `missing ${name}`).toBeDefined();
|
expect(pair, `missing ${name}`).toBeDefined();
|
||||||
expect(
|
expect(
|
||||||
contrastRatio(pair!.foreground, pair!.background),
|
contrastRatio(pair?.foreground, pair?.background),
|
||||||
name,
|
name,
|
||||||
).toBeGreaterThanOrEqual(4.5);
|
).toBeGreaterThanOrEqual(4.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user