{"id":20339862,"url":"https://github.com/uditkarode/montype","last_synced_at":"2025-04-11T23:16:21.445Z","repository":{"id":57302646,"uuid":"366541715","full_name":"uditkarode/montype","owner":"uditkarode","description":"🍃 Generate TypeScript interfaces from regular Mongoose schemas.","archived":false,"fork":false,"pushed_at":"2023-04-19T19:59:22.000Z","size":304,"stargazers_count":11,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T23:16:15.473Z","etag":null,"topics":["mongodb","mongoose","mongoose-schema-interface","mongoose-schema-to-typescript","mongoose-to-typescript","mongoose-typescript","schema-generate-interface","typescript","typescript-mongodb","typescript-mongoose"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uditkarode.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":"2021-05-11T23:54:58.000Z","updated_at":"2024-08-16T09:40:58.000Z","dependencies_parsed_at":"2022-09-13T07:30:56.446Z","dependency_job_id":null,"html_url":"https://github.com/uditkarode/montype","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditkarode%2Fmontype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditkarode%2Fmontype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditkarode%2Fmontype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditkarode%2Fmontype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uditkarode","download_url":"https://codeload.github.com/uditkarode/montype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492884,"owners_count":21113163,"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":["mongodb","mongoose","mongoose-schema-interface","mongoose-schema-to-typescript","mongoose-to-typescript","mongoose-typescript","schema-generate-interface","typescript","typescript-mongodb","typescript-mongoose"],"created_at":"2024-11-14T21:18:47.784Z","updated_at":"2025-04-11T23:16:21.417Z","avatar_url":"https://github.com/uditkarode.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/header.jpg\"\u003e\n\u003c/p\u003e\n  \n## Purpose\nMonType converts your [mongoose](https://github.com/Automattic/mongoose) schemas into TypeScript interfaces so you don't have to.\n  \n## Usage\nDefine your schema, like you always do; example from [mongoosejs.com](https://mongoosejs.com/docs/schematypes.html)\n```typescript\nconst schema = new Schema({\n  name:    String,\n  binary:  Buffer,\n  living:  Boolean,\n  updated: { type: Date, default: Date.now },\n  age:     { type: Number, min: 18, max: 65 },\n  mixed:   Schema.Types.Mixed,\n  _someId: Schema.Types.ObjectId,\n  decimal: Schema.Types.Decimal128,\n  array: [],\n  ofString: [String],\n  ofNumber: [Number],\n  ofDates: [Date],\n  ofBuffer: [Buffer],\n  ofBoolean: [Boolean],\n  ofMixed: [Schema.Types.Mixed],\n  ofObjectId: [Schema.Types.ObjectId],\n  ofArrays: [[]],\n  ofArrayOfNumbers: [[Number]],\n  nested: {\n    stuff: { type: String, lowercase: true, trim: true }\n  },\n  map: Map,\n  mapOfString: {\n    type: Map,\n    of: String\n  }\n});\n```\n\nRun `montype --from schema.ts`, and MonType will convert it into a TypeScript interface:\n```typescript\nimport mongoose from 'mongoose';\n\ninterface schema {\n  name: string;\n  binary: mongoose.Schema.Types.Buffer;\n  living: boolean;\n  updated: Date;\n  age: number;\n  mixed: mongoose.Schema.Types.Mixed;\n  _someId: mongoose.Schema.Types.ObjectId;\n  decimal: mongoose.Schema.Types.Decimal128;\n  array: never[];\n  ofString: string[];\n  ofNumber: number[];\n  ofDates: Date[];\n  ofBuffer: mongoose.Schema.Types.Buffer[];\n  ofBoolean: boolean[];\n  ofMixed: mongoose.Schema.Types.Mixed[];\n  ofObjectId: mongoose.Schema.Types.ObjectId[];\n  ofArrays: never[][];\n  ofArrayOfNumbers: number[][];\n  nested: {\n    stuff: string;\n  };\n  map: mongoose.Schema.Types.Map;\n  mapOfString: Map\u003cstring, String\u003e;\n};\n```\n  \nJust like that!\n  \n## How it works\nMonType parses the source file, and generates an AST from it. It then generates a TypeScript interface from the AST. What this means is that MonType only sees your schemas as a structured chunk of text -- nothing less, nothing more.\n  \nIt's completely independent from your source, does not add additional dependencies to your project, and is highly portable and capable on working on any file that looks like a Mongoose schema.\n\n## Installation\nYou can install MonType by either:\n* Using npx: `npx montype`\n* Downloading a precompiled binary from the [releases](https://github.com/uditkarode/montype/releases) page\n* Downloading a build artifact from a Github Actions [run](https://github.com/uditkarode/montype/actions)\n* Compiling it yourself using [build.sh](https://github.com/uditkarode/montype/blob/master/build.sh)\n  \n## Configuration\nMonType works by 'mapping' descriptors to their TypeScript types, for example `String` -\u003e `string`, `Number` -\u003e `number`, and so on.\n  \nThis means that if you use a custom type in your Schema, MonType will fail:\n```diff\n- [×| Category.ts\n-   | couldn't map the schema type 'MyType' to a TypeScript type!\n```\n  \nTo get around this, you can create a configuration file called `montype.ini` (or use the `-c` flag to provide a path) with the contents:\n```ini\n[types]\nMyType = number\n```\n  \nMonType will now interpret `MyType` as `number`, and succeed.\n```diff\n+ [✓] saved to 'MonType.ts'\n```\n\nPlease read `montype --help` for more information!\n  \n## Credits\nThanks to [@MKRhere](https://github.com/MKRhere) for listening to and answering my barrage of questions!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuditkarode%2Fmontype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuditkarode%2Fmontype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuditkarode%2Fmontype/lists"}