{"id":28435669,"url":"https://github.com/Re-Quant/api-entity-ref","last_synced_at":"2025-06-27T22:31:21.132Z","repository":{"id":40726849,"uuid":"245919518","full_name":"Re-Quant/api-entity-ref","owner":"Re-Quant","description":"Decorators to copy swagger \u0026 class-validator metadata from one class to another","archived":false,"fork":false,"pushed_at":"2023-03-08T01:51:24.000Z","size":1272,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T21:07:37.740Z","etag":null,"topics":["class-validator","decorators","nestjs","nestjs-library","swagger","swagger-decorators","swagger-documentation","swagger-js","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Re-Quant.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,"governance":null}},"created_at":"2020-03-09T01:39:44.000Z","updated_at":"2021-11-17T16:21:05.000Z","dependencies_parsed_at":"2023-02-09T08:47:09.574Z","dependency_job_id":"fbc73f0b-9c65-405f-8912-08c926335d77","html_url":"https://github.com/Re-Quant/api-entity-ref","commit_stats":null,"previous_names":["re-quant/api-entity-ref","z-brain/api-entity-ref"],"tags_count":15,"template":false,"template_full_name":"korniychuk/wallaby-ts-starter","purl":"pkg:github/Re-Quant/api-entity-ref","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Fapi-entity-ref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Fapi-entity-ref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Fapi-entity-ref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Fapi-entity-ref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Re-Quant","download_url":"https://codeload.github.com/Re-Quant/api-entity-ref/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Re-Quant%2Fapi-entity-ref/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262343719,"owners_count":23296380,"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":["class-validator","decorators","nestjs","nestjs-library","swagger","swagger-decorators","swagger-documentation","swagger-js","typescript"],"created_at":"2025-06-05T21:07:36.900Z","updated_at":"2025-06-27T22:31:21.124Z","avatar_url":"https://github.com/Re-Quant.png","language":"TypeScript","readme":"# Z-Brain Api Entity Ref\n\n\u003cp\u003e\n  \u003ca target=\"_blank\" href=\"https://github.com/z-brain/api-entity-ref/actions?query=workflow%3A%22Build%22\"\u003e\n    \u003cimg alt=\"Build status\" src=\"https://github.com/z-brain/api-entity-ref/workflows/Build/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://www.npmjs.com/package/@z-brain/api-entity-ref\"\u003e\n    \u003cimg alt=\"NPM version\" src=\"https://img.shields.io/npm/v/@z-brain/api-entity-ref.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://codecov.io/gh/z-brain/api-entity-ref\"\u003e\n    \u003cimg alt=\"Code Coverage\" src=\"https://codecov.io/gh/z-brain/api-entity-ref/branch/master/graph/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://www.gnu.org/licenses/gpl-3.0\"\u003e\n    \u003cimg alt=\"License: GPL v3\" src=\"https://img.shields.io/badge/License-GPLv3-blue.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nDecorators to copy `@nestjs/swagger`, `class-validator` and `class-transformer` metadata from one class to another.\n\n*Notice: If you have any propositions feel free to make an issue or create a pull request.*\n\n## How to use\n\n### Installing\n\n`yarn add @z-brain/api-entity-ref`  \nor  \n`npm i -s @z-brain/api-entity-ref`\n\n### Usage example\n\n`dtos/account-base.dto.ts`\n```typescript\nimport { ApiPropertyRef } from '@z-brain/api-entity-ref';\nimport { Account } from '../types';\n\nexport abstract class AccountBaseDto implements Omit\u003cAccount, 'id'\u003e {\n\n  @ApiPropertyRef()\n  public email!: string;\n\n  @ApiPropertyRef()\n  public firstName?: string;\n\n}\n```\n\n`dtos/account-create.dto.ts`\n```typescript\nimport { ApiEntityRef, ApiPropertyRef } from '@z-brain/api-entity-ref';\nimport { EEntityValidationGroup } from '@lib/common/enums';\nimport { Account } from '../types';\nimport { AccountBaseDto } from './account-base.dto';\n\n@ApiEntityRef(Account, { groups: [EEntityValidationGroup.Create] })\nexport class AccountCreateDto extends AccountBaseDto {\n\n  @ApiPropertyRef()\n  public lastName?: string;\n\n}\n```\n\n`dtos/account-update.dto.ts`\n```typescript\nimport { Allow, IsNotEmpty } from 'class-validator';\nimport { ApiEntityRef } from '@z-brain/api-entity-ref';\n\nimport { IDInt } from '@lib/common/types';\nimport { EEntityValidationGroup } from '@lib/common/enums';\n\nimport { Account } from '../types';\nimport { AccountBaseDto } from './account-base.dto';\n\n@ApiEntityRef(Account, { groups: [EEntityValidationGroup.Update] })\nexport class AccountUpdateDto extends AccountBaseDto implements Omit\u003cAccount, 'fullName'\u003e {\n\n  @Allow()\n  @IsNotEmpty()\n  public id!: IDInt;\n\n}\n```\n\n`types/account.entity.ts`\n```typescript\nimport { ApiProperty, ApiPropertyOptional, ApiResponseProperty } from '@nestjs/swagger';\nimport { IsEmail, IsOptional, IsString, Length } from 'class-validator';\nlmport { Type } from 'class-transformer';\n\nimport { IDInt } from '@lib/common/types';\nimport {\n  DEFAULT_EMAIL_MAX_LEN,\n  DEFAULT_EMAIL_MIN_LEN,\n  DEFAULT_NAME_MAX_LEN,\n  DEFAULT_NAME_MIN_LEN,\n} from '@lib/common/db.constants';\nimport { IsUnique } from '@lib/common/validators';\nimport { EEntityValidationGroup } from '@lib/common/enums';\n\nclass FirstLast {\n  @ApiPropertyOptional({\n    example: 'Ivan',\n    maxLength: DEFAULT_NAME_MAX_LEN,\n    minLength: DEFAULT_NAME_MIN_LEN,\n  })\n  @IsOptional({ always: true })\n  @IsString({ always: true })\n  @Length(DEFAULT_NAME_MIN_LEN, DEFAULT_NAME_MAX_LEN, { always: true })\n  @Column({ length: DEFAULT_NAME_MAX_LEN, nullable: true })\n  public first!: string;\n\n  @ApiPropertyOptional({\n    example: 'Trump',\n    maxLength: DEFAULT_NAME_MAX_LEN,\n    minLength: DEFAULT_NAME_MIN_LEN,\n  })\n  @IsOptional({ always: true })\n  @IsString({ always: true })\n  @Length(DEFAULT_NAME_MIN_LEN, DEFAULT_NAME_MAX_LEN, { always: true })\n  @Column({ length: DEFAULT_NAME_MAX_LEN, nullable: true })\n  public last!: string;\n}\n\n@Entity()\nexport class Account {\n  public static readonly NAMELESS_FULL_NAME: string = 'Nameless User';\n\n  @ApiResponseProperty({ example: 1234 })\n  @PrimaryGeneratedColumn('increment', { unsigned: true })\n  public id!: IDInt;\n\n  @ApiProperty({\n    example: 'ivan@gmail.com',\n    maxLength: DEFAULT_NAME_MAX_LEN,\n    minLength: DEFAULT_NAME_MIN_LEN,\n    uniqueItems: true,\n  })\n  @Column({ length: DEFAULT_EMAIL_MAX_LEN, unique: true })\n  @IsOptional({ groups: [EEntityValidationGroup.Update] })\n  @IsEmail(undefined, { always: true })\n  @IsUnique(Account, undefined, { always: true })\n  @Length(DEFAULT_EMAIL_MIN_LEN, DEFAULT_EMAIL_MAX_LEN, { always: true })\n  public email!: string;\n\n  @Column(() =\u003e Name)\n  @Type(() =\u003e Name)\n  public name: FirstLast;\n\n  @ApiResponseProperty({\n    example: 'Ivan Trump',\n  })\n  public get fullName(): string {\n    return this.name.first \u0026\u0026 this.name.last\n           ? `${ this.name.first } ${ this.name.last }`\n           : this.name.first || this.name.last || (this.constructor as typeof Account).NAMELESS_FULL_NAME;\n  }\n\n}\n```\n\n## Development notes\n\n### Quick Start\n\n```bash\ncd /code/z-brain\ngit clone git@github.com:z-brain/api-entity-ref.git\ncd api-entity-ref\nyarn install\n```\n\n### How to use NodeJS version from the `.nvmrc`\n\n1. Install NVM\n2. Use `.nvmrc` file one of the next ways:\n\n    * Execute `nvm use` in the project root directory\n    * Install [NVM Loader](https://github.com/korniychuk/ankor-shell) and your .nvmrc will be loaded automatically when you open the terminal.\n      ![NVM Loader demo](./resources/readme.nvm-loader.png)\n\n### How to make a build\n\n`npm run build`\n\n### How to run lint\n\n* Just show problems `npm run lint`\n* Fix problems if it is possible `npm run lint:fix`\n\n### How to run tests\n\n* All tests\n\n  `npm run test`  \n  `npm run test:watch`\n* Specific tests\n\n  `npm run test -- src/my.spec.ts`  \n  `npm run test:watch -- src/my.spec.ts`\n\n### How to build and publish NPM package\n\n*NPM Token:* `npm_ggEB......6ZRs`\n\nCI configuration details here: [.github/workflows/npmpublish.yml](.github/workflows/npmpublish.yml)\n\n```bash\nnpm run pre-push \\\n\u0026\u0026 npm version patch -m 'Update package version version to %s' \\\n\u0026\u0026 npm run gen-public-package.json \\\n\u0026\u0026 cp README.md dist/ \\\n\u0026\u0026 npm publish dist --access public \\\n\u0026\u0026 git push --no-verify \u0026\u0026 git push --tags --no-verify\n```\n\n### How to build package to local installation\n\n1. `yarn run build:local`\n2. Then you can install a local package build from path `file:.../api-entity-ref/dist`.\n\n## Author\n\n| [\u003cimg src=\"https://www.korniychuk.pro/avatar.jpg\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003eAnton Korniychuk\u003c/sub\u003e](https://korniychuk.pro) |\n| :---: |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRe-Quant%2Fapi-entity-ref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRe-Quant%2Fapi-entity-ref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRe-Quant%2Fapi-entity-ref/lists"}