{"id":13595016,"url":"https://github.com/kevinmarrec/h3-typebox","last_synced_at":"2025-04-09T10:32:41.363Z","repository":{"id":53816996,"uuid":"499889835","full_name":"kevinmarrec/h3-typebox","owner":"kevinmarrec","description":"Schema validation utilities for h3, using typebox \u0026 ajv","archived":true,"fork":false,"pushed_at":"2023-09-02T11:50:22.000Z","size":137,"stargazers_count":65,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T07:47:33.795Z","etag":null,"topics":["h3","hacktoberfest","json-schema","typebox"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinmarrec.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-06-04T17:13:26.000Z","updated_at":"2025-02-11T21:35:35.000Z","dependencies_parsed_at":"2024-01-16T22:18:48.585Z","dependency_job_id":"76209c9b-1ac7-4c13-b810-d497849a9dcf","html_url":"https://github.com/kevinmarrec/h3-typebox","commit_stats":{"total_commits":24,"total_committers":5,"mean_commits":4.8,"dds":"0.20833333333333337","last_synced_commit":"a6f88f08961dff74bb87ff7a1d3816b219c58cf3"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarrec%2Fh3-typebox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarrec%2Fh3-typebox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarrec%2Fh3-typebox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinmarrec%2Fh3-typebox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinmarrec","download_url":"https://codeload.github.com/kevinmarrec/h3-typebox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248020593,"owners_count":21034459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["h3","hacktoberfest","json-schema","typebox"],"created_at":"2024-08-01T16:01:42.478Z","updated_at":"2025-04-09T10:32:36.350Z","avatar_url":"https://github.com/kevinmarrec.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# h3-typebox\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions][github-actions-src]][github-actions-href]\n[![Codecov][codecov-src]][codecov-href]\n\n\u003e JSON schema validation for [h3](https://github.com/unjs/h3), using [typebox](https://github.com/sinclairzx81/typebox) \u0026 [ajv](https://github.com/ajv-validator/ajv).\n\n## Install\n\n```sh\n# Using npm\nnpm install h3-typebox\n\n# Using yarn\nyarn install h3-typebox\n\n# Using pnpm\npnpm install h3-typebox\n```\n\n## Usage\n\n```js\nimport { createServer } from 'http'\nimport { createApp } from 'h3'\nimport { validateBody, validateQuery, Type } from 'h3-typebox'\n\nconst app = createApp()\napp.use('/', async (event) =\u003e {\n  // Validate body\n  const body = await validateBody(event, Type.Object({\n    optional: Type.Optional(Type.String()),\n    required: Type.Boolean(),\n  }))\n\n  // Validate query\n  const query = validateQuery(event, Type.Object({\n    required: Type.String(),\n  }))\n})\n\ncreateServer(app).listen(process.env.PORT || 3000)\n```\n\nSee how to define your schema with `Type` on [TypeBox documentation](https://github.com/sinclairzx81/typebox#usage).\n\n### Options\n\nYou can define a options object on `validateBody` or `validateQuery`. Currently the following options are supported:\n\n- `includeAjvFormats: Boolean`\n\n#### includeAjvFormats\n\nSome formats like `date`, `date-time` or `email` are specified in the current JSONSchema draft, but not included in ajv by default, but provided by the `ajv-formats` package. If one of these formats is needed, you can specify `includeAjvFormats: true` in the options of `validateBody` or `validateQuery` like this:\n\n```ts\n// Body\nvalidateBody(event, schema, { includeAjvFormats: true })\n\n// Query\nvalidateQuery(event, schema, { includeAjvFormats: true })\n```\n\nCurrently, only the following extended formats are supported for performance and security reasons:\n\n- date-time\n- time\n- date\n- email\n- uri\n- uri-reference\n\nThese can be used by custom schemas with the `Type.Unsafe` method or with an inline schema:\n\n```ts\nconst bodySchema = Type.Object({\n  optional: Type.Optional(Type.String()),\n  dateTime: Type.String({ format: 'date-time' })\n})\nvalidateBody(event, bodySchema, { includeAjvFormats: true })\n```\n\n## Development 💻\n\n- Clone this repository\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## License\n\nMade with 💙\n\nPublished under [MIT License](./LICENSE).\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/h3-typebox?style=flat-square\n[npm-version-href]: https://npmjs.com/package/h3-typebox\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/h3-typebox?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/h3-typebox\n\n[github-actions-src]: https://img.shields.io/github/workflow/status/kevinmarrec/h3-typebox/CI\n[github-actions-href]: https://github.com/kevinmarrec/h3-typebox/actions?query=workflow%3Aci\n\n[codecov-src]: https://img.shields.io/codecov/c/gh/kevinmarrec/h3-typebox/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/kevinmarrec/h3-typebox\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinmarrec%2Fh3-typebox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinmarrec%2Fh3-typebox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinmarrec%2Fh3-typebox/lists"}