Skip to content

Commit eb8c7d8

Browse files
committed
refactor(types): rename Exists to IfInstalled
1 parent 9c7d191 commit eb8c7d8

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

packages/next-safe-action/src/adapters/types.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import type { GenericSchema, GenericSchemaAsync, InferInput, InferOutput } from "valibot";
22
import type { z } from "zod";
33

4-
export type Exists<T> = any extends T ? never : T;
4+
export type IfInstalled<T> = any extends T ? never : T;
55

6-
export type Schema = Exists<z.ZodType> | Exists<GenericSchema> | Exists<GenericSchemaAsync>;
6+
export type Schema = IfInstalled<z.ZodType> | IfInstalled<GenericSchema> | IfInstalled<GenericSchemaAsync>;
77
export type Infer<S extends Schema> =
8-
S extends Exists<z.ZodType>
8+
S extends IfInstalled<z.ZodType>
99
? z.infer<S>
10-
: S extends Exists<GenericSchema>
10+
: S extends IfInstalled<GenericSchema>
1111
? InferOutput<S>
12-
: S extends Exists<GenericSchemaAsync>
12+
: S extends IfInstalled<GenericSchemaAsync>
1313
? InferOutput<S>
1414
: never;
1515
export type InferIn<S extends Schema> =
16-
S extends Exists<z.ZodType>
16+
S extends IfInstalled<z.ZodType>
1717
? z.input<S>
18-
: S extends Exists<GenericSchema>
18+
: S extends IfInstalled<GenericSchema>
1919
? InferInput<S>
20-
: S extends Exists<GenericSchemaAsync>
20+
: S extends IfInstalled<GenericSchemaAsync>
2121
? InferInput<S>
2222
: never;
2323
export type InferArray<BAS extends readonly Schema[]> = {
@@ -39,12 +39,12 @@ export interface ValidationAdapter {
3939
data: unknown
4040
): Promise<{ success: true; data: Infer<S> } | { success: false; issues: ValidationIssue[] }>;
4141
// zod
42-
validate<S extends z.ZodType>(
42+
validate<S extends IfInstalled<z.ZodType>>(
4343
schema: S,
4444
data: unknown
4545
): Promise<{ success: true; data: Infer<S> } | { success: false; issues: ValidationIssue[] }>;
4646
// valibot
47-
validate<S extends GenericSchema | GenericSchemaAsync>(
47+
validate<S extends IfInstalled<GenericSchema | GenericSchemaAsync>>(
4848
schema: S,
4949
data: unknown
5050
): Promise<{ success: true; data: Infer<S> } | { success: false; issues: ValidationIssue[] }>;

packages/next-safe-action/src/adapters/valibot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getDotPath, safeParseAsync, type GenericSchema, type GenericSchemaAsync } from "valibot";
2-
import type { Infer, ValidationAdapter } from "./types";
2+
import type { IfInstalled, Infer, ValidationAdapter } from "./types";
33

44
class ValibotAdapter implements ValidationAdapter {
5-
async validate<S extends GenericSchema | GenericSchemaAsync>(schema: S, data: unknown) {
5+
async validate<S extends IfInstalled<GenericSchema | GenericSchemaAsync>>(schema: S, data: unknown) {
66
const result = await safeParseAsync(schema, data);
77

88
if (result.success) {

packages/next-safe-action/src/adapters/zod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { z } from "zod";
2-
import type { Infer, ValidationAdapter } from "./types";
2+
import type { IfInstalled, Infer, ValidationAdapter } from "./types";
33

44
export type ZodSchema = z.ZodType;
55

66
class ZodAdapter implements ValidationAdapter {
7-
async validate<S extends z.ZodType>(schema: S, data: unknown) {
7+
async validate<S extends IfInstalled<z.ZodType>>(schema: S, data: unknown) {
88
const result = await schema.safeParseAsync(data);
99

1010
if (result.success) {

0 commit comments

Comments
 (0)