Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new Valibot piping? #432

Open
saturnonearth opened this issue May 21, 2024 · 22 comments
Open

Support new Valibot piping? #432

saturnonearth opened this issue May 21, 2024 · 22 comments
Labels
bug Something isn't working done Implemented enhancements

Comments

@saturnonearth
Copy link
Sponsor

Valibot just released the first RC (https://github.com/fabian-hiller/valibot/releases/tag/v0.31.0-rc.0) for their new piping functionality - is this compatible with Superforms?

@saturnonearth saturnonearth added the bug Something isn't working label May 21, 2024
@lumosminima
Copy link

lumosminima commented May 22, 2024

Don't think so (using Svelte 5 and validbot 0.31.0-rc)
image
Migration guide: https://valibot.dev/guides/migrate-from-v0.30.0/

@ciscoheat
Copy link
Owner

I installed it and ran the tests. It'll be quite a bit of work to make the tests pass, and probably a bit in https://github.com/gcornut/valibot-json-schema as well (the JSON Schema generator). Even more if we want to keep backwards compatibility.

@saturnonearth
Copy link
Sponsor Author

I installed it and ran the tests. It'll be quite a bit of work to make the tests pass, and probably a bit in https://github.com/gcornut/valibot-json-schema as well (the JSON Schema generator). Even more if we want to keep backwards compatibility.

I think since it's a library not even in 1.0, there is no need to keep backwards compatibility, imo

@slowsage
Copy link
Contributor

Draft PR #437 created. Version of valibot-json-schema and valibot not yet finalized in package.json:

  • valibot-json-schema: Waiting on PR #57 in valibot-json-schema to be merged to update version number.

  • valibot: Would appreciate thoughts on specifying valibot@"^0.31.0-rc5" - a release candidate.

@fabian-hiller
Copy link

I am happy to help with any questions.

@ciscoheat
Copy link
Owner

Updated to v0.31 and seems to be working fine with v2.15.0, can anyone confirm?

@ciscoheat ciscoheat added the done Implemented enhancements label Jun 10, 2024
@sillvva
Copy link
Sponsor Contributor

sillvva commented Jun 10, 2024

Everything (types, logic, etc.) seems to be working as expected in my app.

@saturnonearth
Copy link
Sponsor Author

I am getting an error, and some type errors, but this could be because I am using the Drizzle to Valibot adapter which has yet to be updated. Although one error I am getting is...

The "undefinedStrategy" option must be set to handle the `undefined` schema

which seems to be coming from: @gcornut+valibot-json-schema

@sillvva
Copy link
Sponsor Contributor

sillvva commented Jun 11, 2024

I am getting an error, and some type errors, but this could be because I am using the Drizzle to Valibot adapter which has yet to be updated. Although one error I am getting is...

The "undefinedStrategy" option must be set to handle the `undefined` schema

which seems to be coming from: @gcornut+valibot-json-schema

The creator of valibot, Fabian, is working with the Drizzle team to update it. I'd wait for that before migrating.

https://discord.com/channels/1043890932593987624/1083702388021538816/1247145749817593917

@fabian-hiller
Copy link

Here is the Drizzle PR: drizzle-team/drizzle-orm#2481

@saturnonearth
Copy link
Sponsor Author

I am getting an error, and some type errors, but this could be because I am using the Drizzle to Valibot adapter which has yet to be updated. Although one error I am getting is...
The "undefinedStrategy" option must be set to handle the `undefined` schema
which seems to be coming from: @gcornut+valibot-json-schema

The creator of valibot, Fabian, is working with the Drizzle team to update it. I'd wait for that before migrating.

https://discord.com/channels/1043890932593987624/1083702388021538816/1247145749817593917

Awesome!!

@ciscoheat
Copy link
Owner

@saturnonearth You may have to configure the adapter with undefinedStrategy set, as it's hard to know your intention for that validation.

@shiftlabs1
Copy link

shiftlabs1 commented Jun 12, 2024

Updated to v0.31 and seems to be working fine with v2.15.0, can anyone confirm?

unknow() does not work . I get the error

Error: Unsupported valibot schema: unknown

using latest schema definition for example

	netMonthlyPay: pipe(unknown(), transform(Number)),
	grossMonthlyPay: pipe(unknown(), transform(Number)),

used to before the upgrade .

I see the error may be coming from valibot-json-schema , i guess the flag ignoreUnknownValidation needs to be set somewhere ?

@shiftlabs1
Copy link

Updated to v0.31 and seems to be working fine with v2.15.0, can anyone confirm?

unknow() does not work . I get the error

Error: Unsupported valibot schema: unknown

using latest schema definition for example

	netMonthlyPay: pipe(unknown(), transform(Number)),
	grossMonthlyPay: pipe(unknown(), transform(Number)),

used to before the upgrade .

I see the error may be coming from valibot-json-schema , i guess the flag ignoreUnknownValidation needs to be set somewhere ?

Update: This has been replaced (in valibot ) with the union and transform type , so as not to convert unknown to a defined type

@shiftlabs1
Copy link

Updated to v0.31 and seems to be working fine with v2.15.0, can anyone confirm?

unknow() does not work . I get the error

Error: Unsupported valibot schema: unknown

using latest schema definition for example

	netMonthlyPay: pipe(unknown(), transform(Number)),
	grossMonthlyPay: pipe(unknown(), transform(Number)),

used to before the upgrade .
I see the error may be coming from valibot-json-schema , i guess the flag ignoreUnknownValidation needs to be set somewhere ?

Update: This has been replaced (in valibot ) with the union and transform type , so as not to convert unknown to a defined type

Now getting Multi-type unions must have a default value, or exactly one of the union types must have.
error

@saturnonearth
Copy link
Sponsor Author

@saturnonearth You may have to configure the adapter with undefinedStrategy set, as it's hard to know your intention for that validation.

I am not sure what you mean - as I haven't set anything up with undefinedStrategy validations - is likely coming from the drizzle adapter.

@sillvva
Copy link
Sponsor Contributor

sillvva commented Jun 25, 2024

@fabian-hiller It looks like something in Valibot between 0.32.0 (working) and 0.33.3 (not working) broke it again. It seems like the GenericSchema types between these two versions are not compatible.

It works again if I downgrade Valibot to 0.32.0

When I pass this schema to valibot()

export const newCharacterSchema = v.object({
	name: requiredString,
	campaign: v.optional(v.pipe(v.string(), maxStringSize), ""),
	race: v.optional(v.pipe(v.string(), maxStringSize), ""),
	class: v.optional(v.pipe(v.string(), maxStringSize), ""),
	characterSheetUrl: optionalURL,
	imageUrl: optionalURL
});

Like this:

const form = await superValidate(
	parent.character
		? {
				name: parent.character.name,
				campaign: parent.character.campaign || "",
				race: parent.character.race || "",
				class: parent.character.class || "",
				characterSheetUrl: parent.character.characterSheetUrl || "",
				imageUrl: parent.character.imageUrl.replace(BLANK_CHARACTER, "")
			}
		: undefined,
	valibot(newCharacterSchema),
	{
		errors: false
	}
);

I get this error:

Argument of type 

'ObjectSchema<{ readonly name: SchemaWithPipe<[StringSchema<undefined>, MinLengthAction<string, 1, string>]>; readonly campaign: OptionalSchema<SchemaWithPipe<[StringSchema<undefined>, MaxLengthAction<string, 255, string>]>, "">; readonly race: OptionalSchema<SchemaWithPipe<[StringSchema<undefined>, MaxLengthAction<string, 255, string>]>, "">; readonly class: OptionalSchema<SchemaWithPipe<[StringSchema<undefined>, MaxLengthAction<string, 255, string>]>, "">; readonly characterSheetUrl: OptionalSchema<SchemaWithFallback<SchemaWithPipe<[StringSchema<undefined>, UrlAction<string, undefined>, MaxLengthAction<string, 255, string>]>, "">, "">; readonly imageUrl: OptionalSchema<SchemaWithFallback<SchemaWithPipe<[StringSchema<undefined>, UrlAction<string, undefined>, MaxLengthAction<string, 255, string>]>, "">, "">; }, undefined>' 

is not assignable to parameter of type 'SupportedSchemas'.

Where SupportedSchemas is GenericSchema | GenericSchemaAsync

The above type is compatible with the GenericSchema type in version 0.33.3, but not in the version installed by sveltekit-superforms (0.31.x)

@fabian-hiller
Copy link

fabian-hiller commented Jun 25, 2024

This is strange because I haven't made any changes to BaseSchema, BaseSchemaAsync, GenericSchema and GenericSchemaAsync since v0.31.0.

Link: https://github.com/fabian-hiller/valibot/commits/main/library/src/types/schema.ts

@sillvva
Copy link
Sponsor Contributor

sillvva commented Jun 25, 2024

Here's a MRE of the issue
https://stackblitz.com/edit/stackblitz-starters-whs5op?file=index.ts

And here's the MRE where it's working with Valibot 0.32.0
https://stackblitz.com/edit/stackblitz-starters-6zducd?file=index.ts

The version of Superforms is unchanged between these MREs.

@fabian-hiller
Copy link

I think I know what the problem is. I have changed some types that are part of the BaseIssue type which probably causes this problem. I recommend upgrading Valibot in Superforms to the latest version and see if this fixes the problem. Thanks for reporting this!

@ciscoheat
Copy link
Owner

See if it works now with 2.15.2

@sillvva
Copy link
Sponsor Contributor

sillvva commented Jun 26, 2024

See if it works now with 2.15.2

Resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working done Implemented enhancements
Projects
None yet
Development

No branches or pull requests

7 participants