{"id":28214524,"url":"https://github.com/goodrequest/joi-type-extract","last_synced_at":"2025-07-14T16:34:58.153Z","repository":{"id":39709552,"uuid":"477667030","full_name":"GoodRequest/joi-type-extract","owner":"GoodRequest","description":"Extract type from Joi schema","archived":false,"fork":false,"pushed_at":"2023-01-19T16:22:30.000Z","size":18,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-18T01:51:25.888Z","etag":null,"topics":["backend","express","joi","typescript","web-utils"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoodRequest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-04T11:17:14.000Z","updated_at":"2024-10-30T14:02:06.000Z","dependencies_parsed_at":"2023-02-11T09:20:22.138Z","dependency_job_id":null,"html_url":"https://github.com/GoodRequest/joi-type-extract","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/GoodRequest/joi-type-extract","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-type-extract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-type-extract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-type-extract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-type-extract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodRequest","download_url":"https://codeload.github.com/GoodRequest/joi-type-extract/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodRequest%2Fjoi-type-extract/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265319496,"owners_count":23746361,"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":["backend","express","joi","typescript","web-utils"],"created_at":"2025-05-17T21:08:01.245Z","updated_at":"2025-07-14T16:34:58.143Z","avatar_url":"https://github.com/GoodRequest.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# joi-type-extract\nClone of https://github.com/TCMiranda/joi-extract-type\u003cbr\u003e\n\n## Setup\n1. Install package\n\t```bash\n\tnpm install @goodrequest/joi-type-extract\n\tor\n\tyarn add @goodrequest/joi-type-extract\n\t```\n2. Create ./src/types/joi/index.d.ts and import package in it, which will extend Joi types\n   ```Typescript\n   import '@goodrequest/joi-type-extract'\n   ```\n3. Add this compiler option and include created file in tsconfig.json in typeRoots\n\t```Json\n\t{\n\t\t\"compilerOptions\": {\n            \"strictNullChecks\": true,\n\t\t\t\"typeRoots\": [\n\t\t\t\t\"./src/types\"\n\t\t\t]\n\t\t}\n\t}\n\t```\n\n## Usage example\n\n```Typescript\nimport Joi from 'joi'\n\nexport const requestSchema = () =\u003e\n\tJoi.object({\n\t\tparams: Joi.object({\n\t\t\tuserID: Joi.number().required()\n\t\t}),\n\t\tquery: Joi.object({\n\t\t\tsearch: Joi.string().required()\n\t\t}),\n\t\tbody: Joi.object({\n\t\t\tname: Joi.string().required()\n\t\t})\n\t})\n\nexport const responseSchema = Joi.object({\n   messages: Joi.array().items({\n\t   message: Joi.string().required(),\n\t   type: Joi.string().valid(MESSAGE_TYPE.SUCCESS).required()\n   }).required()\n})\n\ntype RequestType = Joi.extractType\u003cReturnType\u003ctypeof requestSchema\u003e\u003e\ntype ResponseType = Joi.extractType\u003ctypeof fullMessagesResponseSchema\u003e\n```\nExtracted EequestType and ResponseType can be then used in express.Request and express.Response types\n```Typescript\nimport { Request, Response, NextFunction } from 'express'\n\nconst businessLogic = async (\n\treq: Request\u003cRequestType['params'], ResponseType, RequestType['body'], RequestType['query']\u003e,\n\tres: Response\u003cResponseType\u003e,\n\tnext: NextFunction\n) =\u003e {\n\tconst { params, query, body } = req\n\n\t// params.userID will have number type\n\t// query.serch will have string type\n\t// body.name will have string type\n\n\t// response will be enforced to be same as ResponseType\n\treturn res.json({\n\t\tmessages: [\n\t\t\t{\n\t\t\t\tmessage: 'Response message',\n\t\t\t\ttype: MESSAGE_TYPE.SUCCESS\n\t\t\t}\n\t\t]\n\t})\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodrequest%2Fjoi-type-extract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodrequest%2Fjoi-type-extract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodrequest%2Fjoi-type-extract/lists"}