Skip to content

Commit

Permalink
Typebox bump to 0.34.9
Browse files Browse the repository at this point in the history
Fixes #511
  • Loading branch information
ciscoheat committed Dec 1, 2024
1 parent 75086f4 commit 8cd97c1
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- All properties for object unions weren't added to the adapter defaults.

### Changed

- Typebox updated to require `^0.34.9` (hoping for a stable release soon).

## [2.20.1] - 2024-11-15

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"peerDependencies": {
"@effect/schema": "^0.75.3",
"@exodus/schemasafe": "^1.3.0",
"@sinclair/typebox": ">=0.32.30 <1",
"@sinclair/typebox": "^0.34.9",
"@sveltejs/kit": "1.x || 2.x",
"@typeschema/class-validator": "^0.3.0",
"@vinejs/vine": "^1.8.0 || ^2.0.0",
Expand Down Expand Up @@ -163,7 +163,7 @@
"@effect/schema": "^0.75.3",
"@exodus/schemasafe": "^1.3.0",
"@gcornut/valibot-json-schema": "^0.31.0",
"@sinclair/typebox": "^0.32.35",
"@sinclair/typebox": "^0.34.9",
"@typeschema/class-validator": "^0.3.0",
"@vinejs/vine": "^2.0.0",
"arktype": "^2.0.0-rc.23",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/routes/(v2)/v2/Navigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
'issue-485',
'arktype',
'effect',
'issue-500'
'issue-500',
'typebox'
].sort();
</script>

Expand Down
23 changes: 23 additions & 0 deletions src/routes/(v2)/v2/typebox/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { typebox } from '$lib/adapters/typebox.js';
import { message, superValidate } from '$lib/server/index.js';
import { schema } from './schema.js';
import { fail } from '@sveltejs/kit';

export const load = async () => {
const form = await superValidate(typebox(schema));
return { form };
};

export const actions = {
default: async ({ request }) => {
const formData = await request.formData();
console.log(formData);

const form = await superValidate(formData, typebox(schema));
console.log(form);

if (!form.valid) return fail(400, { form });

return message(form, 'Posted OK!');
}
};
54 changes: 54 additions & 0 deletions src/routes/(v2)/v2/typebox/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script lang="ts">
import { superForm } from '$lib/client/index.js';
import SuperDebug from '$lib/client/SuperDebug.svelte';
import { typeboxClient } from '$lib/adapters/typebox.js';
import { schema } from './schema.js';
export let data;
const { form, errors, tainted, message, enhance } = superForm(data.form, {
taintedMessage: false,
validators: typeboxClient(schema)
//dataType: 'json',
});
</script>

<SuperDebug data={{ $form, $errors, $tainted }} />

{#if $message}<h4>{$message}</h4>{/if}

<form method="POST" use:enhance>
<label>
Name: <input
name="name"
bind:value={$form.name}
aria-invalid={$errors.name ? 'true' : undefined}
/>
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
</label>
<label>
Email: <input
name="email"
bind:value={$form.email}
aria-invalid={$errors.email ? 'true' : undefined}
/>
{#if $errors.email}<span class="invalid">{$errors.email}</span>{/if}
</label>
<div>
<button>Submit</button>
</div>
</form>

<style lang="scss">
form {
margin: 2rem 0;
input {
background-color: #dedede;
}
.invalid {
color: crimson;
}
}
</style>
6 changes: 6 additions & 0 deletions src/routes/(v2)/v2/typebox/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Type } from '@sinclair/typebox';

export const schema = Type.Object({
name: Type.String({ minLength: 2 }),
email: Type.String({ format: 'email' })
});

0 comments on commit 8cd97c1

Please sign in to comment.