diff --git a/.e2e.env b/.e2e.env new file mode 100644 index 00000000..f48c488a --- /dev/null +++ b/.e2e.env @@ -0,0 +1 @@ +DB_LOGGING=0 diff --git a/.env b/.env new file mode 100644 index 00000000..eaa22638 --- /dev/null +++ b/.env @@ -0,0 +1,14 @@ +DB_HOST=localhost +DB_LOGGING=1 + +DB_USERNAME="postgres" +DB_PASSWORD="postgres" +DB_NAME="json-api-db" +DB_PORT=5432 +DB_TYPE=postgres + +#DB_USERNAME="root" +#DB_PASSWORD="password" +#DB_NAME="example_new" +#DB_PORT=3306 +#DB_TYPE=mysql diff --git a/.github/actions/action.yml b/.github/actions/action.yml index 1eeb890f..d7d2729f 100644 --- a/.github/actions/action.yml +++ b/.github/actions/action.yml @@ -13,12 +13,10 @@ runs: with: path: | node_modules - .nx - .angular ~/.cache/Cypress # needed for the Cypress binary key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }} - name: Npm install - if: steps.cache.outputs.cache-hit != 'true' + if: steps.cache-dependencies-restore.outputs.cache-hit != 'true' run: npm ci shell: bash - name: Cache npm dependencies diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 049df412..7c7f7179 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -23,28 +23,75 @@ jobs: run: | echo "GIST_SECRET=${{ secrets.GIST_SECRET }}" >> $GITHUB_ENV echo "GIST_ID=${{ secrets.GIST_ID }}" >> $GITHUB_ENV + - name: Restore cached .nx + id: cache-nx-restore + uses: actions/cache/restore@v4 + with: + path: | + .nx + key: ${{ runner.os }}-nx-master" - name: Test and build run: npx nx affected -t test build --parallel=3 --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,database,@nestjs-json-api/source' - name: Upload test coverage badge run: npx nx affected -t upload-badge --parallel=3 --exclude='json-api-front,json-api-server,shared-utils,json-api-server-e2e,json-shared-type,database,@nestjs-json-api/source' - - name: Cache npm dependencies + - name: Save cached .nx id: cache-dependencies-save uses: actions/cache/save@v4 with: path: | .nx - .angular - key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }} -# env: -# GIST_SECRET: ${{ secrets.GIST_SECRET }} -# GIST_ID: ${{ secrets.GIST_ID }} - # - run: npm nx affected -t e2e-ci --parallel=1 - # - run: npm nx affected -t deploy --no-agents - + key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }} + run-e2e-test: + runs-on: ubuntu-latest + name: Try run e2e test + needs: + - build-and-test + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: json-api-db + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Npm install + uses: ./.github/actions + - name: Restore cached .nx + id: cache-nx-restore + uses: actions/cache/restore@v4 + with: + path: | + .nx + key: ${{ runner.os }}-nx-master" + - run: git branch --track main origin/master + - run: npm run typeorm migration:run + - run: npm run seed:run + - run: npx nx affected -t e2e --parallel=1 + - name: Save cached .nx + id: cache-dependencies-save + uses: actions/cache/save@v4 + with: + path: | + .nx + key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }} bump-version: name: "Bump version" needs: - - build-and-test + - run-e2e-test runs-on: ubuntu-latest permissions: contents: "write" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46c663d8..edd81774 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ on: - synchronize jobs: run-test: + name: Try build and run unit test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -15,17 +16,73 @@ jobs: fetch-depth: 0 - name: Npm install uses: ./.github/actions - # This line is needed for nx affected to work when CI is running on a PR + - name: Get branch names. + id: branch-names + uses: tj-actions/branch-names@v8 + - name: Restore cached .nx + id: cache-nx-restore + uses: actions/cache/restore@v4 + with: + path: | + .nx + key: ${{ runner.os }}-nx-${{ steps.branch-names.outputs.current_branch }}" - run: git branch --track main origin/master - name: Test and build run: npx nx affected -t test build --parallel=3 --exclude='json-api-front,json-api-server,json-api-server-e2e,json-shared-type,database,@nestjs-json-api/source' - - name: Cache npm dependencies + - name: Save cached .nx + id: cache-dependencies-save + uses: actions/cache/save@v4 + with: + path: | + .nx + key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }} + run-e2e-test: + runs-on: ubuntu-latest + name: Try run e2e test + needs: + - run-test + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: json-api-db + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Npm install + uses: ./.github/actions + - name: Get branch names. + id: branch-names + uses: tj-actions/branch-names@v8 + - name: Restore cached .nx + id: cache-nx-restore + uses: actions/cache/restore@v4 + with: + path: | + .nx + key: ${{ runner.os }}-nx-${{ steps.branch-names.outputs.current_branch }}" + - run: git branch --track main origin/master + - run: npm run typeorm migration:run + - run: npm run seed:run + - run: npx nx affected -t e2e --parallel=1 + - name: Save cached .nx id: cache-dependencies-save uses: actions/cache/save@v4 with: path: | .nx - .angular - key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package-lock.json') }} -# - run: npm nx affected -t e2e-ci --parallel=1 -# - run: npm nx affected -t deploy --no-agents + key: ${{ steps.cache-nx-restore.outputs.cache-primary-key }} diff --git a/apps/json-api-server-e2e/jest.config.ts b/apps/json-api-server-e2e/jest.config.ts index a85f1bbb..f9502b7b 100644 --- a/apps/json-api-server-e2e/jest.config.ts +++ b/apps/json-api-server-e2e/jest.config.ts @@ -6,10 +6,14 @@ export default { globalTeardown: '/src/support/global-teardown.ts', setupFiles: ['/src/support/test-setup.ts'], testEnvironment: 'node', + maxWorkers: 1, transform: { - '^.+\\.[tj]s$': ['ts-jest', { - tsconfig: '/tsconfig.spec.json', - }], + '^.+\\.[tj]s$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.spec.json', + }, + ], }, moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '../../coverage/json-api-server-e2e', diff --git a/apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts b/apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts index f5b9d2bb..2bbf853e 100644 --- a/apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts +++ b/apps/json-api-server-e2e/src/json-api/json-api-sdk/atomic-sdk.spec.ts @@ -1,13 +1,19 @@ -import { - adapterForAxios, - FilterOperand, - JsonApiJs, - JsonSdkPromise, -} from 'json-api-nestjs-sdk'; -import axios from 'axios'; +import { INestApplication } from '@nestjs/common'; +import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk'; import { Addresses, CommentKind, Comments, Roles, Users } from 'database'; import { faker } from '@faker-js/faker'; import { getUser } from '../utils/data-utils'; +import { run, creatSdk } from '../utils/run-ppplication'; + +let app: INestApplication; + +beforeAll(async () => { + app = await run(); +}); + +afterAll(async () => { + await app.close(); +}); describe('Atomic method:', () => { let jsonSdk: JsonSdkPromise; @@ -16,18 +22,7 @@ describe('Atomic method:', () => { let commentsArray: Comments[]; let usersId: number[]; beforeEach(async () => { - const axiosAdapter = adapterForAxios(axios); - - jsonSdk = JsonApiJs( - { - adapter: axiosAdapter, - apiHost: 'http://localhost:3000', - apiPrefix: 'api', - dateFields: ['createdAt', 'updatedAt'], - operationUrl: 'operation', - }, - true - ); + jsonSdk = creatSdk(); const addressesPromise = Array.from(new Array(2)).map(() => { const address = new Addresses(); diff --git a/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-common-decorator.spec.ts b/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-common-decorator.spec.ts index 13295a7e..91751fb0 100644 --- a/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-common-decorator.spec.ts +++ b/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-common-decorator.spec.ts @@ -1,27 +1,24 @@ -import { - adapterForAxios, - FilterOperand, - JsonApiJs, - JsonSdkPromise, -} from 'json-api-nestjs-sdk'; -import axios, { AxiosError } from 'axios'; +import { INestApplication } from '@nestjs/common'; +import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk'; +import { AxiosError } from 'axios'; import { Users } from 'database'; +import { run, creatSdk } from '../utils/run-ppplication'; + +let app: INestApplication; + +beforeAll(async () => { + app = await run(); +}); + +afterAll(async () => { + await app.close(); +}); + describe('Check common decorator', () => { let jsonSdk: JsonSdkPromise; - const axiosAdapter = adapterForAxios(axios); beforeEach(async () => { - jsonSdk = JsonApiJs( - { - adapter: axiosAdapter, - apiHost: 'http://localhost:3000', - apiPrefix: 'api', - dateFields: ['createdAt', 'updatedAt'], - operationUrl: 'operation', - idIsNumber: false, - }, - true - ); + jsonSdk = creatSdk(); }); afterEach(async () => {}); diff --git a/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-othe-call.spec.ts b/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-othe-call.spec.ts index f6544810..3a44773f 100644 --- a/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-othe-call.spec.ts +++ b/apps/json-api-server-e2e/src/json-api/json-api-sdk/check-othe-call.spec.ts @@ -1,29 +1,28 @@ -import { - adapterForAxios, - FilterOperand, - JsonApiJs, - JsonSdkPromise, -} from 'json-api-nestjs-sdk'; +import { INestApplication } from '@nestjs/common'; +import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk'; import { BookList, Users } from 'database'; -import axios, { AxiosError } from 'axios'; +import { AxiosError } from 'axios'; import { faker } from '@faker-js/faker'; import { lastValueFrom } from 'rxjs'; +import { creatSdk, run, axiosAdapter } from '../utils/run-ppplication'; + +let app: INestApplication; + +beforeAll(async () => { + app = await run(); +}); + +afterAll(async () => { + await app.close(); +}); describe('Other call type:', () => { let jsonSdk: JsonSdkPromise; - const axiosAdapter = adapterForAxios(axios); + beforeEach(async () => { - jsonSdk = JsonApiJs( - { - adapter: axiosAdapter, - apiHost: 'http://localhost:3000', - apiPrefix: 'api', - dateFields: ['createdAt', 'updatedAt'], - operationUrl: 'operation', - idIsNumber: false, - }, - true - ); + jsonSdk = creatSdk({ + idIsNumber: false, + }); }); afterEach(async () => {}); @@ -52,7 +51,6 @@ describe('Other call type:', () => { jsonSdk.jsonApiUtilsService.convertResponseData(newBookSource); expect(newBook.id).toBeDefined(); - const bookResultSource = await lastValueFrom( axiosAdapter.get(`${url}/${newBook.id}`) ); diff --git a/apps/json-api-server-e2e/src/json-api/json-api-sdk/get-method.spec.ts b/apps/json-api-server-e2e/src/json-api/json-api-sdk/get-method.spec.ts index bd6822bb..8dec9b0c 100644 --- a/apps/json-api-server-e2e/src/json-api/json-api-sdk/get-method.spec.ts +++ b/apps/json-api-server-e2e/src/json-api/json-api-sdk/get-method.spec.ts @@ -1,14 +1,20 @@ +import { INestApplication } from '@nestjs/common'; import { Addresses, CommentKind, Comments, Roles, Users } from 'database'; import { faker } from '@faker-js/faker'; -import { - adapterForAxios, - FilterOperand, - JsonApiJs, - JsonSdkPromise, -} from 'json-api-nestjs-sdk'; -import axios from 'axios'; +import { FilterOperand, JsonSdkPromise } from 'json-api-nestjs-sdk'; import { getUser } from '../utils/data-utils'; +import { creatSdk, run } from '../utils/run-ppplication'; + +let app: INestApplication; + +beforeAll(async () => { + app = await run(); +}); + +afterAll(async () => { + await app.close(); +}); describe('GET method:', () => { let jsonSdk: JsonSdkPromise; @@ -18,17 +24,7 @@ describe('GET method:', () => { let commentsArray: Comments[]; beforeAll(async () => { - const axiosAdapter = adapterForAxios(axios); - - jsonSdk = JsonApiJs( - { - adapter: axiosAdapter, - apiHost: 'http://localhost:3000', - apiPrefix: 'api', - dateFields: ['createdAt', 'updatedAt'], - }, - true - ); + jsonSdk = creatSdk(); const addressesPromise = Array.from(new Array(2)).map(() => { const address = new Addresses(); diff --git a/apps/json-api-server-e2e/src/json-api/json-api-sdk/patch-methode.spec.ts b/apps/json-api-server-e2e/src/json-api/json-api-sdk/patch-methode.spec.ts index a6cef15a..ffdd50f8 100644 --- a/apps/json-api-server-e2e/src/json-api/json-api-sdk/patch-methode.spec.ts +++ b/apps/json-api-server-e2e/src/json-api/json-api-sdk/patch-methode.spec.ts @@ -1,11 +1,19 @@ +import { INestApplication } from '@nestjs/common'; import { Addresses, CommentKind, Comments, Users } from 'database'; import { faker } from '@faker-js/faker'; -import { - adapterForAxios, - JsonApiJs, - JsonSdkPromise, -} from 'json-api-nestjs-sdk'; -import axios from 'axios'; +import { JsonSdkPromise } from 'json-api-nestjs-sdk'; + +import { creatSdk, run } from '../utils/run-ppplication'; + +let app: INestApplication; + +beforeAll(async () => { + app = await run(); +}); + +afterAll(async () => { + await app.close(); +}); describe('PATCH method:', () => { let jsonSdk: JsonSdkPromise; @@ -19,17 +27,7 @@ describe('PATCH method:', () => { let newCommentsAfterSave: Comments; beforeEach(async () => { - const axiosAdapter = adapterForAxios(axios); - - jsonSdk = JsonApiJs( - { - adapter: axiosAdapter, - apiHost: 'http://localhost:3000', - apiPrefix: 'api', - dateFields: ['createdAt', 'updatedAt'], - }, - true - ); + jsonSdk = creatSdk(); address = new Addresses(); address.city = faker.string.alpha(50); diff --git a/apps/json-api-server-e2e/src/json-api/json-api-sdk/post-method.spec.ts b/apps/json-api-server-e2e/src/json-api/json-api-sdk/post-method.spec.ts index 9f0c13d2..640eb997 100644 --- a/apps/json-api-server-e2e/src/json-api/json-api-sdk/post-method.spec.ts +++ b/apps/json-api-server-e2e/src/json-api/json-api-sdk/post-method.spec.ts @@ -1,11 +1,18 @@ import { Addresses, BookList, CommentKind, Comments, Users } from 'database'; import { faker } from '@faker-js/faker'; -import { - adapterForAxios, - JsonApiJs, - JsonSdkPromise, -} from 'json-api-nestjs-sdk'; -import axios from 'axios'; +import { JsonSdkPromise } from 'json-api-nestjs-sdk'; + +import { creatSdk, run } from '../utils/run-ppplication'; +import { INestApplication } from '@nestjs/common'; +let app: INestApplication; + +beforeAll(async () => { + app = await run(); +}); + +afterAll(async () => { + await app.close(); +}); describe('POST method:', () => { let jsonSdk: JsonSdkPromise; @@ -18,17 +25,7 @@ describe('POST method:', () => { let commentsAfterSave: Comments; beforeEach(() => { - const axiosAdapter = adapterForAxios(axios); - - jsonSdk = JsonApiJs( - { - adapter: axiosAdapter, - apiHost: 'http://localhost:3000', - apiPrefix: 'api', - dateFields: ['createdAt', 'updatedAt'], - }, - true - ); + jsonSdk = creatSdk(); address = new Addresses(); address.city = faker.string.alpha(50); diff --git a/apps/json-api-server-e2e/src/json-api/utils/run-ppplication.ts b/apps/json-api-server-e2e/src/json-api/utils/run-ppplication.ts new file mode 100644 index 00000000..922bb7a3 --- /dev/null +++ b/apps/json-api-server-e2e/src/json-api/utils/run-ppplication.ts @@ -0,0 +1,47 @@ +import { Test } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import { NestFactory } from '@nestjs/core'; +import { adapterForAxios, JsonApiJs } from 'json-api-nestjs-sdk'; +import axios from 'axios'; +import { Logger } from 'nestjs-pino'; + +import { AppModule } from '../../../../json-api-server/src/app/app.module'; + +import { JsonConfig } from '../../../../../libs/json-api/json-api-nestjs-sdk/src/lib/types'; + +export const axiosAdapter = adapterForAxios(axios); +let saveApp: INestApplication; + +export const port = 3000; +export const globalPrefix = 'api'; +export const run = async () => { + if (saveApp) return saveApp; + const moduleRef = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + const app = moduleRef.createNestApplication({ + bufferLogs: true, + logger: false, + }); + app.useLogger(app.get(Logger)); + // const app = await NestFactory.create(AppModule); + app.setGlobalPrefix(globalPrefix); + await app.init(); + await app.listen(port); + + saveApp = app; + return app; +}; + +export const creatSdk = (config: Partial = {}) => + JsonApiJs( + { + adapter: axiosAdapter, + apiHost: `http://localhost:${port}`, + apiPrefix: globalPrefix, + dateFields: ['createdAt', 'updatedAt'], + operationUrl: 'operation', + ...config, + }, + true + ); diff --git a/apps/json-api-server-e2e/tsconfig.spec.json b/apps/json-api-server-e2e/tsconfig.spec.json index 221bd748..30dc8a48 100644 --- a/apps/json-api-server-e2e/tsconfig.spec.json +++ b/apps/json-api-server-e2e/tsconfig.spec.json @@ -3,7 +3,14 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", - "types": ["jest", "node"] + "types": ["jest", "node"], + "emitDecoratorMetadata": true, + "target": "es2021", + "strictBindCallApply": true, + "strictNullChecks": true, + "noImplicitAny": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true }, "include": [ "jest.config.ts", diff --git a/apps/json-api-server/src/app/app.module.ts b/apps/json-api-server/src/app/app.module.ts index fc83ea15..3d7ea992 100644 --- a/apps/json-api-server/src/app/app.module.ts +++ b/apps/json-api-server/src/app/app.module.ts @@ -3,6 +3,7 @@ import { LoggerModule } from 'nestjs-pino'; import { DatabaseModule } from 'database'; import { ResourcesModule } from './resources/resources.module'; +import * as process from 'process'; @Module({ imports: [ @@ -10,7 +11,7 @@ import { ResourcesModule } from './resources/resources.module'; ResourcesModule, LoggerModule.forRoot({ pinoHttp: { - level: 'debug', + level: process.env['NODE_ENV'] === 'test' ? 'silent' : 'debug', }, }), ], diff --git a/libs/database/src/lib/config-cli.ts b/libs/database/src/lib/config-cli.ts index 916094df..8f782496 100644 --- a/libs/database/src/lib/config-cli.ts +++ b/libs/database/src/lib/config-cli.ts @@ -1,17 +1,20 @@ import { DataSource, DataSourceOptions } from 'typeorm'; import { join } from 'path'; +import * as process from 'process'; const config: DataSourceOptions = { - type: 'postgres', - host: 'localhost', - port: 5432, - username: 'postgres', - password: 'postgres', - database: 'json-api-db', - logging: true, + type: process.env['DB_TYPE'] as 'mysql' | 'postgres', + host: process.env['DB_HOST'], + port: parseInt(`${process.env['DB_PORT']}`, 10), + username: process.env['DB_USERNAME'], + password: process.env['DB_PASSWORD'], + database: process.env['DB_NAME'], + logging: process.env['DB_LOGGING'] === '1', migrations: [join(__dirname, '/migrations/**/*{.ts,.js}')], entities: [join(__dirname, '/entities/**/*{.ts,.js}')], + ...(process.env['DB_TYPE'] === 'mysql' ? { connectorPackage: 'mysql2' } : {}), }; + // const config: DataSourceOptions = { // type: 'mysql', // host: 'localhost', diff --git a/libs/database/src/lib/migrations/1607701631900-CreateAddressesTable.ts b/libs/database/src/lib/migrations/1607701631900-CreateAddressesTable.ts index 0acfaa5b..986e2eab 100644 --- a/libs/database/src/lib/migrations/1607701631900-CreateAddressesTable.ts +++ b/libs/database/src/lib/migrations/1607701631900-CreateAddressesTable.ts @@ -1,6 +1,6 @@ import { MigrationInterface, QueryRunner, TableColumn, Table } from 'typeorm'; -export class CreateAddressesTable1607701632000 implements MigrationInterface { +export class CreateAddressesTable1607701631900 implements MigrationInterface { protected readonly tableName = 'addresses'; public async up(queryRunner: QueryRunner): Promise { diff --git a/libs/json-api/json-api-nestjs/src/lib/helper/bind-controller.ts b/libs/json-api/json-api-nestjs/src/lib/helper/bind-controller.ts index 4b46aa12..28eff2c9 100644 --- a/libs/json-api/json-api-nestjs/src/lib/helper/bind-controller.ts +++ b/libs/json-api/json-api-nestjs/src/lib/helper/bind-controller.ts @@ -42,7 +42,7 @@ export function bindController( if (!allowMethod.includes(name)) continue; } - if (!Object.prototype.hasOwnProperty.call(controller, name)) { + if (!Object.prototype.hasOwnProperty.call(controller.prototype, name)) { // need uniq descriptor for correct work swagger Reflect.defineProperty(controller.prototype, name, { value: function ( diff --git a/libs/json-api/json-api-nestjs/src/lib/mixin/interceptors/error.interceptors.ts b/libs/json-api/json-api-nestjs/src/lib/mixin/interceptors/error.interceptors.ts index e659b27a..ce0e0e28 100644 --- a/libs/json-api/json-api-nestjs/src/lib/mixin/interceptors/error.interceptors.ts +++ b/libs/json-api/json-api-nestjs/src/lib/mixin/interceptors/error.interceptors.ts @@ -34,7 +34,6 @@ export class ErrorInterceptors implements NestInterceptor { ): Observable | Promise> { return next.handle().pipe( catchError((error) => { - console.log(error); if (error instanceof QueryFailedError) { return throwError(() => this.prepareDataBaseError(error)); } diff --git a/nx.json b/nx.json index d178dcc7..ee97f50f 100644 --- a/nx.json +++ b/nx.json @@ -15,7 +15,9 @@ "!{projectRoot}/src/test-setup.[jt]s", "!{projectRoot}/test-setup.[jt]s" ], - "sharedGlobals": [] + "sharedGlobals": [ + "{workspaceRoot}/.github/**/*" + ] }, "plugins": [ { diff --git a/package-lock.json b/package-lock.json index 2ecf1ca8..001c0555 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,6 +48,8 @@ "@angular/compiler-cli": "17.2.2", "@angular/language-service": "17.2.2", "@faker-js/faker": "^8.4.1", + "@jorgebodega/typeorm-factory": "^1.4.0", + "@jorgebodega/typeorm-seeding": "^6.0.1", "@nestjs/schematics": "^10.0.1", "@nestjs/testing": "^10.0.2", "@nx/angular": "18.0.7", @@ -4456,6 +4458,165 @@ "node": ">=8" } }, + "node_modules/@jorgebodega/typeorm-factory": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@jorgebodega/typeorm-factory/-/typeorm-factory-1.4.0.tgz", + "integrity": "sha512-c02QHz1FcR8w4Tzv2Ibf2SvxF4LYlna0DktNT9kfMFkMajcbP94KBN4EBpP4ECU/0baY1pflzhFhphlGErUamA==", + "dev": true, + "dependencies": { + "tslib": "2.4.1" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "typeorm": "^0.3.0" + } + }, + "node_modules/@jorgebodega/typeorm-factory/node_modules/tslib": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", + "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", + "dev": true + }, + "node_modules/@jorgebodega/typeorm-seeding": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@jorgebodega/typeorm-seeding/-/typeorm-seeding-6.0.1.tgz", + "integrity": "sha512-vmjomtkMvOlwKeJtGSVb68519TCGKfENCSKE6zxMvr9GTZ+4XiLvIcp6tM5Irl10Pji9dNHPrXdh9HfTvm18aw==", + "dev": true, + "dependencies": { + "chalk": "4.1.2", + "commander": "9.4.1", + "glob": "8.0.3", + "ora": "5.4.1", + "tslib": "2.4.1" + }, + "bin": { + "typeorm-seeding": "dist/cli.js" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "typeorm": "^0.3.0" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/commander": { + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.1.tgz", + "integrity": "sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==", + "dev": true, + "engines": { + "node": "^12.20.0 || >=14" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/glob": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz", + "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@jorgebodega/typeorm-seeding/node_modules/tslib": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", + "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", + "dev": true + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.4", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.4.tgz", @@ -7158,7 +7319,7 @@ "version": "1.3.107", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.107.tgz", "integrity": "sha512-zKhqDyFcTsyLIYK1iEmavljZnf4CCor5pF52UzLAz4B6Nu/4GLU+2LQVAf+oRHjusG39PTPjd2AlRT3f3QWfsQ==", - "dev": true, + "devOptional": true, "hasInstallScript": true, "dependencies": { "@swc/counter": "^0.1.1", @@ -7199,7 +7360,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -7215,7 +7375,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -7231,7 +7390,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "linux" @@ -7247,7 +7405,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -7263,7 +7420,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -7279,7 +7435,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -7295,7 +7450,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -7311,7 +7465,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -7327,7 +7480,6 @@ "cpu": [ "ia32" ], - "dev": true, "optional": true, "os": [ "win32" @@ -7343,7 +7495,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -7356,13 +7507,13 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", - "dev": true + "devOptional": true }, "node_modules/@swc/helpers": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.6.tgz", "integrity": "sha512-aYX01Ke9hunpoCexYAgQucEpARGQ5w/cqHFrIR+e9gdKb1QWTsVJuTJ2ozQzIAxLyRQe/m+2RqzkyOOGiMKRQA==", - "dev": true, + "devOptional": true, "dependencies": { "tslib": "^2.4.0" } @@ -7371,7 +7522,7 @@ "version": "0.1.5", "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.5.tgz", "integrity": "sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==", - "dev": true + "devOptional": true }, "node_modules/@tootallnate/once": { "version": "2.0.0", diff --git a/package.json b/package.json index bfd4336f..03ea7336 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "version": "0.0.0", "license": "MIT", "scripts": { - "typeorm": "ts-node -r tsconfig-paths/register --project libs/database/tsconfig.lib.json ./node_modules/typeorm/cli.js -d libs/database/src/lib/config-cli.ts", + "typeorm": "ts-node -r tsconfig-paths/register -r dotenv/config --project libs/database/tsconfig.lib.json ./node_modules/typeorm/cli.js -d libs/database/src/lib/config-cli.ts", "typeorm:run": "npm run typeorm migration:run", "typeorm:revert": "npm run typeorm migration:revert", - "seed:run": "ts-node -r tsconfig-paths/register --project libs/database/tsconfig.lib.json ./node_modules/@jorgebodega/typeorm-seeding/dist/cli.js -d libs/database/src/lib/config-cli.ts seed libs/database/src/lib/seeders/root.seeder.ts", + "seed:run": "ts-node -r tsconfig-paths/register -r dotenv/config --project libs/database/tsconfig.lib.json ./node_modules/@jorgebodega/typeorm-seeding/dist/cli.js -d libs/database/src/lib/config-cli.ts seed libs/database/src/lib/seeders/root.seeder.ts", "demo:json-api": "nx run json-api-server:serve:development" }, "private": true, @@ -50,6 +50,8 @@ "@angular/compiler-cli": "17.2.2", "@angular/language-service": "17.2.2", "@faker-js/faker": "^8.4.1", + "@jorgebodega/typeorm-factory": "^1.4.0", + "@jorgebodega/typeorm-seeding": "^6.0.1", "@nestjs/schematics": "^10.0.1", "@nestjs/testing": "^10.0.2", "@nx/angular": "18.0.7", @@ -92,4 +94,3 @@ "webpack-cli": "^5.1.4" } } - diff --git a/tools/scripts/prepare-for-angular.mjs b/tools/scripts/prepare-for-angular.mjs index 01226937..651af416 100644 --- a/tools/scripts/prepare-for-angular.mjs +++ b/tools/scripts/prepare-for-angular.mjs @@ -14,6 +14,7 @@ writeFileSync( promisify(exec)( `nx run json-api-nestjs-sdk:compile-for-angular` ).then(r => { + console.log(r) writeFileSync(LIB_ANGULAR_MODULE_PATH, readFileSync(ANGULAR_MODULE_PATH)) }).finally(() => { unlinkSync(TEMP_FILE_PATH)