{"id":16158119,"url":"https://github.com/typeofweb/typesafe-hapi","last_synced_at":"2025-09-12T21:33:07.619Z","repository":{"id":34298580,"uuid":"175474420","full_name":"typeofweb/typesafe-hapi","owner":"typeofweb","description":"Typechecking for HapiJS based on Joi schemas!","archived":false,"fork":false,"pushed_at":"2022-12-08T18:25:00.000Z","size":219,"stargazers_count":21,"open_issues_count":11,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-29T03:03:12.798Z","etag":null,"topics":["hapi","hapijs","joi","typescript"],"latest_commit_sha":null,"homepage":"https://typeofweb.com/","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/typeofweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-13T18:09:48.000Z","updated_at":"2022-03-23T13:25:28.000Z","dependencies_parsed_at":"2023-01-15T06:03:47.452Z","dependency_job_id":null,"html_url":"https://github.com/typeofweb/typesafe-hapi","commit_stats":null,"previous_names":["typeofweb/typesafe-hapi","mmiszy/typesafe-hapi"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeofweb%2Ftypesafe-hapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeofweb%2Ftypesafe-hapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeofweb%2Ftypesafe-hapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typeofweb%2Ftypesafe-hapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typeofweb","download_url":"https://codeload.github.com/typeofweb/typesafe-hapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232792145,"owners_count":18577261,"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":["hapi","hapijs","joi","typescript"],"created_at":"2024-10-10T01:52:51.624Z","updated_at":"2025-01-06T21:44:43.309Z","avatar_url":"https://github.com/typeofweb.png","language":"TypeScript","readme":"# typesafe-hapi\n\ntypesafe-hapi is a fork of [hapi](https://github.com/hapijs/hapi) which aims to improve typesafety. More precisely, this is a fork of [@types/hapi__hapi](https://www.npmjs.com/package/@types/hapi__hapi) because it has just redefined the essential APIs of hapi.\n\ntypesafe-hapi currently matches the API of hapi 18.3.x. It was tested with TypeScript 3.4.5.\n\n## How it works\n`typesafe-hapi` uses `typesafe-joi` to infer correct type from Joi schemas automatically. It uses possesed type information to typecheck:\n\n* request.query\n* request.payload\n* request.params\n* response\n\n## Example\n\n```ts\nconst payloadSchema = Joi.object({\n  user: Joi.object({\n    name: Joi.string().required(),\n    email: Joi.string().required(),\n  }).required(),\n}).required();\n\nconst querySchema = Joi.object({\n  search: Joi.string().optional().allow('', null),\n}).required();\n\nconst paramsSchema = Joi.object({\n  id: Joi.number().required()\n}).required();\n\nconst responseSchema = Joi.object({\n  id: Joi.number().required(),\n  name: Joi.string().required(),\n  email: Joi.string().required(),\n  search: Joi.string().optional().allow(null),\n}).required();\n\nserver.route({\n  method: 'POST',\n  path: '/:id',\n  options: {\n    validate: {\n      payload: payloadSchema,\n      query: querySchema,\n      params: paramsSchema,\n    },\n    response: {\n      schema: responseSchema,\n    },\n  },\n  handler(request) {\n    // type of `payload` is automatically inferred based on `options.validate.payload` schema\n    const payload = request.payload; // { user: { name: string; email: string; }; } \n    const query = request.query; // { search?: string | null | undefined; }\n    const params = request.params; // { id: number; } \n\n    // return type is also typechecked based on `options.response.schema`\n    return {\n      id: params.id,\n      name: payload.user.name, // string\n      email: payload.user.email, // string\n      search: query.search, // string | null | undefined\n    };\n  },\n});\n```\n\nNeat, huh? See more examples in [index.test-d.ts](https://github.com/mmiszy/typesafe-hapi/blob/master/index.test-d.ts).\n\n## Usage\n\nImport and use hapi from `typesafe-hapi`:\n\n```typescript\nimport * as Hapi from 'typesafe-hapi'\n```\n\nIn order to avoid any compatibility issues, and to be able to use existing packages and plugins easily, you should create an alias for `typesafe-hapi` and rename it to just `hapi`. In your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    // … other options\n    \"paths\": {\n      \"hapi\": [\"node_modules/typesafe-hapi\"],\n      \"joi\": [\"node_modules/typesafe-joi\"]\n    }\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeofweb%2Ftypesafe-hapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypeofweb%2Ftypesafe-hapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypeofweb%2Ftypesafe-hapi/lists"}