{"id":20438166,"url":"https://github.com/kiprasmel/tongoose","last_synced_at":"2025-04-12T22:30:03.485Z","repository":{"id":34174704,"uuid":"170938887","full_name":"kiprasmel/tongoose","owner":"kiprasmel","description":"[Discontinued] :blue_book: Auto-generate TypeScript interfaces from Mongoose schemas!","archived":false,"fork":false,"pushed_at":"2022-02-12T10:15:17.000Z","size":165,"stargazers_count":6,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T16:38:42.991Z","etag":null,"topics":["definition","generator","interface","interfaces","mongodb","mongoose","tongoose","type","types","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/kiprasmel.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-02-15T22:53:13.000Z","updated_at":"2022-07-20T02:29:47.000Z","dependencies_parsed_at":"2022-07-25T22:47:30.581Z","dependency_job_id":null,"html_url":"https://github.com/kiprasmel/tongoose","commit_stats":null,"previous_names":["tongoose/tongoose"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Ftongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Ftongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Ftongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Ftongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiprasmel","download_url":"https://codeload.github.com/kiprasmel/tongoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248639639,"owners_count":21137881,"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":["definition","generator","interface","interfaces","mongodb","mongoose","tongoose","type","types","typescript"],"created_at":"2024-11-15T09:09:41.310Z","updated_at":"2025-04-12T22:30:03.449Z","avatar_url":"https://github.com/kiprasmel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tongoose\n\n📘 Auto-generate TypeScript interfaces from Mongoose schemas!\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/tongoose\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n\t\u003cimg src=\"https://img.shields.io/npm/v/tongoose.svg?style=flat-square\" alt=\"\" /\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://www.npmjs.com/package/tongoose\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n\t\u003cimg src=\"https://img.shields.io/npm/dt/tongoose.svg?style=flat-square\" alt=\"\" /\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://github.com/tongoose/tongoose/blob/master/LICENSE\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n\t\u003cimg src=\"https://img.shields.io/npm/l/tongoose.svg?style=flat-square\" alt=\"MIT\"/\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n## Usage\n\n- Remotely\n\n```sh\nnpx tongoose ./path/to/mongoose/model(s/)\n```\n\n- Locally (\u003cspan title=\"More time efficient if ran more than once!\"\u003erecommended\u003c/span\u003e)\n\n```sh\nnpm install --global tongoose\n# or\nyarn global add tongoose\n```\n\nand run\n\n```sh\ntongoose ./path/to/mongoose/model(s/)\n```\n\nThat's it! Now just integrate the generated interfaces with your Mongoose Schemas!\n\nDon't know how? Head over to the [From 0 to hero](https://github.com/tongoose/tongoose#from-0-to-hero) section - you'll set up a sample TypeScript + Babel project \u0026 will learn how to integrate TypeScript with mongoose Schemas!\n\n---\n\n## Table of contents\n\n- [Learn all the basics in just 5 minutes or so while following along!](https://github.com/tongoose/tongoose#from-0-to-hero-youll-love-it)\n\n  - [set up a TypeScript + Babel project](https://github.com/tongoose/tongoose#set-up-a-simple-typescript--babel-project),\n  - [create mongoose schemas](https://github.com/tongoose/tongoose#create-a-mongoose-schema),\n  - [generate TS type definitions / interfaces using tongoose](https://github.com/tongoose/tongoose#generate-the-type-definition-file),\n  - [integrate them in your schemas](https://github.com/tongoose/tongoose#such-success--much-greatness--now-lets-try-to-apply--use-the-generated-type-interface)\n  - ([and test them!](https://github.com/tongoose/tongoose#awesome-now-lets-test-it))\n\n- [The Roadmap](./ROADMAP.md)\n- [How to contribute](https://github.com/tongoose/tongoose#contributing)\n- [Developers](https://github.com/tongoose/tongoose#developers)\n- [License](https://github.com/tongoose/tongoose#license)\n\n## From 0 to hero (you'll love it)\n\n\u003e Note - the code is available at [/tongoose/TypeScript-Babel-Starter](https://github.com/tongoose/TypeScript-Babel-Starter)\n\n\u003e **Warning** - this is currently out-of-date. We'll update this tutorial shortly.\n\n### Set up a simple TypeScript + Babel project\n\n```bash\ngit clone https://github.com/Microsoft/TypeScript-Babel-Starter.git\ncd TypeScript-Babel-Starter\n```\n\n- Install dependencies\n\n```bash\nnpm i mongoose\nnpm i --save-dev @types/node @types/mongoose @types/mongodb\n```\n\n- buckle up\n\n```bash\nrm src/index.ts\nmkdir -pv src/models/\ntouch src/models/User.ts\n```\n\n- open `src/models/User.ts` file in your favorite text editor\n\n### Create a mongoose schema\n\n```ts\n// src/models/User.ts\nimport mongoose from \"mongoose\";\n\nconst UserSchema = new mongoose.Schema({\n\tusername: String,\n\temail: { type: String, required: true },\n\tpassword: { type: String, required: true },\n});\n\nconst User = mongoose.model(\"User\", UserSchema, \"users\");\n\nexport = User;\n```\n\n- Great. Now install `tongoose` \u0026 take a look at the `--help` message:\n\n```bash\nnpm i -g tongoose\ntongoose\n```\n\n```console\nUsage: tongoose ./path/to/models/ [--opt [arg]]\n\nOptions:\n  -s, --src, --source  [required] [selected by default] relative path to\n                       mongoose models' directory\n\n  -o, --output         [auto=source/index.d.ts] relative path for index.d.ts\n                       type definition output\n\n  -n, --noFormat       [auto=false] do not format the type definition files\n\n  -d, --debug          [auto=false] enables debugging - generates .tongoose/\n                       directory with separate type definition, raw \u0026 clean\n                       json files for each schema\n\n  -v, --version        Show version number\n  -h, --help           Show help\n\nExamples:\n  tongoose ./src/models\n  tongoose ./src/models --noFormat\n  tongoose --help\n```\n\n### Generate the type definition file!\n\n- Run `tongoose` with the path to our `src/models/` directory\n\n```bash\ntongoose src/models/\n```\n\n```console\n⚡️ Tongoose finished\n📂 Created `.tongoose` directory for manual debugging (you can safely delete it)\n📘 Main `index.d.ts` file placed in 👉 `src/models/index.d.ts`\n```\n\n- open the generated `src/models/index.d.ts` file \u0026 take a look!\n\n```ts\nimport mongoose from \"mongoose\"\nimport { ObjectId } from \"bson\"; // `npm i --save-dev @types/mongodb`\n\n// Notice the difference between `IUserModel` \u0026 `IUser`!\nexport interface IUserModel extends IUser, mongoose.Document {}\nexport interface IUser {\n\tusername?: string;\n\temail: string;\n\tpassword: string;\n}\n```\n\n### Such Success! 😱 Much Greatness! 😍 Now let's try to apply \u0026 use the generated type interface\n\n- head back to `src/models/User.ts`\n- make the following changes:\n\n```diff\n// src/models/User.ts\nimport mongoose from \"mongoose\";\n+import { IUserModel } from './index.d';\n\nconst UserSchema = new mongoose.Schema({\n\tusername: String,\n\temail: { type: String, required: true },\n\tpassword: { type: String, required: true },\n});\n\n-const User = mongoose.model(\"User\", UserSchema, \"users\");\n+const User = mongoose.model\u003cIUserModel\u003e(\"User\", UserSchema, \"users\");\n\nexport = User;\n```\n\n### Awesome! Now let's test it!\n\n- Create a `src/test.ts` file\n\n```bash\ntouch src/test.ts\n```\n\n- open it \u0026 add the following code:\n\n```ts\n// src/test.ts\nimport User = require(\"./models/User\");\n\nconst user = new User({});\n```\n\n- Start typing **`user\u003cdot\u003e`** and see what comes up!\n\nPlot twist:\n\n![](https://i.imgur.com/QXqYwVT.png)\n\n- You can see the `email` field right at the bottom together with `mongoose.Document`'s fields. Everything (**hopefully**) worked great!\n\n- Congratulations!\n\n---\n\n[Back to Table of Contents ☝️](https://github.com/tongoose/tongoose#table-of-contents)\n\n---\n\n## [Our Roadmap](./ROADMAP.md)\n\n## Contributing\n\nContributions are welcome! Please fork the repo, modify it \u0026 submit a pull request!\n\nThe [Roadmap](./ROADMAP.md) is a good place to start 😃\n\n## Developers\n\n- **Kipras Melnikovas** - author - [**/sarpik**](https://github.com/sarpik) 😎\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiprasmel%2Ftongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiprasmel%2Ftongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiprasmel%2Ftongoose/lists"}