Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .changeset/shiny-crews-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
'@builder.io/qwik-city': minor
---

✨ **(EXPERIMENTAL)** standardSchema$ validator (by [@nothendev](https://github.com/nothendev) in [#8840](https://github.com/QwikDev/qwik/pull/8840))

To use it, you need to pass `experimental: ['standardSchema']` as an option to the `qwikVite` plugin as such:

```ts
// vite.config.ts

export default defineConfig(({ command, mode }): UserConfig => {
return {
plugins: [
// ... other plugins like qwikCity() etc
qwikVite({
experimental: ['standardSchema']
// ... other options
}),

],
// ... rest of the config
};
}
```

Then pass any [Standard Schema compatible](https://standardschema.dev) validator into `standardSchema$`:

```ts
import { type } from 'arktype';
import { routeAction$, standardSchema$ } from '@builder.io/qwik-city';

export const useLogin = routeAction$(
async ({ username, password }, ev) => {
// ... use the type-inferred { username: string, password: string }
},
standardSchema$(
type({
username: 'string',
password: 'string > 8',
})
)
);
```
2 changes: 1 addition & 1 deletion e2e/docs-e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "docs-e2e",
"description": "",
"private": true,
"author": "",
"devDependencies": {
"@playwright/test": "1.54.1",
Expand All @@ -10,6 +9,7 @@
"keywords": [],
"license": "ISC",
"main": "index.js",
"private": true,
"scripts": {
"test": "pnpm exec playwright test --config=playwright.config.ts --project=chromium",
"test-ui": "pnpm exec playwright test --config=playwright.config.ts --project=chromium --ui"
Expand Down
8 changes: 4 additions & 4 deletions e2e/qwik-react-e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "qwik-react-test-app",
"description": "Qwik react test app",
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"private": true,
"devDependencies": {
"@builder.io/qwik-react": "workspace:^",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"private": true,
"scripts": {
"build": "qwik build",
"build.client": "vite build",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
"deps": "corepack pnpm upgrade -i -r --latest && syncpack fix-mismatches && corepack pnpm dedupe",
"docs.dev": "pnpm -C packages/docs build.repl-sw && pnpm -C packages/docs dev",
"docs.preview": "pnpm -C packages/docs preview",
"docs.sync": "node --require ./scripts/runBefore.ts scripts/docs_sync/index.ts && pnpm fmt",
"docs.showcase": "pnpm -C packages/docs run build.showcase",
"docs.sync": "node --require ./scripts/runBefore.ts scripts/docs_sync/index.ts && pnpm fmt",
"eslint.update": "node --require ./scripts/runBefore.ts scripts/eslint-docs.ts",
"fmt": "pnpm prettier.fix && pnpm syncpack format",
"fmt.staged": "pretty-quick --staged",
Expand Down Expand Up @@ -244,9 +244,9 @@
"test.e2e.firefox": "playwright test starters --browser=firefox --config starters/playwright.config.ts",
"test.e2e.integrations.chromium": "playwright test e2e/adapters-e2e/tests --project=chromium --config e2e/adapters-e2e/playwright.config.ts",
"test.e2e.integrations.webkit": "playwright test e2e/adapters-e2e/tests --project=webkit --config e2e/adapters-e2e/playwright.config.ts",
"test.e2e.webkit": "playwright test starters --browser=webkit --config starters/playwright.config.ts",
"test.e2e.qwik-react.chromium": "playwright test e2e/qwik-react-e2e/tests --project=chromium --config e2e/qwik-react-e2e/playwright.config.ts",
"test.e2e.qwik-react.webkit": "playwright test e2e/qwik-react-e2e/tests --project=webkit --config e2e/qwik-react-e2e/playwright.config.ts",
"test.e2e.webkit": "playwright test starters --browser=webkit --config starters/playwright.config.ts",
"test.rust": "make test",
"test.rust.update": "make test-update",
"test.unit": "vitest packages",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"leaflet": "1.9.4",
"magic-string": "0.30.17",
"openai": "3.3.0",
"playwright": "1.58.2",
"prettier": "3.6.2",
"prism-themes": "1.9.0",
"prismjs": "1.30.0",
"playwright": "1.58.2",
"qwik-image": "0.0.16",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand Down
62 changes: 59 additions & 3 deletions packages/docs/src/routes/api/qwik-city/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type GetValidatorInputType<VALIDATOR extends TypedDataValidator> = VALIDATOR extends ValibotDataValidator<infer TYPE> ? v.InferInput<TYPE> : VALIDATOR extends ZodDataValidator<infer TYPE> ? z.input<TYPE> : never;\n```\n**References:** [TypedDataValidator](#typeddatavalidator)",
"content": "```typescript\nexport type GetValidatorInputType<VALIDATOR extends TypedDataValidator> = VALIDATOR extends StandardSchemaDataValidator<infer TYPE> ? StandardSchemaV1.InferInput<TYPE> : VALIDATOR extends ValibotDataValidator<infer TYPE> ? v.InferInput<TYPE> : VALIDATOR extends ZodDataValidator<infer TYPE> ? z.input<TYPE> : never;\n```\n**References:** [TypedDataValidator](#typeddatavalidator)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts",
"mdFile": "qwik-city.getvalidatorinputtype.md"
},
Expand All @@ -320,7 +320,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type GetValidatorOutputType<VALIDATOR extends TypedDataValidator> = VALIDATOR extends ValibotDataValidator<infer TYPE> ? v.InferOutput<TYPE> : VALIDATOR extends ZodDataValidator<infer TYPE> ? z.output<TYPE> : never;\n```\n**References:** [TypedDataValidator](#typeddatavalidator)",
"content": "```typescript\nexport type GetValidatorOutputType<VALIDATOR extends TypedDataValidator> = VALIDATOR extends StandardSchemaDataValidator<infer TYPE> ? StandardSchemaV1.InferOutput<TYPE> : VALIDATOR extends ValibotDataValidator<infer TYPE> ? v.InferOutput<TYPE> : VALIDATOR extends ZodDataValidator<infer TYPE> ? z.output<TYPE> : never;\n```\n**References:** [TypedDataValidator](#typeddatavalidator)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts",
"mdFile": "qwik-city.getvalidatoroutputtype.md"
},
Expand Down Expand Up @@ -828,6 +828,48 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/sw-component.tsx",
"mdFile": "qwik-city.serviceworkerregister.md"
},
{
"name": "standardSchema$",
"id": "standardschema_",
"hierarchy": [
{
"name": "standardSchema$",
"id": "standardschema_"
}
],
"kind": "Variable",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\n\n\n```typescript\nstandardSchema$: StandardSchemaConstructor\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/server-functions.ts",
"mdFile": "qwik-city.standardschema_.md"
},
{
"name": "StandardSchemaConstructor",
"id": "standardschemaconstructor",
"hierarchy": [
{
"name": "StandardSchemaConstructor",
"id": "standardschemaconstructor"
}
],
"kind": "TypeAlias",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\n\n\n```typescript\nexport type StandardSchemaConstructor = {\n <T extends StandardSchemaV1>(schema: T): StandardSchemaDataValidator<T>;\n <T extends StandardSchemaV1>(schema: (ev: RequestEvent) => T): StandardSchemaDataValidator<T>;\n};\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts",
"mdFile": "qwik-city.standardschemaconstructor.md"
},
{
"name": "standardSchemaQrl",
"id": "standardschemaqrl",
"hierarchy": [
{
"name": "standardSchemaQrl",
"id": "standardschemaqrl"
}
],
"kind": "Variable",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\n\n\n```typescript\nstandardSchemaQrl: StandardSchemaConstructorQRL\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/server-functions.ts",
"mdFile": "qwik-city.standardschemaqrl.md"
},
{
"name": "StaticGenerate",
"id": "staticgenerate",
Expand Down Expand Up @@ -880,7 +922,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type TypedDataValidator = ValibotDataValidator | ZodDataValidator;\n```",
"content": "```typescript\nexport type TypedDataValidator = ValibotDataValidator | ZodDataValidator | StandardSchemaDataValidator;\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts",
"mdFile": "qwik-city.typeddatavalidator.md"
},
Expand Down Expand Up @@ -968,6 +1010,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/server-functions.ts",
"mdFile": "qwik-city.valibot_.md"
},
{
"name": "ValibotConstructor",
"id": "valibotconstructor",
"hierarchy": [
{
"name": "ValibotConstructor",
"id": "valibotconstructor"
}
],
"kind": "TypeAlias",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\n\n\n```typescript\nexport type ValibotConstructor = {\n <T extends v.GenericSchema | v.GenericSchemaAsync>(schema: T): ValibotDataValidator<T>;\n <T extends v.GenericSchema | v.GenericSchemaAsync>(schema: (ev: RequestEvent) => T): ValibotDataValidator<T>;\n};\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts",
"mdFile": "qwik-city.valibotconstructor.md"
},
{
"name": "valibotQrl",
"id": "valibotqrl",
Expand Down
81 changes: 70 additions & 11 deletions packages/docs/src/routes/api/qwik-city/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,13 @@ RequestEvent \| undefined

```typescript
export type GetValidatorInputType<VALIDATOR extends TypedDataValidator> =
VALIDATOR extends ValibotDataValidator<infer TYPE>
? v.InferInput<TYPE>
: VALIDATOR extends ZodDataValidator<infer TYPE>
? z.input<TYPE>
: never;
VALIDATOR extends StandardSchemaDataValidator<infer TYPE>
? StandardSchemaV1.InferInput<TYPE>
: VALIDATOR extends ValibotDataValidator<infer TYPE>
? v.InferInput<TYPE>
: VALIDATOR extends ZodDataValidator<infer TYPE>
? z.input<TYPE>
: never;
```

**References:** [TypedDataValidator](#typeddatavalidator)
Expand All @@ -1416,11 +1418,13 @@ export type GetValidatorInputType<VALIDATOR extends TypedDataValidator> =

```typescript
export type GetValidatorOutputType<VALIDATOR extends TypedDataValidator> =
VALIDATOR extends ValibotDataValidator<infer TYPE>
? v.InferOutput<TYPE>
: VALIDATOR extends ZodDataValidator<infer TYPE>
? z.output<TYPE>
: never;
VALIDATOR extends StandardSchemaDataValidator<infer TYPE>
? StandardSchemaV1.InferOutput<TYPE>
: VALIDATOR extends ValibotDataValidator<infer TYPE>
? v.InferOutput<TYPE>
: VALIDATOR extends ZodDataValidator<infer TYPE>
? z.output<TYPE>
: never;
```

**References:** [TypedDataValidator](#typeddatavalidator)
Expand Down Expand Up @@ -2489,6 +2493,41 @@ JSXOutput

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/sw-component.tsx)

<h2 id="standardschema_">standardSchema$</h2>

> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

```typescript
standardSchema$: StandardSchemaConstructor;
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/server-functions.ts)

<h2 id="standardschemaconstructor">StandardSchemaConstructor</h2>

> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

```typescript
export type StandardSchemaConstructor = {
<T extends StandardSchemaV1>(schema: T): StandardSchemaDataValidator<T>;
<T extends StandardSchemaV1>(
schema: (ev: RequestEvent) => T,
): StandardSchemaDataValidator<T>;
};
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts)

<h2 id="standardschemaqrl">standardSchemaQrl</h2>

> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

```typescript
standardSchemaQrl: StandardSchemaConstructorQRL;
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/server-functions.ts)

<h2 id="staticgenerate">StaticGenerate</h2>

```typescript
Expand Down Expand Up @@ -2556,7 +2595,10 @@ export type StrictUnion<T> = Prettify<StrictUnionHelper<T, T>>;
<h2 id="typeddatavalidator">TypedDataValidator</h2>

```typescript
export type TypedDataValidator = ValibotDataValidator | ZodDataValidator;
export type TypedDataValidator =
| ValibotDataValidator
| ZodDataValidator
| StandardSchemaDataValidator;
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts)
Expand Down Expand Up @@ -2681,6 +2723,23 @@ valibot$: ValibotConstructor;

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/server-functions.ts)

<h2 id="valibotconstructor">ValibotConstructor</h2>

> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

```typescript
export type ValibotConstructor = {
<T extends v.GenericSchema | v.GenericSchemaAsync>(
schema: T,
): ValibotDataValidator<T>;
<T extends v.GenericSchema | v.GenericSchemaAsync>(
schema: (ev: RequestEvent) => T,
): ValibotDataValidator<T>;
};
```

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/types.ts)

<h2 id="valibotqrl">valibotQrl</h2>

> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Expand Down
19 changes: 18 additions & 1 deletion packages/docs/src/routes/api/qwik-optimizer/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
}
],
"kind": "Enum",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nUse `__EXPERIMENTAL__.x` to check if feature `x` is enabled. It will be replaced with `true` or `false` via an exact string replacement.\n\nAdd experimental features to this enum definition.\n\n\n```typescript\nexport declare enum ExperimentalFeatures \n```\n\n\n<table><thead><tr><th>\n\nMember\n\n\n</th><th>\n\nValue\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nenableRequestRewrite\n\n\n</td><td>\n\n`\"enableRequestRewrite\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable request.rewrite()\n\n\n</td></tr>\n<tr><td>\n\nnoSPA\n\n\n</td><td>\n\n`\"noSPA\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Disable SPA navigation handler in Qwik City\n\n\n</td></tr>\n<tr><td>\n\npreventNavigate\n\n\n</td><td>\n\n`\"preventNavigate\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the usePreventNavigate hook\n\n\n</td></tr>\n<tr><td>\n\nvalibot\n\n\n</td><td>\n\n`\"valibot\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the Valibot form validation\n\n\n</td></tr>\n</tbody></table>",
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nUse `__EXPERIMENTAL__.x` to check if feature `x` is enabled. It will be replaced with `true` or `false` via an exact string replacement.\n\nAdd experimental features to this enum definition.\n\n\n```typescript\nexport declare enum ExperimentalFeatures \n```\n\n\n<table><thead><tr><th>\n\nMember\n\n\n</th><th>\n\nValue\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nenableRequestRewrite\n\n\n</td><td>\n\n`\"enableRequestRewrite\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable request.rewrite()\n\n\n</td></tr>\n<tr><td>\n\nnoSPA\n\n\n</td><td>\n\n`\"noSPA\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Disable SPA navigation handler in Qwik City\n\n\n</td></tr>\n<tr><td>\n\npreventNavigate\n\n\n</td><td>\n\n`\"preventNavigate\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the usePreventNavigate hook\n\n\n</td></tr>\n<tr><td>\n\nstandardSchema\n\n\n</td><td>\n\n`\"standardSchema\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable form validation using Standard Schema\n\n\n</td></tr>\n<tr><td>\n\nvalibot\n\n\n</td><td>\n\n`\"valibot\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the Valibot form validation\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/plugin.ts",
"mdFile": "qwik.experimentalfeatures.md"
},
Expand Down Expand Up @@ -727,6 +727,23 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
"mdFile": "qwik.sourcemapsoption.md"
},
{
"name": "standardSchema",
"id": "experimentalfeatures-standardschema",
"hierarchy": [
{
"name": "ExperimentalFeatures",
"id": "experimentalfeatures-standardschema"
},
{
"name": "standardSchema",
"id": "experimentalfeatures-standardschema"
}
],
"kind": "EnumMember",
"content": "",
"mdFile": "qwik.experimentalfeatures.standardschema.md"
},
{
"name": "symbolMapper",
"id": "symbolmapper",
Expand Down
15 changes: 15 additions & 0 deletions packages/docs/src/routes/api/qwik-optimizer/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ preventNavigate
</td></tr>
<tr><td>

standardSchema

</td><td>

`"standardSchema"`

</td><td>

**_(ALPHA)_** Enable form validation using Standard Schema

</td></tr>
<tr><td>

valibot

</td><td>
Expand Down Expand Up @@ -3023,6 +3036,8 @@ export type SourceMapsOption = "external" | "inline" | undefined | null;

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts)

<h2 id="experimentalfeatures-standardschema">standardSchema</h2>

<h2 id="symbolmapper-variable">symbolMapper</h2>

> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Expand Down
Loading