Skip to content

Commit 2015c64

Browse files
committed
Adapters updated to use the Infer improvement.
1 parent fc2d338 commit 2015c64

File tree

8 files changed

+44
-40
lines changed

8 files changed

+44
-40
lines changed

src/lib/adapters/classvalidator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ const fetchModule = /* @__PURE__ */ memoize(modules);
2121
async function validate<T extends Schema>(
2222
schema: T,
2323
data: unknown
24-
): Promise<ValidationResult<Infer<T>>> {
24+
): Promise<ValidationResult<Infer<T, 'classvalidator'>>> {
2525
const { validate } = await fetchModule();
2626
const result = await validate<T>(schema, data);
2727
if (result.success) {
2828
return {
29-
data: result.data as Infer<T>,
29+
data: result.data as Infer<T, 'classvalidator'>,
3030
success: true
3131
};
3232
}
@@ -41,8 +41,8 @@ async function validate<T extends Schema>(
4141

4242
function _classvalidator<T extends Schema>(
4343
schema: T,
44-
options: RequiredDefaultsOptions<Infer<T>>
45-
): ValidationAdapter<Infer<T>, InferIn<T>> {
44+
options: RequiredDefaultsOptions<Infer<T, 'classvalidator'>>
45+
): ValidationAdapter<Infer<T, 'classvalidator'>, InferIn<T, 'classvalidator'>> {
4646
return createAdapter({
4747
superFormValidationLibrary: 'classvalidator',
4848
validate: async (data: unknown) => validate(schema, data),
@@ -53,7 +53,7 @@ function _classvalidator<T extends Schema>(
5353

5454
function _classvalidatorClient<T extends Schema>(
5555
schema: T
56-
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
56+
): ClientValidationAdapter<Infer<T, 'classvalidator'>, InferIn<T, 'classvalidator'>> {
5757
return {
5858
superFormValidationLibrary: 'classvalidator',
5959
validate: async (data) => validate(schema, data)

src/lib/adapters/effect.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ type AnySchema = Schema.Schema<any, any>;
2424
async function validate<T extends AnySchema>(
2525
schema: T,
2626
data: unknown,
27-
options?: AdapterOptions<Infer<T>> & { parseOptions?: ParseOptions }
28-
): Promise<ValidationResult<Infer<T>>> {
27+
options?: AdapterOptions<Infer<T, 'effect'>> & { parseOptions?: ParseOptions }
28+
): Promise<ValidationResult<Infer<T, 'effect'>>> {
2929
const result = Schema.decodeUnknownEither(schema, { errors: 'all' })(data, options?.parseOptions);
3030
if (Either.isRight(result)) {
3131
return {
32-
data: result.right as Infer<T>,
32+
data: result.right as Infer<T, 'effect'>,
3333
success: true
3434
};
3535
}
@@ -40,13 +40,13 @@ async function validate<T extends AnySchema>(
4040
path: [...path] // path is readonly array so we have to copy it
4141
})),
4242
success: false
43-
} satisfies ValidationResult<Infer<T>>;
43+
} satisfies ValidationResult<Infer<T, 'effect'>>;
4444
}
4545

4646
function _effect<T extends AnySchema>(
4747
schema: T,
48-
options?: AdapterOptions<Infer<T>> & { parseOptions?: ParseOptions }
49-
): ValidationAdapter<Infer<T>, InferIn<T>> {
48+
options?: AdapterOptions<Infer<T, 'effect'>> & { parseOptions?: ParseOptions }
49+
): ValidationAdapter<Infer<T, 'effect'>, InferIn<T, 'effect'>> {
5050
return createAdapter({
5151
superFormValidationLibrary: 'effect',
5252
validate: async (data) => validate(schema, data, options),
@@ -57,8 +57,8 @@ function _effect<T extends AnySchema>(
5757

5858
function _effectClient<T extends AnySchema>(
5959
schema: T,
60-
options?: AdapterOptions<Infer<T>> & { parseOptions?: ParseOptions }
61-
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
60+
options?: AdapterOptions<Infer<T, 'effect'>> & { parseOptions?: ParseOptions }
61+
): ClientValidationAdapter<Infer<T, 'effect'>, InferIn<T, 'effect'>> {
6262
return {
6363
superFormValidationLibrary: 'effect',
6464
validate: async (data) => validate(schema, data, options)

src/lib/adapters/joi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function validate<T extends ObjectSchema>(
3333
/* @__NO_SIDE_EFFECTS__ */
3434
function _joi<T extends ObjectSchema>(
3535
schema: T,
36-
options?: AdapterOptions<Infer<T>>
36+
options?: AdapterOptions<Infer<T, 'joi'>>
3737
): ValidationAdapter<Record<string, unknown>> {
3838
return createAdapter({
3939
superFormValidationLibrary: 'joi',

src/lib/adapters/superstruct.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { memoize } from '$lib/memoize.js';
1313
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1414
type StructObject<T extends Record<string, unknown>> = Struct<T, any>;
1515

16-
async function validate<T extends StructObject<Infer<T>>>(
16+
async function validate<T extends StructObject<Infer<T, 'superstruct'>>>(
1717
schema: T,
1818
data: unknown
19-
): Promise<ValidationResult<Infer<T>>> {
19+
): Promise<ValidationResult<Infer<T, 'superstruct'>>> {
2020
const result = schema.validate(data, { coerce: true });
2121
if (!result[0]) {
2222
return {
23-
data: result[1] as Infer<T>,
23+
data: result[1] as Infer<T, 'superstruct'>,
2424
success: true
2525
};
2626
}
@@ -34,10 +34,10 @@ async function validate<T extends StructObject<Infer<T>>>(
3434
};
3535
}
3636

37-
function _superstruct<T extends StructObject<Infer<T>>>(
37+
function _superstruct<T extends StructObject<Infer<T, 'superstruct'>>>(
3838
schema: T,
39-
options: RequiredDefaultsOptions<Infer<T>>
40-
): ValidationAdapter<Infer<T>> {
39+
options: RequiredDefaultsOptions<Infer<T, 'superstruct'>>
40+
): ValidationAdapter<Infer<T, 'superstruct'>> {
4141
return createAdapter({
4242
superFormValidationLibrary: 'superstruct',
4343
defaults: options.defaults,
@@ -46,9 +46,9 @@ function _superstruct<T extends StructObject<Infer<T>>>(
4646
});
4747
}
4848

49-
function _superstructClient<T extends StructObject<Infer<T>>>(
49+
function _superstructClient<T extends StructObject<Infer<T, 'superstruct'>>>(
5050
schema: T
51-
): ClientValidationAdapter<Infer<T>> {
51+
): ClientValidationAdapter<Infer<T, 'superstruct'>> {
5252
return {
5353
superFormValidationLibrary: 'superstruct',
5454
validate: async (data) => validate(schema, data)

src/lib/adapters/typebox.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const fetchModule = /* @__PURE__ */ memoize(modules);
2525
async function validate<T extends TSchema>(
2626
schema: T,
2727
data: unknown
28-
): Promise<ValidationResult<Infer<T>>> {
28+
): Promise<ValidationResult<Infer<T, 'typebox'>>> {
2929
const { TypeCompiler, FormatRegistry } = await fetchModule();
3030

3131
if (!compiled.has(schema)) {
@@ -40,7 +40,7 @@ async function validate<T extends TSchema>(
4040
const errors = [...(validator?.Errors(data) ?? [])];
4141

4242
if (!errors.length) {
43-
return { success: true, data: data as Infer<T> };
43+
return { success: true, data: data as Infer<T, 'typebox'> };
4444
}
4545

4646
return {
@@ -52,7 +52,9 @@ async function validate<T extends TSchema>(
5252
};
5353
}
5454

55-
function _typebox<T extends TSchema>(schema: T): ValidationAdapter<Infer<T>, InferIn<T>> {
55+
function _typebox<T extends TSchema>(
56+
schema: T
57+
): ValidationAdapter<Infer<T, 'typebox'>, InferIn<T, 'typebox'>> {
5658
return createAdapter({
5759
superFormValidationLibrary: 'typebox',
5860
validate: async (data: unknown) => validate(schema, data),
@@ -62,7 +64,7 @@ function _typebox<T extends TSchema>(schema: T): ValidationAdapter<Infer<T>, Inf
6264

6365
function _typeboxClient<T extends TSchema>(
6466
schema: T
65-
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
67+
): ClientValidationAdapter<Infer<T, 'typebox'>, InferIn<T, 'typebox'>> {
6668
return {
6769
superFormValidationLibrary: 'typebox',
6870
validate: async (data) => validate(schema, data)

src/lib/adapters/valibot.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ async function _validate<T extends SupportedSchemas>(
4646
schema: T,
4747
data: unknown,
4848
config?: Config<GenericIssue<unknown>>
49-
): Promise<ValidationResult<Infer<T>>> {
49+
): Promise<ValidationResult<Infer<T, 'valibot'>>> {
5050
const result = await safeParseAsync(schema, data, config);
5151
if (result.success) {
5252
return {
53-
data: result.output as Infer<T>,
53+
data: result.output as Infer<T, 'valibot'>,
5454
success: true
5555
};
5656
}
@@ -66,10 +66,10 @@ async function _validate<T extends SupportedSchemas>(
6666
function _valibot<T extends SupportedSchemas>(
6767
schema: T,
6868
options: Omit<ToJSONSchemaOptions, 'schema'> &
69-
AdapterOptions<Infer<T>> & {
69+
AdapterOptions<Infer<T, 'valibot'>> & {
7070
config?: Config<GenericIssue<unknown>>;
7171
} = {}
72-
): ValidationAdapter<Infer<T>, InferIn<T>> {
72+
): ValidationAdapter<Infer<T, 'valibot'>, InferIn<T, 'valibot'>> {
7373
return createAdapter({
7474
superFormValidationLibrary: 'valibot',
7575
validate: async (data) => _validate<T>(schema, data, options?.config),
@@ -81,7 +81,7 @@ function _valibot<T extends SupportedSchemas>(
8181

8282
function _valibotClient<T extends SupportedSchemas>(
8383
schema: T
84-
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
84+
): ClientValidationAdapter<Infer<T, 'valibot'>, InferIn<T, 'valibot'>> {
8585
return {
8686
superFormValidationLibrary: 'valibot',
8787
validate: async (data) => _validate<T>(schema, data)

src/lib/adapters/vine.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ const fetchModule = /* @__PURE__ */ memoize(modules);
2121
async function validate<T extends SchemaTypes>(
2222
schema: T,
2323
data: unknown
24-
): Promise<ValidationResult<Infer<T>>> {
24+
): Promise<ValidationResult<Infer<T, 'vine'>>> {
2525
const { Vine, errors } = await fetchModule();
2626
try {
2727
const output = await new Vine().validate({ schema, data });
2828
return {
2929
success: true,
30-
data: output as Infer<T>
30+
data: output as Infer<T, 'vine'>
3131
};
3232
} catch (e) {
3333
if (e instanceof errors.E_VALIDATION_ERROR) {
@@ -46,8 +46,8 @@ async function validate<T extends SchemaTypes>(
4646

4747
function _vine<T extends SchemaTypes>(
4848
schema: T,
49-
options: RequiredDefaultsOptions<Infer<T>>
50-
): ValidationAdapter<Infer<T>, InferIn<T>> {
49+
options: RequiredDefaultsOptions<Infer<T, 'vine'>>
50+
): ValidationAdapter<Infer<T, 'vine'>, InferIn<T, 'vine'>> {
5151
return createAdapter({
5252
superFormValidationLibrary: 'vine',
5353
validate: async (data: unknown) => validate(schema, data),
@@ -58,7 +58,7 @@ function _vine<T extends SchemaTypes>(
5858

5959
function _vineClient<T extends SchemaTypes>(
6060
schema: T
61-
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
61+
): ClientValidationAdapter<Infer<T, 'vine'>, InferIn<T, 'vine'>> {
6262
return {
6363
superFormValidationLibrary: 'vine',
6464
validate: async (data) => validate(schema, data)

src/lib/adapters/yup.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function yupToJSONSchema(schema: AnySchema) {
3333
async function validate<T extends Schema>(
3434
schema: T,
3535
data: unknown
36-
): Promise<ValidationResult<Infer<T>>> {
36+
): Promise<ValidationResult<Infer<T, 'yup'>>> {
3737
const { ValidationError } = await fetchModule();
3838
try {
3939
return {
@@ -56,8 +56,8 @@ async function validate<T extends Schema>(
5656
/* @__NO_SIDE_EFFECTS__ */
5757
function _yup<T extends Schema>(
5858
schema: T,
59-
options?: AdapterOptions<Infer<T>>
60-
): ValidationAdapter<Infer<T>, InferIn<T>> {
59+
options?: AdapterOptions<Infer<T, 'yup'>>
60+
): ValidationAdapter<Infer<T, 'yup'>, InferIn<T, 'yup'>> {
6161
return createAdapter({
6262
superFormValidationLibrary: 'yup',
6363
validate: async (data: unknown) => validate(schema, data),
@@ -66,7 +66,9 @@ function _yup<T extends Schema>(
6666
});
6767
}
6868

69-
function _yupClient<T extends Schema>(schema: T): ClientValidationAdapter<Infer<T>, InferIn<T>> {
69+
function _yupClient<T extends Schema>(
70+
schema: T
71+
): ClientValidationAdapter<Infer<T, 'yup'>, InferIn<T, 'yup'>> {
7072
return {
7173
superFormValidationLibrary: 'yup',
7274
validate: async (data) => validate(schema, data)

0 commit comments

Comments
 (0)