{"id":14975717,"url":"https://github.com/jfrazx/mongoose-transient","last_synced_at":"2025-10-27T14:31:14.734Z","repository":{"id":38174561,"uuid":"262891183","full_name":"jfrazx/mongoose-transient","owner":"jfrazx","description":"Create transient properties on mongoose schemas!","archived":false,"fork":false,"pushed_at":"2023-01-06T05:31:36.000Z","size":1989,"stargazers_count":2,"open_issues_count":20,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-28T20:43:22.706Z","etag":null,"topics":["mongoosejs","monogdb","transient","typescript"],"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/jfrazx.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":"2020-05-10T23:03:34.000Z","updated_at":"2023-05-20T20:49:04.000Z","dependencies_parsed_at":"2023-02-05T10:30:26.243Z","dependency_job_id":null,"html_url":"https://github.com/jfrazx/mongoose-transient","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrazx%2Fmongoose-transient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrazx%2Fmongoose-transient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrazx%2Fmongoose-transient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfrazx%2Fmongoose-transient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfrazx","download_url":"https://codeload.github.com/jfrazx/mongoose-transient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219861084,"owners_count":16556007,"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":["mongoosejs","monogdb","transient","typescript"],"created_at":"2024-09-24T13:52:26.153Z","updated_at":"2025-10-27T14:31:09.402Z","avatar_url":"https://github.com/jfrazx.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoose Transient\n\nCreate transient properties on mongoose schemas.\n\n## Basic Usage\n\n```typescript\nimport { transient } from 'mongoose-transient';\nimport * as mongoose from 'mongoose';\n\nconst { Schema } = mongoose;\nconst UserSchema = new Schema({\n  name: String,\n  password: String,\n  confirmationPassword: {\n    type: String,\n    transient: true,\n  },\n  // other fields....\n});\n\nUserSchema.plugin(transient);\n\nexport const User = mongoose.model('User', UserSchema);\n```\n\nThat's it! The `confirmationPassword` field will not be saved to your database but you can still use it on documents and in hooks.\n\n```typescript\nfunction passwordMatchValidation() {\n  if (this.isNew || this.isModified('password')) {\n    if (this.password !== this.confirmationPassword) {\n      this.invalidate('password', 'Password and Confirmation Password do not match');\n    }\n  }\n}\n\nUserSchema.pre('validate', passwordMatchValidation);\n```\n\nAny supplied default values will be used if no assignment has occurred.\n\n```typescript\nconst UserSchema = new Schema({\n  isBrilliant: {\n    type: Boolean,\n    transient: true,\n    default: false,\n  },\n});\n```\n\nTypes are still required by the Schema.\n\n### Options\n\nFor more advanced usage there are a number of options.\n\nInternally a private field is created to store content for transient properties with the default being `_${path}`, e.g. `_confirmationPassword`.\nTo change this simply set the transient property on your schema to a string you would prefer to use.\n\n```typescript\nconst UserSchema = new Schema({\n  confirmationPassword: {\n    type: String,\n    transient: 'passwordConfirmation',\n  },\n});\n```\n\nThis does not affect your future interactions with your documents, you will still call it by the prescribed path: `this.confirmationPassword`. This is really only necessary to avoid conflict with\nmongoose document properties.\n\nYou may want to manipulate values before assignment. To do so, set the transient property to a function that accepts the value being set and returns your modified content. Whatever is returned will be assigned to your field.\n\n```typescript\nconst UserSchema = new Schema({\n  name: String,\n  password: String,\n  modifyMe: {\n    type: String,\n    transient: function (value: string) {\n      return `modified ${value}`;\n    },\n  },\n});\n```\n\nThe supplied function will be called in the context of the current document.\n\nIf you need the full range of options you may pass an object with any of the following properties:\n\n- as: string - As described above, this will set the internal property name for stored content.\n- set: Function - As described above, this function allows manipulation of content being assigned.\n- get: Function - Similar to `set`, this function allows manipulation of content being retrieved.\n- linkTo: string - Adds a link between a transient property and a schema property. Whenever the schema property is updated the transient property is also updated.\n- args: any[] - An array of values that will be passed to `get` and `set`. The contents of the array will be spread when passed. `...args`\n\n```typescript\nconst UserSchema = new Schema({\n  name: String,\n  password: String,\n  role: String,\n  confirmationPassword: {\n    type: String,\n    transient: true,\n  },\n  modifyMe: {\n    type: String,\n    transient: function (value: string) {\n      return `modified ${value}`;\n    },\n  },\n  isBrilliant: {\n    type: Boolean,\n    transient: 'isKindaSmrt',\n    default: false,\n  },\n  description: {\n    type: String,\n    transient: {\n      linkTo: 'role',\n      as: 'roleDescription',\n      args: ['admin', 'moderator', 'user'],\n      set: function (role: string, ...roles: string[]) {\n        return roles.includes(role) ? role : 'invalid';\n      },\n      get: function (role: string) {\n        return `The user role is ${role}`;\n      },\n    },\n  },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfrazx%2Fmongoose-transient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfrazx%2Fmongoose-transient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfrazx%2Fmongoose-transient/lists"}