Skip to content

Commit c0848b2

Browse files
committed
Fixed valibot type generation.
1 parent cca34e7 commit c0848b2

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

all-adapters.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { readdirSync, existsSync } from 'fs';
2+
3+
const path = './dist/adapters/';
4+
5+
// Sometimes, valibot types doesn't generate
6+
const js = readdirSync(path)
7+
.filter((f) => f.endsWith('.js'))
8+
.map((f) => path + f.slice(0, -2) + 'd.ts');
9+
10+
// The other file using the Prettify type
11+
js.push('./dist/client/proxies.d.ts');
12+
13+
for (const file of js) {
14+
if (!existsSync(file)) {
15+
console.error('Missing type definition:', file);
16+
process.exit(1);
17+
}
18+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"prepublishOnly": "npm run test && npm run lint && npm run check && npm run package",
4242
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.check.json",
4343
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
44+
"check:adapters": "node all-adapters.js",
4445
"test": "vitest run",
4546
"lint": "prettier --check . && eslint .",
4647
"format": "prettier --write ."

src/lib/adapters/valibot.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ import {
77
type ValidationResult,
88
type ClientValidationAdapter
99
} from './adapters.js';
10-
import { safeParseAsync, type BaseSchema, type BaseSchemaAsync } from 'valibot';
10+
import { safeParseAsync, type BaseSchema, type BaseSchemaAsync, type SchemaConfig } from 'valibot';
1111
import { memoize } from '$lib/memoize.js';
1212
import {
1313
type ToJSONSchemaOptions,
1414
toJSONSchema as valibotToJSON
1515
} from '@gcornut/valibot-json-schema';
1616
import type { JSONSchema } from '../jsonSchema/index.js';
17-
import type { Prettify } from '$lib/utils.js';
1817

1918
type SupportedSchemas = BaseSchema | BaseSchemaAsync;
2019

21-
type SchemaConfig = NonNullable<Parameters<typeof safeParseAsync>[2]>;
22-
2320
const defaultOptions = {
2421
strictObjectTypes: true,
2522
dateStrategy: 'integer' as const,
@@ -55,12 +52,10 @@ async function validate<T extends SupportedSchemas>(
5552

5653
function _valibot<T extends SupportedSchemas>(
5754
schema: T,
58-
options: Prettify<
59-
Omit<ToJSONSchemaOptions, 'schema'> &
60-
AdapterOptions<T> & {
61-
config?: SchemaConfig;
62-
}
63-
> = {}
55+
options: Omit<ToJSONSchemaOptions, 'schema'> &
56+
AdapterOptions<T> & {
57+
config?: SchemaConfig;
58+
} = {}
6459
): ValidationAdapter<Infer<T>, InferIn<T>> {
6560
return createAdapter({
6661
superFormValidationLibrary: 'valibot',

0 commit comments

Comments
 (0)