Skip to content

Commit 42db540

Browse files
committed
Finalizing effect adapter
1 parent 86f193f commit 42db540

File tree

10 files changed

+108
-13
lines changed

10 files changed

+108
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
- New validation library: [Effect](https://effect.website/)!
11+
812
## [2.19.1]
913

1014
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# Feature list
2222

23-
- Server- and client-side validation with your favorite validation libraries, and more to come: 💥 [Arktype](https://arktype.io/) 💥 [class-validator](https://github.com/typestack/class-validator) 💥 [Joi](https://joi.dev/) 💥 [Superstruct](https://docs.superstructjs.org/) 💥 [TypeBox](https://github.com/sinclairzx81/typebox) 💥 [Valibot](https://valibot.dev/) 💥 [VineJS](https://vinejs.dev/) 💥 [Yup](https://github.com/jquense/yup) 💥 [Zod](https://zod.dev/) 💥 or use [JSON Schema](https://json-schema.org/) directly.
23+
- Server- and client-side validation with your favorite validation libraries, and more to come: 💥 [Arktype](https://arktype.io/) 💥 [class-validator](https://github.com/typestack/class-validator) 💥 [Effect](https://effect.website/) 💥 [Joi](https://joi.dev/) 💥 [Superstruct](https://docs.superstructjs.org/) 💥 [TypeBox](https://github.com/sinclairzx81/typebox) 💥 [Valibot](https://valibot.dev/) 💥 [VineJS](https://vinejs.dev/) 💥 [Yup](https://github.com/jquense/yup) 💥 [Zod](https://zod.dev/) 💥 or use [JSON Schema](https://json-schema.org/) directly.
2424
- Seamless merging of `PageData` and `ActionData` - Forget about how to combine them, just focus on your form data, always strongly typed.
2525
- [Auto-centering and focusing](https://superforms.rocks/concepts/error-handling#usage-client) on invalid form fields.
2626
- [Tainted form detection](https://superforms.rocks/concepts/tainted), prevents the user from losing data if navigating away from an unsaved form. Or use [snapshots](https://superforms.rocks/concepts/snapshots) to save the form state.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"!dist/**/*.spec.*"
103103
],
104104
"peerDependencies": {
105-
"@effect/schema": "^0.73.4",
105+
"@effect/schema": "^0.75.3",
106106
"@exodus/schemasafe": "^1.3.0",
107107
"@sinclair/typebox": ">=0.32.30 <1",
108108
"@sveltejs/kit": "1.x || 2.x",
@@ -160,15 +160,15 @@
160160
}
161161
},
162162
"optionalDependencies": {
163-
"@effect/schema": "^0.73.4",
163+
"@effect/schema": "^0.75.3",
164164
"@exodus/schemasafe": "^1.3.0",
165165
"@gcornut/valibot-json-schema": "^0.31.0",
166166
"@sinclair/typebox": "^0.32.35",
167167
"@typeschema/class-validator": "^0.2.0",
168168
"@vinejs/vine": "^1.8.0",
169169
"arktype": "2.0.0-rc.8",
170170
"class-validator": "^0.14.1",
171-
"effect": "^3.8.2",
171+
"effect": "^3.9.1",
172172
"joi": "^17.13.3",
173173
"json-schema-to-ts": "^3.1.1",
174174
"superstruct": "^2.0.2",

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/adapters/effect.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ function _effect<T extends AnySchema>(
4747
schema: T,
4848
options?: AdapterOptions<Infer<T>> & { parseOptions?: ParseOptions }
4949
): ValidationAdapter<Infer<T>, InferIn<T>> {
50-
// @ts-expect-error idk why this happens, it seems to happen in other adapters too
5150
return createAdapter({
5251
superFormValidationLibrary: 'effect',
5352
validate: async (data) => validate(schema, data, options),

src/lib/adapters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type { ValidationAdapter, ClientValidationAdapter, Infer, InferIn } from
22

33
export { arktype, arktypeClient } from './arktype.js';
44
export { classvalidator, classvalidatorClient } from './classvalidator.js';
5+
export { effect, effectClient } from './effect.js';
56
export { joi, joiClient } from './joi.js';
67
export { superformClient } from './superform.js';
78
export { typebox, typeboxClient } from './typebox.js';

src/routes/(v2)/v2/Navigation.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
'issue-470',
6969
'issue-484',
7070
'component-regen',
71-
'issue-485'
71+
'issue-485',
72+
'arktype',
73+
'effect'
7274
].sort();
7375
</script>
7476

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { effect } from '$lib/adapters/effect.js';
2+
import { message, superValidate } from '$lib/server/index.js';
3+
import { schema } from './schema.js';
4+
import { fail } from '@sveltejs/kit';
5+
6+
export const load = async () => {
7+
const form = await superValidate(effect(schema));
8+
return { form };
9+
};
10+
11+
export const actions = {
12+
default: async ({ request }) => {
13+
const formData = await request.formData();
14+
console.log(formData);
15+
16+
const form = await superValidate(formData, effect(schema));
17+
console.log(form);
18+
19+
if (!form.valid) return fail(400, { form });
20+
21+
return message(form, 'Posted OK!');
22+
}
23+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script lang="ts">
2+
import { superForm } from '$lib/client/index.js';
3+
import SuperDebug from '$lib/client/SuperDebug.svelte';
4+
//import { zod } from '$lib/adapters/zod.js'
5+
//import { schema } from './schema.js';
6+
7+
export let data;
8+
9+
const { form, errors, tainted, message, enhance } = superForm(data.form, {
10+
taintedMessage: false
11+
//dataType: 'json',
12+
//validators: zod(schema)
13+
});
14+
</script>
15+
16+
<SuperDebug data={{ $form, $errors, $tainted }} />
17+
18+
{#if $message}<h4>{$message}</h4>{/if}
19+
20+
<form method="POST" use:enhance>
21+
<label>
22+
Name: <input
23+
name="name"
24+
bind:value={$form.name}
25+
aria-invalid={$errors.name ? 'true' : undefined}
26+
/>
27+
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
28+
</label>
29+
<label>
30+
Email: <input
31+
name="email"
32+
bind:value={$form.email}
33+
aria-invalid={$errors.email ? 'true' : undefined}
34+
/>
35+
{#if $errors.email}<span class="invalid">{$errors.email}</span>{/if}
36+
</label>
37+
<div>
38+
<button>Submit</button>
39+
</div>
40+
</form>
41+
42+
<style lang="scss">
43+
form {
44+
margin: 2rem 0;
45+
46+
input {
47+
background-color: #dedede;
48+
}
49+
50+
.invalid {
51+
color: crimson;
52+
}
53+
}
54+
</style>

src/routes/(v2)/v2/effect/schema.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Schema } from '@effect/schema';
2+
3+
const emailRegex = /^[^@]+@[^@]+\.[^@]+$/;
4+
5+
export const schema = Schema.Struct({
6+
name: Schema.String.annotations({ default: 'Hello world!' }),
7+
email: Schema.String.pipe(
8+
Schema.filter((s) => emailRegex.test(s) || 'must be a valid email', {
9+
jsonSchema: {}
10+
})
11+
)
12+
});

0 commit comments

Comments
 (0)