From fec4cae71e5afee1235d49537a563f489c091ddf Mon Sep 17 00:00:00 2001 From: AmauryD Date: Sun, 12 Nov 2023 21:50:53 +0100 Subject: [PATCH] folder-by-feature and up deps --- config/orm.config.ts | 4 +- package.json | 8 +- pnpm-lock.yaml | 163 +++--------------- src/application.ts | 20 +-- src/{api => }/areas/main.area.ts | 6 +- src/database/configuration.ts | 4 +- src/database/connection.ts | 6 +- .../seeders/development/development.seeder.ts | 8 +- src/database/seeders/test/seed.ts | 4 +- src/database/seeders/test/test.seeder.ts | 8 +- .../decorators/current-user.decorator.ts | 2 +- src/{api => }/decorators/json-api-body.ts | 0 src/{api => }/decorators/json-api-query.ts | 0 src/{api => }/decorators/validated-body.ts | 0 .../decorators/validated-file-body.ts | 0 src/{api => }/decorators/validated-params.ts | 0 src/{api => }/decorators/validated-query.ts | 0 .../error-handler/default.error-handler.ts | 4 +- src/{api/errors/web => errors}/bad-request.ts | 0 .../errors/configuration-not-loaded.ts | 0 src/{api/errors/web => errors}/forbidden.ts | 0 src/{api/errors/web => errors}/not-found.ts | 0 .../web => errors}/payload-too-large.ts | 0 .../web => errors}/too-many-requests.ts | 0 src/{api/errors/web => errors}/web-error.ts | 0 .../auth}/controllers/auth.controller.ts | 16 +- .../auth/errors}/invalid-bearer-token.ts | 2 +- .../auth/errors}/invalid-refresh-token.ts | 2 +- .../errors}/invalid-username-or-password.ts | 2 +- .../auth}/models/refresh-token.model.ts | 4 +- .../repositories/refresh-token.repository.ts | 2 +- .../auth}/services/auth.service.ts | 12 +- .../auth}/validators/auth.validator.ts | 0 .../common}/models/base.model.ts | 0 .../common}/resources/base/authorizer.ts | 2 +- .../common}/resources/base/controller.ts | 2 +- .../common}/resources/base/service.ts | 0 .../controllers/documents.controller.ts | 18 +- .../users}/controllers/users.controller.ts | 10 +- .../users}/enums/mime-type.enum.ts | 0 .../users}/enums/roles.enum.ts | 0 .../users/errors}/user-not-found.ts | 2 +- .../users}/factories/document.factory.ts | 2 +- .../users}/factories/refresh-token.factory.ts | 2 +- .../users}/factories/user.factory.ts | 0 .../users}/models/document.model.ts | 4 +- .../users}/models/user.model.ts | 6 +- .../users}/resources/documents/authorizer.ts | 6 +- .../resources/documents/deserializer.ts | 0 .../users}/resources/documents/register.ts | 0 .../users}/resources/documents/schema.ts | 2 +- .../users}/resources/documents/serializer.ts | 0 .../users}/resources/documents/service.ts | 8 +- .../users}/resources/registry.ts | 0 .../users}/resources/user/authorizer.ts | 4 +- .../users}/resources/user/deserializer.ts | 0 .../users}/resources/user/register.ts | 0 .../users}/resources/user/schema.ts | 0 .../users}/resources/user/serializer.ts | 0 .../users}/resources/user/service.ts | 8 +- .../users}/services/user.service.ts | 8 +- .../users}/validators/document.validator.ts | 0 .../users}/validators/user.validator.ts | 0 src/{api => }/guards/authorize.guard.ts | 2 +- .../middlewares/current-user.middleware.ts | 2 +- .../middlewares/file-upload.middleware.ts | 2 +- src/{api => }/middlewares/log.middleware.ts | 2 +- .../middlewares/rate-limit.middleware.ts | 2 +- .../services/configuration.service.ts | 0 src/{api => }/services/logger.service.ts | 0 src/{api => }/utils/can-or-fail.ts | 6 +- src/{api => }/utils/date.ts | 0 .../utils/json-api-query-to-find-options.ts | 0 src/{api => }/utils/offset-from-page.ts | 0 .../query/json-api-query-to-find-options.ts | 0 src/{api => }/utils/query/sort-transformer.ts | 0 .../utils/query/transform-includes-query.ts | 0 src/{api => }/validators/query.validator.ts | 0 tests/mocks/authorizer.ts | 2 +- tests/mocks/resource-service.ts | 2 +- tests/src/acceptance/application.test.ts | 4 +- tests/src/acceptance/controllers/auth.test.ts | 4 +- .../acceptance/controllers/documents.test.ts | 8 +- .../src/acceptance/controllers/users.test.ts | 4 +- .../integration/controllers/auth/auth.test.ts | 10 +- .../src/integration/controllers/auth/seed.ts | 10 +- .../controllers/documents/documents.test.ts | 10 +- .../src/integration/controllers/users/seed.ts | 8 +- .../controllers/users/users.test.ts | 6 +- .../resources/deserializer.test.ts | 4 +- tests/src/unit/authorizer/document.test.ts | 8 +- tests/src/unit/authorizer/user.test.ts | 6 +- tests/src/unit/controllers/auth.test.ts | 2 +- tests/src/unit/controllers/documents.test.ts | 22 +-- tests/src/unit/controllers/users.test.ts | 20 ++- tests/src/unit/error-handlers/default.test.ts | 4 +- tests/src/unit/guards/authorize.test.ts | 4 +- .../src/unit/middlewares/current-user.test.ts | 2 +- .../file-upload-middleware.test.ts | 4 +- tests/src/unit/middlewares/log.test.ts | 4 +- tests/src/unit/middlewares/rate-limit.test.ts | 2 +- .../unit/resources/document/service.test.ts | 6 +- tests/src/unit/resources/user/service.test.ts | 6 +- tests/src/unit/services/auth.test.ts | 2 +- tests/src/unit/services/configuration.test.ts | 6 +- tests/src/unit/services/logger.test.ts | 4 +- tests/src/unit/services/user.test.ts | 6 +- tests/src/unit/utils/date.test.ts | 2 +- .../json-api-query-to-find-options.test.ts | 2 +- tests/utils/setup-acceptance-test.ts | 6 +- tsconfig.json | 9 +- vitest.workspace.ts | 11 +- 112 files changed, 232 insertions(+), 355 deletions(-) rename src/{api => }/areas/main.area.ts (55%) rename src/{api => }/decorators/current-user.decorator.ts (89%) rename src/{api => }/decorators/json-api-body.ts (100%) rename src/{api => }/decorators/json-api-query.ts (100%) rename src/{api => }/decorators/validated-body.ts (100%) rename src/{api => }/decorators/validated-file-body.ts (100%) rename src/{api => }/decorators/validated-params.ts (100%) rename src/{api => }/decorators/validated-query.ts (100%) rename src/{api => }/error-handler/default.error-handler.ts (95%) rename src/{api/errors/web => errors}/bad-request.ts (100%) rename src/{api => }/errors/configuration-not-loaded.ts (100%) rename src/{api/errors/web => errors}/forbidden.ts (100%) rename src/{api/errors/web => errors}/not-found.ts (100%) rename src/{api/errors/web => errors}/payload-too-large.ts (100%) rename src/{api/errors/web => errors}/too-many-requests.ts (100%) rename src/{api/errors/web => errors}/web-error.ts (100%) rename src/{api => features/auth}/controllers/auth.controller.ts (81%) rename src/{api/errors/web => features/auth/errors}/invalid-bearer-token.ts (56%) rename src/{api/errors/web => features/auth/errors}/invalid-refresh-token.ts (57%) rename src/{api/errors/web => features/auth/errors}/invalid-username-or-password.ts (58%) rename src/{database => features/auth}/models/refresh-token.model.ts (81%) rename src/{database => features/auth}/repositories/refresh-token.repository.ts (91%) rename src/{api => features/auth}/services/auth.service.ts (73%) rename src/{api => features/auth}/validators/auth.validator.ts (100%) rename src/{database => features/common}/models/base.model.ts (100%) rename src/{api => features/common}/resources/base/authorizer.ts (81%) rename src/{api => features/common}/resources/base/controller.ts (85%) rename src/{api => features/common}/resources/base/service.ts (100%) rename src/{api => features/users}/controllers/documents.controller.ts (84%) rename src/{api => features/users}/controllers/users.controller.ts (90%) rename src/{api => features/users}/enums/mime-type.enum.ts (100%) rename src/{api => features/users}/enums/roles.enum.ts (100%) rename src/{api/errors/web => features/users/errors}/user-not-found.ts (54%) rename src/{database => features/users}/factories/document.factory.ts (86%) rename src/{database => features/users}/factories/refresh-token.factory.ts (77%) rename src/{database => features/users}/factories/user.factory.ts (100%) rename src/{database => features/users}/models/document.model.ts (89%) rename src/{database => features/users}/models/user.model.ts (88%) rename src/{api => features/users}/resources/documents/authorizer.ts (82%) rename src/{api => features/users}/resources/documents/deserializer.ts (100%) rename src/{api => features/users}/resources/documents/register.ts (100%) rename src/{api => features/users}/resources/documents/schema.ts (94%) rename src/{api => features/users}/resources/documents/serializer.ts (100%) rename src/{api => features/users}/resources/documents/service.ts (86%) rename src/{api => features/users}/resources/registry.ts (100%) rename src/{api => features/users}/resources/user/authorizer.ts (86%) rename src/{api => features/users}/resources/user/deserializer.ts (100%) rename src/{api => features/users}/resources/user/register.ts (100%) rename src/{api => features/users}/resources/user/schema.ts (100%) rename src/{api => features/users}/resources/user/serializer.ts (100%) rename src/{api => features/users}/resources/user/service.ts (86%) rename src/{api => features/users}/services/user.service.ts (79%) rename src/{api => features/users}/validators/document.validator.ts (100%) rename src/{api => features/users}/validators/user.validator.ts (100%) rename src/{api => }/guards/authorize.guard.ts (87%) rename src/{api => }/middlewares/current-user.middleware.ts (88%) rename src/{api => }/middlewares/file-upload.middleware.ts (94%) rename src/{api => }/middlewares/log.middleware.ts (90%) rename src/{api => }/middlewares/rate-limit.middleware.ts (94%) rename src/{api => }/services/configuration.service.ts (100%) rename src/{api => }/services/logger.service.ts (100%) rename src/{api => }/utils/can-or-fail.ts (63%) rename src/{api => }/utils/date.ts (100%) rename src/{api => }/utils/json-api-query-to-find-options.ts (100%) rename src/{api => }/utils/offset-from-page.ts (100%) rename src/{api => }/utils/query/json-api-query-to-find-options.ts (100%) rename src/{api => }/utils/query/sort-transformer.ts (100%) rename src/{api => }/utils/query/transform-includes-query.ts (100%) rename src/{api => }/validators/query.validator.ts (100%) diff --git a/config/orm.config.ts b/config/orm.config.ts index 58b7847d..7f57dc49 100644 --- a/config/orm.config.ts +++ b/config/orm.config.ts @@ -1,7 +1,7 @@ import { container } from '@triptyk/nfw-core'; -import type { ConfigurationService, Env } from '../src/api/services/configuration.service.js'; import { getConfiguration } from '../src/database/configuration.js'; -import { ConfigurationServiceImpl } from '../src/api/services/configuration.service.js'; +import { ConfigurationServiceImpl } from '../src/services/configuration.service.js'; +import type { ConfigurationService, Env } from '../src/services/configuration.service.js'; const configService = container.resolve>(ConfigurationServiceImpl); configService.load(); diff --git a/package.json b/package.json index 87b8c9cc..84a5d72e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "5.0.0-alpha.1", "description": "![alt text](https://repository-images.githubusercontent.com/166414581/dc0a1b80-a1a0-11e9-805b-cf8be46b5507)", "scripts": { - "test": "node test.js", + "test": "node test.js", "test:acceptance": "vitest -c config/vitest/acceptance.vitest.config.ts", "test:unit": "vitest -c config/vitest/unit.vitest.config.ts", "test:integration": "vitest -c config/vitest/integration.vitest.config.ts", @@ -50,7 +50,6 @@ "koa-helmet": "~7.0.2", "koa-qs": "~3.0.0", "koa-ratelimit": "~5.0.1", - "param-case": "~4.0.0", "pluralize": "~8.0.0", "reflect-metadata": "~0.1.13", "tracer": "~1.3.0", @@ -82,7 +81,7 @@ "eslint": "~8.53.0", "eslint-config-standard": "~17.1.0", "eslint-plugin-import": "~2.29.0", - "eslint-plugin-n": "~16.3.0", + "eslint-plugin-n": "~16.3.1", "eslint-plugin-node": "~11.1.0", "eslint-plugin-promise": "~6.1.1", "eslint-plugin-unused-imports": "~3.0.0", @@ -93,11 +92,8 @@ "nodemon": "~3.0.1", "prettier-eslint": "~16.1.2", "ts-node": "~10.9.1", - "ts-node-dev": "~2.0.0", - "tsconfig-paths": "^4.2.0", "type-fest": "~4.7.1", "vite": "~4.5.0", - "vite-tsconfig-paths": "^4.2.1", "vitest": "~0.34.6" }, "volta": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6fe50a32..8e13fc55 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -59,9 +59,6 @@ dependencies: koa-ratelimit: specifier: ~5.0.1 version: 5.0.1 - param-case: - specifier: ~4.0.0 - version: 4.0.0 pluralize: specifier: ~8.0.0 version: 8.0.0 @@ -144,13 +141,13 @@ devDependencies: version: 8.53.0 eslint-config-standard: specifier: ~17.1.0 - version: 17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.0)(eslint-plugin-promise@6.1.1)(eslint@8.53.0) + version: 17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-promise@6.1.1)(eslint@8.53.0) eslint-plugin-import: specifier: ~2.29.0 version: 2.29.0(@typescript-eslint/parser@6.10.0)(eslint@8.53.0) eslint-plugin-n: - specifier: ~16.3.0 - version: 16.3.0(eslint@8.53.0) + specifier: ~16.3.1 + version: 16.3.1(eslint@8.53.0) eslint-plugin-node: specifier: ~11.1.0 version: 11.1.0(eslint@8.53.0) @@ -181,21 +178,12 @@ devDependencies: ts-node: specifier: ~10.9.1 version: 10.9.1(@types/node@20.9.0)(typescript@5.2.2) - ts-node-dev: - specifier: ~2.0.0 - version: 2.0.0(@types/node@20.9.0)(typescript@5.2.2) - tsconfig-paths: - specifier: ^4.2.0 - version: 4.2.0 type-fest: specifier: ~4.7.1 version: 4.7.1 vite: specifier: ~4.5.0 version: 4.5.0(@types/node@20.9.0) - vite-tsconfig-paths: - specifier: ^4.2.1 - version: 4.2.1(typescript@5.2.2)(vite@4.5.0) vitest: specifier: ~0.34.6 version: 0.34.6(@vitest/ui@0.34.6) @@ -1194,14 +1182,6 @@ packages: '@types/mime': 3.0.4 '@types/node': 20.9.0 - /@types/strip-bom@3.0.0: - resolution: {integrity: sha512-xevGOReSYGM7g/kUBZzPqCrR/KYAo+F0yiPc85WFTJa0MSLtyFTVTU6cJu/aV4mid7IffDIWqo69THF2o4JiEQ==} - dev: true - - /@types/strip-json-comments@0.0.30: - resolution: {integrity: sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==} - dev: true - /@types/uuid@9.0.7: resolution: {integrity: sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==} dev: true @@ -1717,15 +1697,16 @@ packages: resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==} dev: false - /buffer-from@1.1.2: - resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} - dev: true - /buffer-writer@2.0.0: resolution: {integrity: sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==} engines: {node: '>=4'} dev: false + /builtin-modules@3.3.0: + resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} + engines: {node: '>=6'} + dev: true + /builtins@5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: @@ -2132,12 +2113,6 @@ packages: engines: {node: '>=12'} dev: false - /dynamic-dedupe@0.3.0: - resolution: {integrity: sha512-ssuANeD+z97meYOqd50e04Ze5qp4bPqo8cCkI4TRjZkzAUgIDTrXV1R8QCdINpiI+hw14+rYazvTRdQrz0/rFQ==} - dependencies: - xtend: 4.0.2 - dev: true - /ecdsa-sig-formatter@1.0.11: resolution: {integrity: sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==} dependencies: @@ -2284,7 +2259,7 @@ packages: engines: {node: '>=10'} dev: true - /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.0)(eslint-plugin-promise@6.1.1)(eslint@8.53.0): + /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-promise@6.1.1)(eslint@8.53.0): resolution: {integrity: sha512-IwHwmaBNtDK4zDHQukFDW5u/aTb8+meQWZvNFWkiGmbWjD6bqyuSSBxxXKkCftCUzc1zwCH2m/baCNDLGmuO5Q==} engines: {node: '>=12.0.0'} peerDependencies: @@ -2295,7 +2270,7 @@ packages: dependencies: eslint: 8.53.0 eslint-plugin-import: 2.29.0(@typescript-eslint/parser@6.10.0)(eslint@8.53.0) - eslint-plugin-n: 16.3.0(eslint@8.53.0) + eslint-plugin-n: 16.3.1(eslint@8.53.0) eslint-plugin-promise: 6.1.1(eslint@8.53.0) dev: true @@ -2395,8 +2370,8 @@ packages: - supports-color dev: true - /eslint-plugin-n@16.3.0(eslint@8.53.0): - resolution: {integrity: sha512-/XZLH5CUXGK3laz3xYFNza8ZxLCq8ZNW6MsVw5z3d5hc2AwZzi0fPiySFZHQTdVDOHGs2cGv91aqzWmgBdq2gQ==} + /eslint-plugin-n@16.3.1(eslint@8.53.0): + resolution: {integrity: sha512-w46eDIkxQ2FaTHcey7G40eD+FhTXOdKudDXPUO2n9WNcslze/i/HT2qJ3GXjHngYSGDISIgPNhwGtgoix4zeOw==} engines: {node: '>=16.0.0'} peerDependencies: eslint: '>=7.0.0' @@ -2407,6 +2382,7 @@ packages: eslint-plugin-es-x: 7.3.0(eslint@8.53.0) get-tsconfig: 4.7.2 ignore: 5.2.4 + is-builtin-module: 3.2.1 is-core-module: 2.13.1 minimatch: 3.1.2 resolve: 1.22.8 @@ -2894,10 +2870,6 @@ packages: merge2: 1.4.1 slash: 3.0.0 - /globrex@0.1.2: - resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} - dev: true - /gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} dependencies: @@ -3134,6 +3106,13 @@ packages: has-tostringtag: 1.0.0 dev: true + /is-builtin-module@3.2.1: + resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} + engines: {node: '>=6'} + dependencies: + builtin-modules: 3.3.0 + dev: true + /is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} @@ -3356,6 +3335,7 @@ packages: resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==} engines: {node: '>=6'} hasBin: true + dev: false /jsonc-parser@3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} @@ -3754,6 +3734,7 @@ packages: resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==} engines: {node: '>=10'} hasBin: true + dev: false /mlly@1.4.2: resolution: {integrity: sha512-i/Ykufi2t1EZ6NaPLdfnZk2AX8cs0d+mTzVKuPfqPKPatxLApaBoxJQ9x1/uckXtrS/U5oisPMDkNs0yQTaBRg==} @@ -3790,11 +3771,6 @@ packages: engines: {node: '>= 0.6'} dev: false - /no-case@4.0.0: - resolution: {integrity: sha512-WmS3EUGw+vXHlTgiUPi3NzbZNwH6+uGX0QLGgqG+aFSJ5rkX/Ee0nuwHBJfZTfQwwR8lGO819NEIwQ7CGhkdEQ==} - deprecated: Use `change-case` - dev: false - /node-addon-api@5.1.0: resolution: {integrity: sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==} dev: false @@ -3991,13 +3967,6 @@ packages: resolution: {integrity: sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==} dev: false - /param-case@4.0.0: - resolution: {integrity: sha512-+kVIBemYVaPPzBX6Z9FcBvaY0YSIBxD1fyShn6P3HkWOIbsOkT8OmEgLrQSaAHRDyYKdu7YH5RRiACiJLSJ2pw==} - deprecated: Use `change-case` - dependencies: - no-case: 4.0.0 - dev: false - /parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -4472,13 +4441,6 @@ packages: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - /rimraf@2.7.1: - resolution: {integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==} - hasBin: true - dependencies: - glob: 7.2.3 - dev: true - /rimraf@3.0.2: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} hasBin: true @@ -4632,13 +4594,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /source-map-support@0.5.21: - resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} - dependencies: - buffer-from: 1.1.2 - source-map: 0.6.1 - dev: true - /source-map@0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} @@ -4759,11 +4714,6 @@ packages: engines: {node: '>=6'} dev: true - /strip-json-comments@2.0.1: - resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==} - engines: {node: '>=0.10.0'} - dev: true - /strip-json-comments@3.1.1: resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} engines: {node: '>=8'} @@ -4930,34 +4880,6 @@ packages: resolution: {integrity: sha512-oTTXmjSMkCIK8d+uKbQnHh7JS9zEYGn3pq7nE0qHVERq+6Mx9wZKcXVAT+7X0qhOWpRz10dqrJCFFcKwunYz5w==} dev: false - /ts-node-dev@2.0.0(@types/node@20.9.0)(typescript@5.2.2): - resolution: {integrity: sha512-ywMrhCfH6M75yftYvrvNarLEY+SUXtUvU8/0Z6llrHQVBx12GiFk5sStF8UdfE/yfzk9IAq7O5EEbTQsxlBI8w==} - engines: {node: '>=0.8.0'} - hasBin: true - peerDependencies: - node-notifier: '*' - typescript: '*' - peerDependenciesMeta: - node-notifier: - optional: true - dependencies: - chokidar: 3.5.3 - dynamic-dedupe: 0.3.0 - minimist: 1.2.8 - mkdirp: 1.0.4 - resolve: 1.22.2 - rimraf: 2.7.1 - source-map-support: 0.5.21 - tree-kill: 1.2.2 - ts-node: 10.9.1(@types/node@20.9.0)(typescript@5.2.2) - tsconfig: 7.0.0 - typescript: 5.2.2 - transitivePeerDependencies: - - '@swc/core' - - '@swc/wasm' - - '@types/node' - dev: true - /ts-node@10.9.1(@types/node@20.9.0)(typescript@5.2.2): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true @@ -4989,19 +4911,6 @@ packages: yn: 3.1.1 dev: true - /tsconfck@2.1.2(typescript@5.2.2): - resolution: {integrity: sha512-ghqN1b0puy3MhhviwO2kGF8SeMDNhEbnKxjK7h6+fvY9JAxqvXi8y5NAHSQv687OVboS2uZIByzGd45/YxrRHg==} - engines: {node: ^14.13.1 || ^16 || >=18} - hasBin: true - peerDependencies: - typescript: ^4.3.5 || ^5.0.0 - peerDependenciesMeta: - typescript: - optional: true - dependencies: - typescript: 5.2.2 - dev: true - /tsconfig-paths@3.14.2: resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==} dependencies: @@ -5018,15 +4927,7 @@ packages: json5: 2.2.3 minimist: 1.2.8 strip-bom: 3.0.0 - - /tsconfig@7.0.0: - resolution: {integrity: sha512-vZXmzPrL+EmC4T/4rVlT2jNVMWCi/O4DIiSj3UHg1OE5kCKbk4mfrXc6dZksLgRM/TZlKnousKH9bbTazUWRRw==} - dependencies: - '@types/strip-bom': 3.0.0 - '@types/strip-json-comments': 0.0.30 - strip-bom: 3.0.0 - strip-json-comments: 2.0.1 - dev: true + dev: false /tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} @@ -5241,23 +5142,6 @@ packages: - terser dev: true - /vite-tsconfig-paths@4.2.1(typescript@5.2.2)(vite@4.5.0): - resolution: {integrity: sha512-GNUI6ZgPqT3oervkvzU+qtys83+75N/OuDaQl7HmOqFTb0pjZsuARrRipsyJhJ3enqV8beI1xhGbToR4o78nSQ==} - peerDependencies: - vite: '*' - peerDependenciesMeta: - vite: - optional: true - dependencies: - debug: 4.3.4 - globrex: 0.1.2 - tsconfck: 2.1.2(typescript@5.2.2) - vite: 4.5.0(@types/node@20.9.0) - transitivePeerDependencies: - - supports-color - - typescript - dev: true - /vite@4.5.0(@types/node@20.9.0): resolution: {integrity: sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==} engines: {node: ^14.18.0 || >=16.0.0} @@ -5467,6 +5351,7 @@ packages: /xtend@4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} + dev: false /y18n@5.0.8: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} diff --git a/src/application.ts b/src/application.ts index 57e456b7..0e1bf667 100644 --- a/src/application.ts +++ b/src/application.ts @@ -1,25 +1,25 @@ /* eslint-disable import/first */ import 'reflect-metadata'; import { container, inject, singleton } from '@triptyk/nfw-core'; -import { ConfigurationServiceImpl } from './api/services/configuration.service.js'; +import { ConfigurationServiceImpl } from './services/configuration.service.js'; import KoaQS from 'koa-qs'; import Koa from 'koa'; -import { MainArea } from './api/areas/main.area.js'; +import { MainArea } from './areas/main.area.js'; import helmet from 'koa-helmet'; import cors from '@koa/cors'; import { koaBody } from 'koa-body'; import { requestContext } from '@triptyk/nfw-mikro-orm'; import { createApplication, resolveMiddlewareInstance } from '@triptyk/nfw-http'; import type { Server } from 'http'; -import { LoggerServiceImpl } from './api/services/logger.service.js'; -import type { LoggerService } from './api/services/logger.service.js'; +import { LoggerServiceImpl } from './services/logger.service.js'; +import type { LoggerService } from './services/logger.service.js'; import { DatabaseConnectionImpl } from './database/connection.js'; -import { LogMiddleware } from './api/middlewares/log.middleware.js'; -import { DefaultErrorHandler } from './api/error-handler/default.error-handler.js'; -import { createRateLimitMiddleware } from './api/middlewares/rate-limit.middleware.js'; -import { BadRequestError } from './api/errors/web/bad-request.js'; -import { PayloadTooLargeError } from './api/errors/web/payload-too-large.js'; -import { setupRegistry } from './api/resources/registry.js'; +import { LogMiddleware } from './middlewares/log.middleware.js'; +import { DefaultErrorHandler } from './error-handler/default.error-handler.js'; +import { createRateLimitMiddleware } from './middlewares/rate-limit.middleware.js'; +import { BadRequestError } from './errors/bad-request.js'; +import { PayloadTooLargeError } from './errors/payload-too-large.js'; +import { setupRegistry } from './features/users/resources/registry.js'; import { ResourcesRegistryImpl } from '@triptyk/nfw-resources'; @singleton() diff --git a/src/api/areas/main.area.ts b/src/areas/main.area.ts similarity index 55% rename from src/api/areas/main.area.ts rename to src/areas/main.area.ts index b01f4a7a..ca364037 100644 --- a/src/api/areas/main.area.ts +++ b/src/areas/main.area.ts @@ -1,7 +1,7 @@ import { Controller, UseMiddleware } from '@triptyk/nfw-http'; -import { AuthController } from '../controllers/auth.controller.js'; -import { DocumentsController } from '../controllers/documents.controller.js'; -import { UsersController } from '../controllers/users.controller.js'; +import { AuthController } from '../features/auth/controllers/auth.controller.js'; +import { DocumentsController } from '../features/users/controllers/documents.controller.js'; +import { UsersController } from '../features/users/controllers/users.controller.js'; import { CurrentUserMiddleware } from '../middlewares/current-user.middleware.js'; @Controller({ diff --git a/src/database/configuration.ts b/src/database/configuration.ts index 0f345d07..13c441db 100644 --- a/src/database/configuration.ts +++ b/src/database/configuration.ts @@ -1,5 +1,5 @@ import type { Options } from '@mikro-orm/core'; -import type { ConfigurationService, Env } from '../api/services/configuration.service.js'; +import type { ConfigurationService, Env } from '../services/configuration.service.js'; export function getConfiguration (configurationService: ConfigurationService) { return { @@ -11,7 +11,7 @@ export function getConfiguration (configurationService: ConfigurationService import(id), dbName: configurationService.get('DATABASE_NAME'), host: configurationService.get('DATABASE_HOST'), diff --git a/src/database/connection.ts b/src/database/connection.ts index 83a36b5f..8f274804 100644 --- a/src/database/connection.ts +++ b/src/database/connection.ts @@ -3,9 +3,9 @@ import { LoadStrategy } from '@mikro-orm/core'; import { inject, singleton } from '@triptyk/nfw-core'; import { init } from '@triptyk/nfw-mikro-orm'; import type { Promisable } from 'type-fest'; -import { NotFoundError } from '../api/errors/web/not-found.js'; -import type { ConfigurationService, Env } from '../api/services/configuration.service.js'; -import { ConfigurationServiceImpl } from '../api/services/configuration.service.js'; +import { NotFoundError } from '../errors/not-found.js'; +import type { ConfigurationService, Env } from '../services/configuration.service.js'; +import { ConfigurationServiceImpl } from '../services/configuration.service.js'; import { getConfiguration } from './configuration.js'; export interface DatabaseConnection { diff --git a/src/database/seeders/development/development.seeder.ts b/src/database/seeders/development/development.seeder.ts index 6eb01332..1a39d556 100644 --- a/src/database/seeders/development/development.seeder.ts +++ b/src/database/seeders/development/development.seeder.ts @@ -1,10 +1,10 @@ import type { Collection, EntityManager } from '@mikro-orm/core'; import { Seeder } from '@mikro-orm/seeder'; import { writeFile, mkdir } from 'fs/promises'; -import { Roles } from '../../../api/enums/roles.enum.js'; -import type { DocumentModel } from '../../models/document.model.js'; -import { DocumentFactory } from '../../factories/document.factory.js'; -import { UserFactory } from '../../factories/user.factory.js'; +import { Roles } from '../../../features/users/enums/roles.enum.js'; +import type { DocumentModel } from '../../../features/users/models/document.model.js'; +import { DocumentFactory } from '../../../features/users/factories/document.factory.js'; +import { UserFactory } from '../../../features/users/factories/user.factory.js'; /** * This is the default seeder for this environment diff --git a/src/database/seeders/test/seed.ts b/src/database/seeders/test/seed.ts index 7f922a98..3e1e6f0e 100644 --- a/src/database/seeders/test/seed.ts +++ b/src/database/seeders/test/seed.ts @@ -1,7 +1,7 @@ import type { EntityManager } from '@mikro-orm/core'; import { Seeder } from '@mikro-orm/seeder'; -import { MimeTypes } from '../../../api/enums/mime-type.enum.js'; -import { DocumentFactory } from '../../factories/document.factory.js'; +import { MimeTypes } from '../../../features/users/enums/mime-type.enum.js'; +import { DocumentFactory } from '../../../features/users/factories/document.factory.js'; export const dummyDocument = { id: 'document', diff --git a/src/database/seeders/test/test.seeder.ts b/src/database/seeders/test/test.seeder.ts index 0e45cd17..a14b63f2 100644 --- a/src/database/seeders/test/test.seeder.ts +++ b/src/database/seeders/test/test.seeder.ts @@ -1,9 +1,9 @@ import type { EntityManager } from '@mikro-orm/core'; import { Seeder } from '@mikro-orm/seeder'; -import { Roles } from '../../../api/enums/roles.enum.js'; -import { DocumentFactory } from '../../factories/document.factory.js'; -import { UserFactory } from '../../factories/user.factory.js'; -import { RefreshTokenFactory } from '../../factories/refresh-token.factory.js'; +import { Roles } from '../../../features/users/enums/roles.enum.js'; +import { DocumentFactory } from '../../../features/users/factories/document.factory.js'; +import { UserFactory } from '../../../features/users/factories/user.factory.js'; +import { RefreshTokenFactory } from '../../../features/users/factories/refresh-token.factory.js'; import { DocumentsControllerTestSeeder } from './seed.js'; /** diff --git a/src/api/decorators/current-user.decorator.ts b/src/decorators/current-user.decorator.ts similarity index 89% rename from src/api/decorators/current-user.decorator.ts rename to src/decorators/current-user.decorator.ts index 6cfde20a..bca88ef0 100644 --- a/src/api/decorators/current-user.decorator.ts +++ b/src/decorators/current-user.decorator.ts @@ -1,7 +1,7 @@ import { inject, injectable } from '@triptyk/nfw-core'; import type { ControllerParamsContext, ParamInterface } from '@triptyk/nfw-http'; import { createCustomDecorator } from '@triptyk/nfw-http'; -import { UserService } from '../services/user.service.js'; +import { UserService } from '../features/users/services/user.service.js'; @injectable() class CurrentUserParam implements ParamInterface { diff --git a/src/api/decorators/json-api-body.ts b/src/decorators/json-api-body.ts similarity index 100% rename from src/api/decorators/json-api-body.ts rename to src/decorators/json-api-body.ts diff --git a/src/api/decorators/json-api-query.ts b/src/decorators/json-api-query.ts similarity index 100% rename from src/api/decorators/json-api-query.ts rename to src/decorators/json-api-query.ts diff --git a/src/api/decorators/validated-body.ts b/src/decorators/validated-body.ts similarity index 100% rename from src/api/decorators/validated-body.ts rename to src/decorators/validated-body.ts diff --git a/src/api/decorators/validated-file-body.ts b/src/decorators/validated-file-body.ts similarity index 100% rename from src/api/decorators/validated-file-body.ts rename to src/decorators/validated-file-body.ts diff --git a/src/api/decorators/validated-params.ts b/src/decorators/validated-params.ts similarity index 100% rename from src/api/decorators/validated-params.ts rename to src/decorators/validated-params.ts diff --git a/src/api/decorators/validated-query.ts b/src/decorators/validated-query.ts similarity index 100% rename from src/api/decorators/validated-query.ts rename to src/decorators/validated-query.ts diff --git a/src/api/error-handler/default.error-handler.ts b/src/error-handler/default.error-handler.ts similarity index 95% rename from src/api/error-handler/default.error-handler.ts rename to src/error-handler/default.error-handler.ts index 417cf044..83532a62 100644 --- a/src/api/error-handler/default.error-handler.ts +++ b/src/error-handler/default.error-handler.ts @@ -3,8 +3,8 @@ import { inject, injectable } from '@triptyk/nfw-core'; import type { MiddlewareInterface } from '@triptyk/nfw-http'; import type { Next } from 'koa'; import { ValidationError } from 'yup'; -import { NotFoundError } from '../errors/web/not-found.js'; -import { WebError } from '../errors/web/web-error.js'; +import { NotFoundError } from '../errors/not-found.js'; +import { WebError } from '../errors/web-error.js'; import type { ConfigurationService, Env } from '../services/configuration.service.js'; import { ConfigurationServiceImpl } from '../services/configuration.service.js'; import { LoggerServiceImpl } from '../services/logger.service.js'; diff --git a/src/api/errors/web/bad-request.ts b/src/errors/bad-request.ts similarity index 100% rename from src/api/errors/web/bad-request.ts rename to src/errors/bad-request.ts diff --git a/src/api/errors/configuration-not-loaded.ts b/src/errors/configuration-not-loaded.ts similarity index 100% rename from src/api/errors/configuration-not-loaded.ts rename to src/errors/configuration-not-loaded.ts diff --git a/src/api/errors/web/forbidden.ts b/src/errors/forbidden.ts similarity index 100% rename from src/api/errors/web/forbidden.ts rename to src/errors/forbidden.ts diff --git a/src/api/errors/web/not-found.ts b/src/errors/not-found.ts similarity index 100% rename from src/api/errors/web/not-found.ts rename to src/errors/not-found.ts diff --git a/src/api/errors/web/payload-too-large.ts b/src/errors/payload-too-large.ts similarity index 100% rename from src/api/errors/web/payload-too-large.ts rename to src/errors/payload-too-large.ts diff --git a/src/api/errors/web/too-many-requests.ts b/src/errors/too-many-requests.ts similarity index 100% rename from src/api/errors/web/too-many-requests.ts rename to src/errors/too-many-requests.ts diff --git a/src/api/errors/web/web-error.ts b/src/errors/web-error.ts similarity index 100% rename from src/api/errors/web/web-error.ts rename to src/errors/web-error.ts diff --git a/src/api/controllers/auth.controller.ts b/src/features/auth/controllers/auth.controller.ts similarity index 81% rename from src/api/controllers/auth.controller.ts rename to src/features/auth/controllers/auth.controller.ts index 9c7fa6b9..e4677895 100644 --- a/src/api/controllers/auth.controller.ts +++ b/src/features/auth/controllers/auth.controller.ts @@ -1,19 +1,19 @@ import { inject } from '@triptyk/nfw-core'; -import { UserModel } from '../../database/models/user.model.js'; -import { RefreshTokenModel } from '../../database/models/refresh-token.model.js'; -import { RefreshTokenRepository } from '../../database/repositories/refresh-token.repository.js'; -import { ValidatedBody } from '../decorators/validated-body.js'; -import { Roles } from '../enums/roles.enum.js'; +import { UserModel } from '../../users/models/user.model.js'; +import { RefreshTokenModel } from '../models/refresh-token.model.js'; +import { RefreshTokenRepository } from '../repositories/refresh-token.repository.js'; +import { ValidatedBody } from '../../../decorators/validated-body.js'; +import { Roles } from '../../users/enums/roles.enum.js'; import type { RouterContext } from '@koa/router'; import { injectRepository } from '@triptyk/nfw-mikro-orm'; import { Controller, Ctx, POST, UseMiddleware } from '@triptyk/nfw-http'; import { AuthService } from '../services/auth.service.js'; import { EntityRepository } from '@mikro-orm/postgresql'; -import { InvalidUserNameOrPasswordError } from '../errors/web/invalid-username-or-password.js'; -import { InvalidRefreshTokenError } from '../errors/web/invalid-refresh-token.js'; +import { InvalidUserNameOrPasswordError } from '../errors/invalid-username-or-password.js'; +import { InvalidRefreshTokenError } from '../errors/invalid-refresh-token.js'; import { loginBodySchema, refreshBodySchema, registeredUserBodySchema } from '../validators/auth.validator.js'; import type { InferType } from 'yup'; -import { createRateLimitMiddleware } from '../middlewares/rate-limit.middleware.js'; +import { createRateLimitMiddleware } from '../../../middlewares/rate-limit.middleware.js'; @Controller({ routeName: '/auth', diff --git a/src/api/errors/web/invalid-bearer-token.ts b/src/features/auth/errors/invalid-bearer-token.ts similarity index 56% rename from src/api/errors/web/invalid-bearer-token.ts rename to src/features/auth/errors/invalid-bearer-token.ts index e41c7437..283cee08 100644 --- a/src/api/errors/web/invalid-bearer-token.ts +++ b/src/features/auth/errors/invalid-bearer-token.ts @@ -1,4 +1,4 @@ -import { WebError } from './web-error.js'; +import { WebError } from '../../../errors/web-error.js'; export class InvalidBearerTokenError extends WebError { status = 417; diff --git a/src/api/errors/web/invalid-refresh-token.ts b/src/features/auth/errors/invalid-refresh-token.ts similarity index 57% rename from src/api/errors/web/invalid-refresh-token.ts rename to src/features/auth/errors/invalid-refresh-token.ts index 3c842d6c..77e7fe40 100644 --- a/src/api/errors/web/invalid-refresh-token.ts +++ b/src/features/auth/errors/invalid-refresh-token.ts @@ -1,4 +1,4 @@ -import { WebError } from './web-error.js'; +import { WebError } from '../../../errors/web-error.js'; export class InvalidRefreshTokenError extends WebError { status = 417; diff --git a/src/api/errors/web/invalid-username-or-password.ts b/src/features/auth/errors/invalid-username-or-password.ts similarity index 58% rename from src/api/errors/web/invalid-username-or-password.ts rename to src/features/auth/errors/invalid-username-or-password.ts index e77cbe07..b87aeaed 100644 --- a/src/api/errors/web/invalid-username-or-password.ts +++ b/src/features/auth/errors/invalid-username-or-password.ts @@ -1,4 +1,4 @@ -import { WebError } from './web-error.js'; +import { WebError } from '../../../errors/web-error.js'; export class InvalidUserNameOrPasswordError extends WebError { status = 417; diff --git a/src/database/models/refresh-token.model.ts b/src/features/auth/models/refresh-token.model.ts similarity index 81% rename from src/database/models/refresh-token.model.ts rename to src/features/auth/models/refresh-token.model.ts index 8a11a602..9b09c712 100644 --- a/src/database/models/refresh-token.model.ts +++ b/src/features/auth/models/refresh-token.model.ts @@ -1,8 +1,8 @@ import { types, Entity, Property, OneToOne } from '@mikro-orm/core'; import type { Ref } from '@mikro-orm/core'; import { RefreshTokenRepository } from '../repositories/refresh-token.repository.js'; -import { BaseModel } from './base.model.js'; -import type { UserModel } from './user.model.js'; +import { BaseModel } from '../../common/models/base.model.js'; +import type { UserModel } from '../../users/models/user.model.js'; @Entity({ tableName: 'refresh-token', diff --git a/src/database/repositories/refresh-token.repository.ts b/src/features/auth/repositories/refresh-token.repository.ts similarity index 91% rename from src/database/repositories/refresh-token.repository.ts rename to src/features/auth/repositories/refresh-token.repository.ts index c183c1c6..73379530 100644 --- a/src/database/repositories/refresh-token.repository.ts +++ b/src/features/auth/repositories/refresh-token.repository.ts @@ -1,4 +1,4 @@ -import type { UserModel } from '../models/user.model.js'; +import type { UserModel } from '../../users/models/user.model.js'; import { v4 } from 'uuid'; import type { RefreshTokenModel } from '../models/refresh-token.model.js'; import { EntityRepository } from '@mikro-orm/core'; diff --git a/src/api/services/auth.service.ts b/src/features/auth/services/auth.service.ts similarity index 73% rename from src/api/services/auth.service.ts rename to src/features/auth/services/auth.service.ts index 51c0417b..39b574d8 100644 --- a/src/api/services/auth.service.ts +++ b/src/features/auth/services/auth.service.ts @@ -1,13 +1,13 @@ import { inject, injectable, singleton } from '@triptyk/nfw-core'; -import { unixTimestamp } from '../utils/date.js'; +import { unixTimestamp } from '../../../utils/date.js'; import * as Jwt from 'jsonwebtoken'; import { hash } from 'bcrypt'; import { injectRepository } from '@triptyk/nfw-mikro-orm'; -import { RefreshTokenModel } from '../../database/models/refresh-token.model.js'; -import type { UserModel } from '../../database/models/user.model.js'; -import { RefreshTokenRepository } from '../../database/repositories/refresh-token.repository.js'; -import type { ConfigurationService, Env } from './configuration.service.js'; -import { ConfigurationServiceImpl } from './configuration.service.js'; +import { RefreshTokenModel } from '../models/refresh-token.model.js'; +import type { UserModel } from '../../users/models/user.model.js'; +import { RefreshTokenRepository } from '../repositories/refresh-token.repository.js'; +import type { ConfigurationService, Env } from '../../../services/configuration.service.js'; +import { ConfigurationServiceImpl } from '../../../services/configuration.service.js'; @singleton() @injectable() diff --git a/src/api/validators/auth.validator.ts b/src/features/auth/validators/auth.validator.ts similarity index 100% rename from src/api/validators/auth.validator.ts rename to src/features/auth/validators/auth.validator.ts diff --git a/src/database/models/base.model.ts b/src/features/common/models/base.model.ts similarity index 100% rename from src/database/models/base.model.ts rename to src/features/common/models/base.model.ts diff --git a/src/api/resources/base/authorizer.ts b/src/features/common/resources/base/authorizer.ts similarity index 81% rename from src/api/resources/base/authorizer.ts rename to src/features/common/resources/base/authorizer.ts index b85c6f5d..1c96b8d7 100644 --- a/src/api/resources/base/authorizer.ts +++ b/src/features/common/resources/base/authorizer.ts @@ -1,6 +1,6 @@ import type { EntityData } from '@mikro-orm/core'; import type { Promisable } from 'type-fest'; -import type { UserModel } from '../../../database/models/user.model.js'; +import type { UserModel } from '../../../users/models/user.model.js'; export type AuthorizerAction = 'create' | 'update' | 'delete' | 'read'; diff --git a/src/api/resources/base/controller.ts b/src/features/common/resources/base/controller.ts similarity index 85% rename from src/api/resources/base/controller.ts rename to src/features/common/resources/base/controller.ts index 57c4c7d8..6b5f9a9c 100644 --- a/src/api/resources/base/controller.ts +++ b/src/features/common/resources/base/controller.ts @@ -1,6 +1,6 @@ import type { EntityData, RequiredEntityData } from '@mikro-orm/core'; import type { JsonApiQuery, ResourceSerializer } from '@triptyk/nfw-resources'; -import type { UserModel } from '../../../database/models/user.model.js'; +import type { UserModel } from '../../../users/models/user.model.js'; import type { ResourceAuthorizer } from './authorizer.js'; import type { ResourceService } from './service.js'; diff --git a/src/api/resources/base/service.ts b/src/features/common/resources/base/service.ts similarity index 100% rename from src/api/resources/base/service.ts rename to src/features/common/resources/base/service.ts diff --git a/src/api/controllers/documents.controller.ts b/src/features/users/controllers/documents.controller.ts similarity index 84% rename from src/api/controllers/documents.controller.ts rename to src/features/users/controllers/documents.controller.ts index cc14e84e..eb02aa0a 100644 --- a/src/api/controllers/documents.controller.ts +++ b/src/features/users/controllers/documents.controller.ts @@ -2,21 +2,21 @@ import { inject, injectable } from '@triptyk/nfw-core'; import { JsonApiDelete, JsonApiFindAll, JsonApiGet } from '@triptyk/nfw-resources'; import type { JsonApiQuery, ResourceSerializer } from '@triptyk/nfw-resources'; import { Controller, Param, POST, PUT, UseMiddleware } from '@triptyk/nfw-http'; -import { JsonApiQueryDecorator } from '../decorators/json-api-query.js'; -import { CurrentUser } from '../decorators/current-user.decorator.js'; -import { UserModel } from '../../database/models/user.model.js'; +import { JsonApiQueryDecorator } from '../../../decorators/json-api-query.js'; +import { CurrentUser } from '../../../decorators/current-user.decorator.js'; +import { UserModel } from '../models/user.model.js'; import { DocumentResourceServiceImpl } from '../resources/documents/service.js'; import type { DocumentResourceService } from '../resources/documents/service.js'; import { DocumentResourceAuthorizerImpl } from '../resources/documents/authorizer.js'; import { validatedDocumentSchema } from '../validators/document.validator.js'; -import { serializeDocument } from '../../database/models/document.model.js'; -import type { DocumentModel } from '../../database/models/document.model.js'; -import { createFileUploadMiddleware } from '../middlewares/file-upload.middleware.js'; -import { ValidatedFileBody } from '../decorators/validated-file-body.js'; +import { serializeDocument } from '../models/document.model.js'; +import type { DocumentModel } from '../models/document.model.js'; +import { createFileUploadMiddleware } from '../../../middlewares/file-upload.middleware.js'; +import { ValidatedFileBody } from '../../../decorators/validated-file-body.js'; import { DocumentSerializer } from '../resources/documents/serializer.js'; import type { InferType } from 'yup'; -import type { ResourceAuthorizer } from '../resources/base/authorizer.js'; -import { canOrFail } from '../utils/can-or-fail.js'; +import type { ResourceAuthorizer } from '../../common/resources/base/authorizer.js'; +import { canOrFail } from '../../../utils/can-or-fail.js'; const RESOURCE_NAME = 'documents'; diff --git a/src/api/controllers/users.controller.ts b/src/features/users/controllers/users.controller.ts similarity index 90% rename from src/api/controllers/users.controller.ts rename to src/features/users/controllers/users.controller.ts index dcecedf5..63d5d246 100644 --- a/src/api/controllers/users.controller.ts +++ b/src/features/users/controllers/users.controller.ts @@ -8,12 +8,12 @@ import type { UserResourceAuthorizer } from '../resources/user/authorizer.js'; import type { InferType } from 'yup'; import { createUserValidationSchema, updateUserValidationSchema } from '../validators/user.validator.js'; import { Controller, Param } from '@triptyk/nfw-http'; -import { JsonApiQueryDecorator } from '../decorators/json-api-query.js'; -import { CurrentUser } from '../decorators/current-user.decorator.js'; -import { UserModel, serializeUser } from '../../database/models/user.model.js'; -import { JsonApiBody } from '../decorators/json-api-body.js'; +import { JsonApiQueryDecorator } from '../../../decorators/json-api-query.js'; +import { CurrentUser } from '../../../decorators/current-user.decorator.js'; +import { UserModel, serializeUser } from '../models/user.model.js'; +import { JsonApiBody } from '../../../decorators/json-api-body.js'; import { UsersSerializer } from '../resources/user/serializer.js'; -import { canOrFail } from '../utils/can-or-fail.js'; +import { canOrFail } from '../../../utils/can-or-fail.js'; const RESOURCE_NAME = 'users'; diff --git a/src/api/enums/mime-type.enum.ts b/src/features/users/enums/mime-type.enum.ts similarity index 100% rename from src/api/enums/mime-type.enum.ts rename to src/features/users/enums/mime-type.enum.ts diff --git a/src/api/enums/roles.enum.ts b/src/features/users/enums/roles.enum.ts similarity index 100% rename from src/api/enums/roles.enum.ts rename to src/features/users/enums/roles.enum.ts diff --git a/src/api/errors/web/user-not-found.ts b/src/features/users/errors/user-not-found.ts similarity index 54% rename from src/api/errors/web/user-not-found.ts rename to src/features/users/errors/user-not-found.ts index e9c814d2..1863d27d 100644 --- a/src/api/errors/web/user-not-found.ts +++ b/src/features/users/errors/user-not-found.ts @@ -1,4 +1,4 @@ -import { WebError } from './web-error.js'; +import { WebError } from '../../../errors/web-error.js'; export class UserNotFoundError extends WebError { status = 404; diff --git a/src/database/factories/document.factory.ts b/src/features/users/factories/document.factory.ts similarity index 86% rename from src/database/factories/document.factory.ts rename to src/features/users/factories/document.factory.ts index 0b59e1f5..ed8b9d4e 100644 --- a/src/database/factories/document.factory.ts +++ b/src/features/users/factories/document.factory.ts @@ -1,5 +1,5 @@ import { Factory } from '@mikro-orm/seeder'; -import { MimeTypes } from '../../api/enums/mime-type.enum.js'; +import { MimeTypes } from '../enums/mime-type.enum.js'; import { DocumentModel } from '../models/document.model.js'; export class DocumentFactory extends Factory { diff --git a/src/database/factories/refresh-token.factory.ts b/src/features/users/factories/refresh-token.factory.ts similarity index 77% rename from src/database/factories/refresh-token.factory.ts rename to src/features/users/factories/refresh-token.factory.ts index f44c52b8..ee21ab2e 100644 --- a/src/database/factories/refresh-token.factory.ts +++ b/src/features/users/factories/refresh-token.factory.ts @@ -1,5 +1,5 @@ import { Factory } from '@mikro-orm/seeder'; -import { RefreshTokenModel } from '../models/refresh-token.model.js'; +import { RefreshTokenModel } from '../../auth/models/refresh-token.model.js'; export class RefreshTokenFactory extends Factory { model = RefreshTokenModel; diff --git a/src/database/factories/user.factory.ts b/src/features/users/factories/user.factory.ts similarity index 100% rename from src/database/factories/user.factory.ts rename to src/features/users/factories/user.factory.ts diff --git a/src/database/models/document.model.ts b/src/features/users/models/document.model.ts similarity index 89% rename from src/database/models/document.model.ts rename to src/features/users/models/document.model.ts index 365c650a..b88ed8e1 100644 --- a/src/database/models/document.model.ts +++ b/src/features/users/models/document.model.ts @@ -8,10 +8,10 @@ import { types, wrap } from '@mikro-orm/core'; -import { MimeTypes } from '../../api/enums/mime-type.enum.js'; +import { MimeTypes } from '../enums/mime-type.enum.js'; import * as Fs from 'fs/promises'; import type { UserModel } from './user.model.js'; -import { BaseModel } from './base.model.js'; +import { BaseModel } from '../../common/models/base.model.js'; @Entity({ tableName: 'documents' diff --git a/src/database/models/user.model.ts b/src/features/users/models/user.model.ts similarity index 88% rename from src/database/models/user.model.ts rename to src/features/users/models/user.model.ts index 4add0165..ecddc333 100644 --- a/src/database/models/user.model.ts +++ b/src/features/users/models/user.model.ts @@ -12,11 +12,11 @@ import { Filter, wrap } from '@mikro-orm/core'; -import { Roles } from '../../api/enums/roles.enum.js'; -import type { RefreshTokenModel } from './refresh-token.model.js'; +import { Roles } from '../enums/roles.enum.js'; +import type { RefreshTokenModel } from '../../auth/models/refresh-token.model.js'; import bcrypt from 'bcrypt'; import type { DocumentModel } from './document.model.js'; -import { BaseModel } from './base.model.js'; +import { BaseModel } from '../../common/models/base.model.js'; @Entity({ tableName: 'users' diff --git a/src/api/resources/documents/authorizer.ts b/src/features/users/resources/documents/authorizer.ts similarity index 82% rename from src/api/resources/documents/authorizer.ts rename to src/features/users/resources/documents/authorizer.ts index 87f2e4c2..0d985d94 100644 --- a/src/api/resources/documents/authorizer.ts +++ b/src/features/users/resources/documents/authorizer.ts @@ -2,10 +2,10 @@ import { defineAbility, subject } from '@casl/ability'; import type { EntityData } from '@mikro-orm/core'; import { singleton } from '@triptyk/nfw-core'; import type { Promisable } from 'type-fest'; -import type { DocumentModel } from '../../../database/models/document.model.js'; -import type { UserModel } from '../../../database/models/user.model.js'; +import type { DocumentModel } from '../../models/document.model.js'; +import type { UserModel } from '../../models/user.model.js'; import { Roles } from '../../enums/roles.enum.js'; -import type { AuthorizerAction, ResourceAuthorizer } from '../base/authorizer.js'; +import type { AuthorizerAction, ResourceAuthorizer } from '../../../common/resources/base/authorizer.js'; export type DocumentResourceAuthorizer = ResourceAuthorizer; diff --git a/src/api/resources/documents/deserializer.ts b/src/features/users/resources/documents/deserializer.ts similarity index 100% rename from src/api/resources/documents/deserializer.ts rename to src/features/users/resources/documents/deserializer.ts diff --git a/src/api/resources/documents/register.ts b/src/features/users/resources/documents/register.ts similarity index 100% rename from src/api/resources/documents/register.ts rename to src/features/users/resources/documents/register.ts diff --git a/src/api/resources/documents/schema.ts b/src/features/users/resources/documents/schema.ts similarity index 94% rename from src/api/resources/documents/schema.ts rename to src/features/users/resources/documents/schema.ts index 40c6da58..ba889643 100644 --- a/src/api/resources/documents/schema.ts +++ b/src/features/users/resources/documents/schema.ts @@ -1,6 +1,6 @@ import type { ResourceSchema } from '@triptyk/nfw-resources'; import type { UserResource } from '../user/schema.js'; -import type { MimeTypes } from 'app/api/enums/mime-type.enum.js'; +import type { MimeTypes } from '../../enums/mime-type.enum.js'; export type DocumentResource = { filename: string, diff --git a/src/api/resources/documents/serializer.ts b/src/features/users/resources/documents/serializer.ts similarity index 100% rename from src/api/resources/documents/serializer.ts rename to src/features/users/resources/documents/serializer.ts diff --git a/src/api/resources/documents/service.ts b/src/features/users/resources/documents/service.ts similarity index 86% rename from src/api/resources/documents/service.ts rename to src/features/users/resources/documents/service.ts index dab69c42..91f70a2a 100644 --- a/src/api/resources/documents/service.ts +++ b/src/features/users/resources/documents/service.ts @@ -1,12 +1,12 @@ import { wrap, EntityRepository } from '@mikro-orm/core'; import type { Loaded, RequiredEntityData, EntityData } from '@mikro-orm/core'; -import { NotFoundError } from '../../errors/web/not-found.js'; +import { NotFoundError } from '../../../../errors/not-found.js'; import { singleton } from '@triptyk/nfw-core'; import { injectRepository } from '@triptyk/nfw-mikro-orm'; import type { JsonApiQuery } from '@triptyk/nfw-resources'; -import { DocumentModel } from '../../../database/models/document.model.js'; -import { jsonApiQueryToFindOptions } from '../../utils/query/json-api-query-to-find-options.js'; -import type { ResourceService } from '../base/service.js'; +import { DocumentModel } from '../../models/document.model.js'; +import { jsonApiQueryToFindOptions } from '../../../../utils/query/json-api-query-to-find-options.js'; +import type { ResourceService } from '../../../common/resources/base/service.js'; export type DocumentResourceService = ResourceService; diff --git a/src/api/resources/registry.ts b/src/features/users/resources/registry.ts similarity index 100% rename from src/api/resources/registry.ts rename to src/features/users/resources/registry.ts diff --git a/src/api/resources/user/authorizer.ts b/src/features/users/resources/user/authorizer.ts similarity index 86% rename from src/api/resources/user/authorizer.ts rename to src/features/users/resources/user/authorizer.ts index 11dbda05..94d99fbb 100644 --- a/src/api/resources/user/authorizer.ts +++ b/src/features/users/resources/user/authorizer.ts @@ -2,9 +2,9 @@ import { defineAbility, subject } from '@casl/ability'; import type { EntityData } from '@mikro-orm/core'; import { singleton } from '@triptyk/nfw-core'; import type { Promisable } from 'type-fest'; -import type { UserModel } from '../../../database/models/user.model.js'; +import type { UserModel } from '../../models/user.model.js'; import { Roles } from '../../enums/roles.enum.js'; -import type { AuthorizerAction, ResourceAuthorizer } from '../base/authorizer.js'; +import type { AuthorizerAction, ResourceAuthorizer } from '../../../common/resources/base/authorizer.js'; export type UserResourceAuthorizer = ResourceAuthorizer; diff --git a/src/api/resources/user/deserializer.ts b/src/features/users/resources/user/deserializer.ts similarity index 100% rename from src/api/resources/user/deserializer.ts rename to src/features/users/resources/user/deserializer.ts diff --git a/src/api/resources/user/register.ts b/src/features/users/resources/user/register.ts similarity index 100% rename from src/api/resources/user/register.ts rename to src/features/users/resources/user/register.ts diff --git a/src/api/resources/user/schema.ts b/src/features/users/resources/user/schema.ts similarity index 100% rename from src/api/resources/user/schema.ts rename to src/features/users/resources/user/schema.ts diff --git a/src/api/resources/user/serializer.ts b/src/features/users/resources/user/serializer.ts similarity index 100% rename from src/api/resources/user/serializer.ts rename to src/features/users/resources/user/serializer.ts diff --git a/src/api/resources/user/service.ts b/src/features/users/resources/user/service.ts similarity index 86% rename from src/api/resources/user/service.ts rename to src/features/users/resources/user/service.ts index 214c43f4..3401128d 100644 --- a/src/api/resources/user/service.ts +++ b/src/features/users/resources/user/service.ts @@ -3,10 +3,10 @@ import { wrap, EntityRepository } from '@mikro-orm/core'; import { singleton } from '@triptyk/nfw-core'; import { injectRepository } from '@triptyk/nfw-mikro-orm'; import type { JsonApiQuery } from '@triptyk/nfw-resources'; -import { UserModel } from '../../../database/models/user.model.js'; -import { NotFoundError } from '../../errors/web/not-found.js'; -import { jsonApiQueryToFindOptions } from '../../utils/query/json-api-query-to-find-options.js'; -import type { ResourceService } from '../base/service.js'; +import { UserModel } from '../../models/user.model.js'; +import { NotFoundError } from '../../../../errors/not-found.js'; +import { jsonApiQueryToFindOptions } from '../../../../utils/query/json-api-query-to-find-options.js'; +import type { ResourceService } from '../../../common/resources/base/service.js'; export type UserResourceService = ResourceService; diff --git a/src/api/services/user.service.ts b/src/features/users/services/user.service.ts similarity index 79% rename from src/api/services/user.service.ts rename to src/features/users/services/user.service.ts index 02648f9e..0726aec6 100644 --- a/src/api/services/user.service.ts +++ b/src/features/users/services/user.service.ts @@ -1,11 +1,11 @@ import { inject, singleton } from '@triptyk/nfw-core'; import { injectRepository } from '@triptyk/nfw-mikro-orm'; -import { UserModel } from '../../database/models/user.model.js'; +import { UserModel } from '../models/user.model.js'; import * as JWT from 'jsonwebtoken'; -import { InvalidBearerTokenError } from '../errors/web/invalid-bearer-token.js'; +import { InvalidBearerTokenError } from '../../auth/errors/invalid-bearer-token.js'; import { EntityRepository } from '@mikro-orm/postgresql'; -import { ConfigurationServiceImpl } from './configuration.service.js'; -import type { Env, ConfigurationService } from './configuration.service.js'; +import { ConfigurationServiceImpl } from '../../../services/configuration.service.js'; +import type { Env, ConfigurationService } from '../../../services/configuration.service.js'; @singleton() export class UserService { diff --git a/src/api/validators/document.validator.ts b/src/features/users/validators/document.validator.ts similarity index 100% rename from src/api/validators/document.validator.ts rename to src/features/users/validators/document.validator.ts diff --git a/src/api/validators/user.validator.ts b/src/features/users/validators/user.validator.ts similarity index 100% rename from src/api/validators/user.validator.ts rename to src/features/users/validators/user.validator.ts diff --git a/src/api/guards/authorize.guard.ts b/src/guards/authorize.guard.ts similarity index 87% rename from src/api/guards/authorize.guard.ts rename to src/guards/authorize.guard.ts index 5788053e..fb16e5d1 100644 --- a/src/api/guards/authorize.guard.ts +++ b/src/guards/authorize.guard.ts @@ -2,7 +2,7 @@ import { injectable } from '@triptyk/nfw-core'; import type { GuardInterface } from '@triptyk/nfw-http'; import { Args } from '@triptyk/nfw-http'; import { CurrentUser } from '../decorators/current-user.decorator.js'; -import type { UserModel } from '../../database/models/user.model.js'; +import type { UserModel } from '../features/users/models/user.model.js'; @injectable() export class AuthorizeGuard implements GuardInterface { diff --git a/src/api/middlewares/current-user.middleware.ts b/src/middlewares/current-user.middleware.ts similarity index 88% rename from src/api/middlewares/current-user.middleware.ts rename to src/middlewares/current-user.middleware.ts index 30c198ba..81e59ec5 100644 --- a/src/api/middlewares/current-user.middleware.ts +++ b/src/middlewares/current-user.middleware.ts @@ -2,7 +2,7 @@ import type { RouterContext } from '@koa/router'; import type { Next } from 'koa'; import { inject, injectable } from '@triptyk/nfw-core'; import type { MiddlewareInterface } from '@triptyk/nfw-http'; -import { UserService } from '../services/user.service.js'; +import { UserService } from '../features/users/services/user.service.js'; @injectable() export class CurrentUserMiddleware implements MiddlewareInterface { diff --git a/src/api/middlewares/file-upload.middleware.ts b/src/middlewares/file-upload.middleware.ts similarity index 94% rename from src/api/middlewares/file-upload.middleware.ts rename to src/middlewares/file-upload.middleware.ts index 8befa617..504e3796 100644 --- a/src/api/middlewares/file-upload.middleware.ts +++ b/src/middlewares/file-upload.middleware.ts @@ -4,7 +4,7 @@ import type { MiddlewareInterface } from '@triptyk/nfw-http'; import type { Middleware, Next } from 'koa'; import { koaBody } from 'koa-body'; import type { Class } from 'type-fest'; -import { createBadRequestError } from '../errors/web/bad-request.js'; +import { createBadRequestError } from '../errors/bad-request.js'; export function createFileUploadMiddleware (path: string, maxFileSizeInMb: number = 1): Class { @injectable() diff --git a/src/api/middlewares/log.middleware.ts b/src/middlewares/log.middleware.ts similarity index 90% rename from src/api/middlewares/log.middleware.ts rename to src/middlewares/log.middleware.ts index 3a6aa2e2..b338c27f 100644 --- a/src/api/middlewares/log.middleware.ts +++ b/src/middlewares/log.middleware.ts @@ -3,7 +3,7 @@ import { inject, injectable } from '@triptyk/nfw-core'; import { LoggerServiceImpl } from '../services/logger.service.js'; import type { LoggerService } from '../services/logger.service.js'; import type { Next } from 'koa'; -import type { UserModel } from '../../database/models/user.model.js'; +import type { UserModel } from '../features/users/models/user.model.js'; import type { MiddlewareInterface } from '@triptyk/nfw-http'; @injectable() diff --git a/src/api/middlewares/rate-limit.middleware.ts b/src/middlewares/rate-limit.middleware.ts similarity index 94% rename from src/api/middlewares/rate-limit.middleware.ts rename to src/middlewares/rate-limit.middleware.ts index 2cdb30bc..680b0e47 100644 --- a/src/api/middlewares/rate-limit.middleware.ts +++ b/src/middlewares/rate-limit.middleware.ts @@ -3,7 +3,7 @@ import { inject, injectable } from '@triptyk/nfw-core'; import type { MiddlewareInterface } from '@triptyk/nfw-http'; import type { Middleware, Next } from 'koa'; import KoaRatelimit from 'koa-ratelimit'; -import { TooManyRequestsError } from '../errors/web/too-many-requests.js'; +import { TooManyRequestsError } from '../errors/too-many-requests.js'; import type { ConfigurationService, Env } from '../services/configuration.service.js'; import { ConfigurationServiceImpl } from '../services/configuration.service.js'; diff --git a/src/api/services/configuration.service.ts b/src/services/configuration.service.ts similarity index 100% rename from src/api/services/configuration.service.ts rename to src/services/configuration.service.ts diff --git a/src/api/services/logger.service.ts b/src/services/logger.service.ts similarity index 100% rename from src/api/services/logger.service.ts rename to src/services/logger.service.ts diff --git a/src/api/utils/can-or-fail.ts b/src/utils/can-or-fail.ts similarity index 63% rename from src/api/utils/can-or-fail.ts rename to src/utils/can-or-fail.ts index 2d4c794c..096b0440 100644 --- a/src/api/utils/can-or-fail.ts +++ b/src/utils/can-or-fail.ts @@ -1,7 +1,7 @@ import type { EntityData } from '@mikro-orm/core'; -import type { UserModel } from '../../database/models/user.model.js'; -import { ForbiddenError } from '../errors/web/forbidden.js'; -import type { AuthorizerAction, ResourceAuthorizer } from '../resources/base/authorizer.js'; +import type { UserModel } from '../features/users/models/user.model.js'; +import { ForbiddenError } from '../errors/forbidden.js'; +import type { AuthorizerAction, ResourceAuthorizer } from '../features/common/resources/base/authorizer.js'; export async function canOrFail (authorizer: ResourceAuthorizer, actor: UserModel, action: AuthorizerAction, on: EntityData | EntityData[]) { const targets = Array.isArray(on) ? on : [on]; diff --git a/src/api/utils/date.ts b/src/utils/date.ts similarity index 100% rename from src/api/utils/date.ts rename to src/utils/date.ts diff --git a/src/api/utils/json-api-query-to-find-options.ts b/src/utils/json-api-query-to-find-options.ts similarity index 100% rename from src/api/utils/json-api-query-to-find-options.ts rename to src/utils/json-api-query-to-find-options.ts diff --git a/src/api/utils/offset-from-page.ts b/src/utils/offset-from-page.ts similarity index 100% rename from src/api/utils/offset-from-page.ts rename to src/utils/offset-from-page.ts diff --git a/src/api/utils/query/json-api-query-to-find-options.ts b/src/utils/query/json-api-query-to-find-options.ts similarity index 100% rename from src/api/utils/query/json-api-query-to-find-options.ts rename to src/utils/query/json-api-query-to-find-options.ts diff --git a/src/api/utils/query/sort-transformer.ts b/src/utils/query/sort-transformer.ts similarity index 100% rename from src/api/utils/query/sort-transformer.ts rename to src/utils/query/sort-transformer.ts diff --git a/src/api/utils/query/transform-includes-query.ts b/src/utils/query/transform-includes-query.ts similarity index 100% rename from src/api/utils/query/transform-includes-query.ts rename to src/utils/query/transform-includes-query.ts diff --git a/src/api/validators/query.validator.ts b/src/validators/query.validator.ts similarity index 100% rename from src/api/validators/query.validator.ts rename to src/validators/query.validator.ts diff --git a/tests/mocks/authorizer.ts b/tests/mocks/authorizer.ts index 2bee7874..d083968e 100644 --- a/tests/mocks/authorizer.ts +++ b/tests/mocks/authorizer.ts @@ -1,6 +1,6 @@ -import type { ResourceAuthorizer } from 'app/api/resources/base/authorizer.js'; import type { Mock } from 'vitest'; import { vi } from 'vitest'; +import type { ResourceAuthorizer } from '../../src/features/common/resources/base/authorizer.js'; export const mockedAuthorizer = { can: vi.fn() as Mock diff --git a/tests/mocks/resource-service.ts b/tests/mocks/resource-service.ts index 87ed9652..98e2f62c 100644 --- a/tests/mocks/resource-service.ts +++ b/tests/mocks/resource-service.ts @@ -1,6 +1,6 @@ -import type { ResourceService } from 'app/api/resources/base/service.js'; import type { Mock } from 'vitest'; import { vi } from 'vitest'; +import type { ResourceService } from '../../src/features/common/resources/base/service.js'; export const mockedResourceService = { getAll: vi.fn() as Mock, diff --git a/tests/src/acceptance/application.test.ts b/tests/src/acceptance/application.test.ts index 41b97049..225f8623 100644 --- a/tests/src/acceptance/application.test.ts +++ b/tests/src/acceptance/application.test.ts @@ -1,7 +1,7 @@ -import type { Application } from 'app/application.js'; import fetch from 'node-fetch'; -import { teardownAcceptance, setupAcceptance } from 'tests/utils/setup-acceptance-test.js'; import { test, expect, beforeAll, afterAll } from 'vitest'; +import { setupAcceptance, teardownAcceptance } from '../../utils/setup-acceptance-test.js'; +import type { Application } from '../../../src/application.js'; let application: Application; diff --git a/tests/src/acceptance/controllers/auth.test.ts b/tests/src/acceptance/controllers/auth.test.ts index 32aae362..37e79002 100644 --- a/tests/src/acceptance/controllers/auth.test.ts +++ b/tests/src/acceptance/controllers/auth.test.ts @@ -1,7 +1,7 @@ -import type { Application } from 'app/application.js'; -import { teardownAcceptance, setupAcceptance } from 'tests/utils/setup-acceptance-test.js'; import { test, expect, beforeAll, afterAll } from 'vitest'; import { fetchApi } from '../../../utils/config.js'; +import type { Application } from '../../../../src/application.js'; +import { setupAcceptance, teardownAcceptance } from '../../../utils/setup-acceptance-test.js'; const resource = 'auth'; diff --git a/tests/src/acceptance/controllers/documents.test.ts b/tests/src/acceptance/controllers/documents.test.ts index 096bd38d..b992b743 100644 --- a/tests/src/acceptance/controllers/documents.test.ts +++ b/tests/src/acceptance/controllers/documents.test.ts @@ -1,10 +1,10 @@ -import type { Application } from 'app/application.js'; -import { dummyDocument } from 'app/database/seeders/test/seed.js'; -import { createFileWithManyRelationship } from 'tests/utils/create-file-with-relation.js'; -import { teardownAcceptance, setupAcceptance } from 'tests/utils/setup-acceptance-test.js'; import { afterEach, beforeEach, expect, test, vitest } from 'vitest'; import { accessTokenAdmin } from '../../../utils/access-token.js'; import { fetchApi } from '../../../utils/config.js'; +import type { Application } from '../../../../src/application.js'; +import { setupAcceptance, teardownAcceptance } from '../../../utils/setup-acceptance-test.js'; +import { createFileWithManyRelationship } from '../../../utils/create-file-with-relation.js'; +import { dummyDocument } from '../../../../src/database/seeders/test/seed.js'; let application: Application; diff --git a/tests/src/acceptance/controllers/users.test.ts b/tests/src/acceptance/controllers/users.test.ts index c408ce50..f43380b1 100644 --- a/tests/src/acceptance/controllers/users.test.ts +++ b/tests/src/acceptance/controllers/users.test.ts @@ -1,8 +1,8 @@ -import type { Application } from 'app/application.js'; -import { teardownAcceptance, setupAcceptance } from 'tests/utils/setup-acceptance-test.js'; import { afterAll, beforeAll, expect, test } from 'vitest'; import { accessTokenAdmin } from '../../../utils/access-token.js'; import { fetchApi } from '../../../utils/config.js'; +import type { Application } from '../../../../src/application.js'; +import { setupAcceptance, teardownAcceptance } from '../../../utils/setup-acceptance-test.js'; let application: Application; diff --git a/tests/src/integration/controllers/auth/auth.test.ts b/tests/src/integration/controllers/auth/auth.test.ts index 3516afa9..9f64c193 100644 --- a/tests/src/integration/controllers/auth/auth.test.ts +++ b/tests/src/integration/controllers/auth/auth.test.ts @@ -3,12 +3,12 @@ import { container } from '@triptyk/nfw-core'; import { beforeAll, expect } from 'vitest'; import { MikroORM } from '@mikro-orm/core'; -import { testCtx } from 'tests/utils/it-request-context.js'; -import { DatabaseConnectionImpl } from 'app/database/connection.js'; -import { RefreshTokenModel } from 'app/database/models/refresh-token.model.js'; -import { setupIntegrationTest } from 'tests/utils/setup-integration-test.js'; -import { AuthController } from 'app/api/controllers/auth.controller.js'; import { AuthControllerTestSeeder } from './seed.js'; +import { setupIntegrationTest } from '../../../../utils/setup-integration-test.js'; +import { testCtx } from '../../../../utils/it-request-context.js'; +import { AuthController } from '../../../../../src/features/auth/controllers/auth.controller.js'; +import { DatabaseConnectionImpl } from '../../../../../src/database/connection.js'; +import { RefreshTokenModel } from '../../../../../src/features/auth/models/refresh-token.model.js'; beforeAll(async () => { await setupIntegrationTest(AuthControllerTestSeeder); diff --git a/tests/src/integration/controllers/auth/seed.ts b/tests/src/integration/controllers/auth/seed.ts index 25b0d89c..b58bf3eb 100644 --- a/tests/src/integration/controllers/auth/seed.ts +++ b/tests/src/integration/controllers/auth/seed.ts @@ -1,11 +1,11 @@ import type { EntityManager } from '@mikro-orm/core'; import { Seeder } from '@mikro-orm/seeder'; import { container } from '@triptyk/nfw-core'; -import { Roles } from 'app/api/enums/roles.enum.js'; -import { AuthService } from 'app/api/services/auth.service.js'; -import { DocumentFactory } from 'app/database/factories/document.factory.js'; -import { RefreshTokenFactory } from 'app/database/factories/refresh-token.factory.js'; -import { UserFactory } from 'app/database/factories/user.factory.js'; +import { AuthService } from '../../../../../src/features/auth/services/auth.service.js'; +import { Roles } from '../../../../../src/features/users/enums/roles.enum.js'; +import { DocumentFactory } from '../../../../../src/features/users/factories/document.factory.js'; +import { RefreshTokenFactory } from '../../../../../src/features/users/factories/refresh-token.factory.js'; +import { UserFactory } from '../../../../../src/features/users/factories/user.factory.js'; export class AuthControllerTestSeeder extends Seeder { async run (em: EntityManager): Promise { diff --git a/tests/src/integration/controllers/documents/documents.test.ts b/tests/src/integration/controllers/documents/documents.test.ts index 7c39abd7..9f3ab439 100644 --- a/tests/src/integration/controllers/documents/documents.test.ts +++ b/tests/src/integration/controllers/documents/documents.test.ts @@ -1,14 +1,14 @@ import { MikroORM } from '@mikro-orm/core'; import { container } from '@triptyk/nfw-core'; import { afterAll, beforeAll, expect, vi } from 'vitest'; -import { DocumentsController } from 'app/api/controllers/documents.controller.js'; -import { Roles } from 'app/api/enums/roles.enum.js'; -import { UserModel } from 'app/database/models/user.model.js'; import { testCtx } from '../../../../utils/it-request-context.js'; import { setupIntegrationTest } from '../../../../utils/setup-integration-test.js'; import { unlink } from 'fs/promises'; -import { MimeTypes } from 'app/api/enums/mime-type.enum.js'; -import { deleteDummyDocument, DocumentsControllerTestSeeder, dummyDocument } from 'app/database/seeders/test/seed.js'; +import { DocumentsControllerTestSeeder, dummyDocument, deleteDummyDocument } from '../../../../../src/database/seeders/test/seed.js'; +import { DocumentsController } from '../../../../../src/features/users/controllers/documents.controller.js'; +import { MimeTypes } from '../../../../../src/features/users/enums/mime-type.enum.js'; +import { Roles } from '../../../../../src/features/users/enums/roles.enum.js'; +import { UserModel } from '../../../../../src/features/users/models/user.model.js'; let documentsController: DocumentsController; diff --git a/tests/src/integration/controllers/users/seed.ts b/tests/src/integration/controllers/users/seed.ts index ab5ea5c6..9a95f840 100644 --- a/tests/src/integration/controllers/users/seed.ts +++ b/tests/src/integration/controllers/users/seed.ts @@ -1,10 +1,10 @@ import type { EntityManager } from '@mikro-orm/core'; import { Seeder } from '@mikro-orm/seeder'; import { container } from '@triptyk/nfw-core'; -import { Roles } from '../../../../../src/api/enums/roles.enum.js'; -import { AuthService } from '../../../../../src/api/services/auth.service.js'; -import { DocumentFactory } from '../../../../../src/database/factories/document.factory.js'; -import { UserFactory } from '../../../../../src/database/factories/user.factory.js'; +import { Roles } from '../../../../../src/features/users/enums/roles.enum.js'; +import { AuthService } from '../../../../../src/features/auth/services/auth.service.js'; +import { DocumentFactory } from '../../../../../src/features/users/factories/document.factory.js'; +import { UserFactory } from '../../../../../src/features/users/factories/user.factory.js'; /** * This is the default seeder for this environment diff --git a/tests/src/integration/controllers/users/users.test.ts b/tests/src/integration/controllers/users/users.test.ts index 85a39803..2e158503 100644 --- a/tests/src/integration/controllers/users/users.test.ts +++ b/tests/src/integration/controllers/users/users.test.ts @@ -1,9 +1,9 @@ import { MikroORM } from '@mikro-orm/core'; import { container } from '@triptyk/nfw-core'; import { beforeAll, expect } from 'vitest'; -import { UsersController } from '../../../../../src/api/controllers/users.controller.js'; -import { Roles } from '../../../../../src/api/enums/roles.enum.js'; -import { UserModel } from '../../../../../src/database/models/user.model.js'; +import { UsersController } from '../../../../../src/features/users/controllers/users.controller.js'; +import { Roles } from '../../../../../src/features/users/enums/roles.enum.js'; +import { UserModel } from '../../../../../src/features/users/models/user.model.js'; import { testCtx } from '../../../../utils/it-request-context.js'; import { setupIntegrationTest } from '../../../../utils/setup-integration-test.js'; import { UsersControllerTestSeeder } from './seed.js'; diff --git a/tests/src/integration/resources/deserializer.test.ts b/tests/src/integration/resources/deserializer.test.ts index 439bd636..714c4c88 100644 --- a/tests/src/integration/resources/deserializer.test.ts +++ b/tests/src/integration/resources/deserializer.test.ts @@ -3,8 +3,8 @@ import { container } from '@triptyk/nfw-core'; import type { ResourcesRegistry } from '@triptyk/nfw-resources'; import { ResourcesRegistryImpl } from '@triptyk/nfw-resources'; import { beforeEach, expect, test } from 'vitest'; -import { setupRegistry } from 'app/api/resources/registry.js'; -import { UsersDeserializer } from 'app/api/resources/user/deserializer.js'; +import { setupRegistry } from '../../../../src/features/users/resources/registry.js'; +import { UsersDeserializer } from '../../../../src/features/users/resources/user/deserializer.js'; let registry : ResourcesRegistry; diff --git a/tests/src/unit/authorizer/document.test.ts b/tests/src/unit/authorizer/document.test.ts index 1076f402..55748ad0 100644 --- a/tests/src/unit/authorizer/document.test.ts +++ b/tests/src/unit/authorizer/document.test.ts @@ -1,10 +1,10 @@ import type { EntityData } from '@mikro-orm/core'; import 'reflect-metadata'; import { describe, expect, it } from 'vitest'; -import { Roles } from '../../../../src/api/enums/roles.enum.js'; -import { DocumentResourceAuthorizerImpl } from '../../../../src/api/resources/documents/authorizer.js'; -import { DocumentModel } from '../../../../src/database/models/document.model.js'; -import { UserModel } from '../../../../src/database/models/user.model.js'; +import { Roles } from '../../../../src/features/users/enums/roles.enum.js'; +import { DocumentResourceAuthorizerImpl } from '../../../../src/features/users/resources/documents/authorizer.js'; +import { DocumentModel } from '../../../../src/features/users/models/document.model.js'; +import { UserModel } from '../../../../src/features/users/models/user.model.js'; const adminUser = new UserModel(); adminUser.role = Roles.ADMIN; diff --git a/tests/src/unit/authorizer/user.test.ts b/tests/src/unit/authorizer/user.test.ts index 51faf54b..b39010fb 100644 --- a/tests/src/unit/authorizer/user.test.ts +++ b/tests/src/unit/authorizer/user.test.ts @@ -1,8 +1,8 @@ import 'reflect-metadata'; import { expect, test } from 'vitest'; -import { Roles } from 'app/api/enums/roles.enum.js'; -import { UserResourceAuthorizerImpl } from 'app/api/resources/user/authorizer.js'; -import { UserModel } from 'app/database/models/user.model.js'; +import { Roles } from '../../../../src/features/users/enums/roles.enum.js'; +import { UserModel } from '../../../../src/features/users/models/user.model.js'; +import { UserResourceAuthorizerImpl } from '../../../../src/features/users/resources/user/authorizer.js'; const adminUser = new UserModel(); adminUser.role = Roles.ADMIN; diff --git a/tests/src/unit/controllers/auth.test.ts b/tests/src/unit/controllers/auth.test.ts index fbaf875f..a1e5653b 100644 --- a/tests/src/unit/controllers/auth.test.ts +++ b/tests/src/unit/controllers/auth.test.ts @@ -1,6 +1,6 @@ import 'reflect-metadata'; import { expect, test, vi } from 'vitest'; -import { AuthController } from 'app/api/controllers/auth.controller.js'; +import { AuthController } from '../../../../src/features/auth/controllers/auth.controller.js'; const refreshTokenRepositoryMock = { getEntityManager: () => ({ diff --git a/tests/src/unit/controllers/documents.test.ts b/tests/src/unit/controllers/documents.test.ts index 468499c6..69fc1a63 100644 --- a/tests/src/unit/controllers/documents.test.ts +++ b/tests/src/unit/controllers/documents.test.ts @@ -1,14 +1,18 @@ -import { mockedORMImport } from 'tests/mocks/orm-core.js'; +/* eslint-disable import/first */ import 'reflect-metadata'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; -import { DocumentsController } from '../../../../src/api/controllers/documents.controller.js'; -import { ForbiddenError } from '../../../../src/api/errors/web/forbidden.js'; -import { DocumentModel } from '../../../../src/database/models/document.model.js'; -import { UserModel } from '../../../../src/database/models/user.model.js'; +import { mockedORMImport } from '../../../mocks/orm-core.js'; + +vi.mock('@mikro-orm/core', async () => await mockedORMImport()); + +import { DocumentsController } from '../../../../src/features/users/controllers/documents.controller.js'; +import { ForbiddenError } from '../../../../src/errors/forbidden.js'; +import { DocumentModel } from '../../../../src/features/users/models/document.model.js'; +import { UserModel } from '../../../../src/features/users/models/user.model.js'; import { NotFoundError } from '@mikro-orm/core'; -import { mockedResourceService } from 'tests/mocks/resource-service.js'; -import { mockedSerializer } from 'tests/mocks/serializer.js'; -import { mockedAuthorizer } from 'tests/mocks/authorizer.js'; +import { mockedAuthorizer } from '../../../mocks/authorizer.js'; +import { mockedResourceService } from '../../../mocks/resource-service.js'; +import { mockedSerializer } from '../../../mocks/serializer.js'; const service = mockedResourceService; const serializer = mockedSerializer; @@ -28,8 +32,6 @@ afterEach(() => { vi.restoreAllMocks(); }) -vi.mock('@mikro-orm/core', async () => await mockedORMImport()); - const currentUser = new UserModel(); describe('Get', () => { diff --git a/tests/src/unit/controllers/users.test.ts b/tests/src/unit/controllers/users.test.ts index 71777e07..831574d5 100644 --- a/tests/src/unit/controllers/users.test.ts +++ b/tests/src/unit/controllers/users.test.ts @@ -1,12 +1,16 @@ +/* eslint-disable import/first */ import 'reflect-metadata'; -import { mockedORMImport } from 'tests/mocks/orm-core.js'; +import { mockedORMImport } from '../../../mocks/orm-core.js'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; -import { UsersController } from 'app/api/controllers/users.controller.js'; -import { ForbiddenError } from 'app/api/errors/web/forbidden.js'; -import { UserModel } from 'app/database/models/user.model.js'; -import { mockedAuthorizer } from 'tests/mocks/authorizer.js'; -import { mockedResourceService } from 'tests/mocks/resource-service.js'; -import { mockedSerializer } from 'tests/mocks/serializer.js'; + +vi.mock('@mikro-orm/core', async () => await mockedORMImport()); + +import { UsersController } from '../../../../src/features/users/controllers/users.controller.js'; +import { UserModel } from '../../../../src/features/users/models/user.model.js'; +import { mockedAuthorizer } from '../../../mocks/authorizer.js'; +import { mockedResourceService } from '../../../mocks/resource-service.js'; +import { mockedSerializer } from '../../../mocks/serializer.js'; +import { ForbiddenError } from '../../../../src/errors/forbidden.js'; const usersService = mockedResourceService; const serializer = mockedSerializer; @@ -14,8 +18,6 @@ const authorizer = mockedAuthorizer; let controller: UsersController; -vi.mock('@mikro-orm/core', async () => await mockedORMImport()); - beforeEach(() => { controller = new UsersController( usersService, diff --git a/tests/src/unit/error-handlers/default.test.ts b/tests/src/unit/error-handlers/default.test.ts index 950e72dd..8e55d89f 100644 --- a/tests/src/unit/error-handlers/default.test.ts +++ b/tests/src/unit/error-handlers/default.test.ts @@ -1,8 +1,8 @@ import 'reflect-metadata'; import { expect, test, vi } from 'vitest'; import { ValidationError } from 'yup'; -import { DefaultErrorHandler } from '../../../../src/api/error-handler/default.error-handler.js'; -import { WebError } from '../../../../src/api/errors/web/web-error.js'; +import { DefaultErrorHandler } from '../../../../src/error-handler/default.error-handler.js'; +import { WebError } from '../../../../src/errors/web-error.js'; const loggerService = { info: vi.fn(), diff --git a/tests/src/unit/guards/authorize.test.ts b/tests/src/unit/guards/authorize.test.ts index ffb2136c..b811a321 100644 --- a/tests/src/unit/guards/authorize.test.ts +++ b/tests/src/unit/guards/authorize.test.ts @@ -1,7 +1,7 @@ import 'reflect-metadata'; import { beforeEach, expect, test } from 'vitest'; -import { Roles } from '../../../../src/api/enums/roles.enum.js'; -import { AuthorizeGuard } from '../../../../src/api/guards/authorize.guard.js'; +import { Roles } from '../../../../src/features/users/enums/roles.enum.js'; +import { AuthorizeGuard } from '../../../../src/guards/authorize.guard.js'; let guard: AuthorizeGuard; diff --git a/tests/src/unit/middlewares/current-user.test.ts b/tests/src/unit/middlewares/current-user.test.ts index 15df66cd..ff54e02f 100644 --- a/tests/src/unit/middlewares/current-user.test.ts +++ b/tests/src/unit/middlewares/current-user.test.ts @@ -1,6 +1,6 @@ import 'reflect-metadata'; import { expect, test, vi } from 'vitest'; -import { CurrentUserMiddleware } from '../../../../src/api/middlewares/current-user.middleware.js'; +import { CurrentUserMiddleware } from '../../../../src/middlewares/current-user.middleware.js'; const mockUserService = { tryLoadUserFromToken: vi.fn(), diff --git a/tests/src/unit/middlewares/file-upload-middleware.test.ts b/tests/src/unit/middlewares/file-upload-middleware.test.ts index 8c66d30a..57d6d0cc 100644 --- a/tests/src/unit/middlewares/file-upload-middleware.test.ts +++ b/tests/src/unit/middlewares/file-upload-middleware.test.ts @@ -1,8 +1,8 @@ import 'reflect-metadata'; import { vi, it, expect, afterAll, vitest } from 'vitest'; -import { createFileUploadMiddleware } from '../../../../src/api/middlewares/file-upload.middleware.js'; +import { createFileUploadMiddleware } from '../../../../src/middlewares/file-upload.middleware.js'; import * as KoaBody from 'koa-body'; -import { createBadRequestError } from 'app/api/errors/web/bad-request.js'; +import { createBadRequestError } from '../../../../src/errors/bad-request.js'; vi.mock('koa-body', () => ({ koaBody: vi.fn(() => vi.fn()) diff --git a/tests/src/unit/middlewares/log.test.ts b/tests/src/unit/middlewares/log.test.ts index 44d343d5..2ce9421a 100644 --- a/tests/src/unit/middlewares/log.test.ts +++ b/tests/src/unit/middlewares/log.test.ts @@ -1,7 +1,7 @@ import 'reflect-metadata'; import { afterEach, beforeEach, expect, test, vi } from 'vitest'; -import { LogMiddleware } from '../../../../src/api/middlewares/log.middleware.js'; -import type { LoggerService } from '../../../../src/api/services/logger.service.js'; +import { LogMiddleware } from '../../../../src/middlewares/log.middleware.js'; +import type { LoggerService } from '../../../../src/services/logger.service.js'; const loggerServiceMock = { error: vi.fn(), diff --git a/tests/src/unit/middlewares/rate-limit.test.ts b/tests/src/unit/middlewares/rate-limit.test.ts index de7d3034..dbd2beb8 100644 --- a/tests/src/unit/middlewares/rate-limit.test.ts +++ b/tests/src/unit/middlewares/rate-limit.test.ts @@ -1,7 +1,7 @@ import KoaRatelimit from 'koa-ratelimit'; import 'reflect-metadata'; import { afterEach, expect, test, vi } from 'vitest'; -import { createRateLimitMiddleware } from '../../../../src/api/middlewares/rate-limit.middleware.js'; +import { createRateLimitMiddleware } from '../../../../src/middlewares/rate-limit.middleware.js'; const configService = { get: vi.fn(), diff --git a/tests/src/unit/resources/document/service.test.ts b/tests/src/unit/resources/document/service.test.ts index 3a03bb97..83ba8f57 100644 --- a/tests/src/unit/resources/document/service.test.ts +++ b/tests/src/unit/resources/document/service.test.ts @@ -1,7 +1,7 @@ -import { mockedEntityRepository } from 'tests/mocks/repository.js'; import { expect, test, beforeEach, describe, it } from 'vitest'; -import { DocumentResourceServiceImpl } from '../../../../../src/api/resources/documents/service.js'; -import { DocumentModel } from '../../../../../src/database/models/document.model.js'; +import { DocumentResourceServiceImpl } from '../../../../../src/features/users/resources/documents/service.js'; +import { DocumentModel } from '../../../../../src/features/users/models/document.model.js'; +import { mockedEntityRepository } from '../../../../mocks/repository.js'; let documentResourceService: DocumentResourceServiceImpl; const document = new DocumentModel(); diff --git a/tests/src/unit/resources/user/service.test.ts b/tests/src/unit/resources/user/service.test.ts index 08bed8e2..2c28b4ba 100644 --- a/tests/src/unit/resources/user/service.test.ts +++ b/tests/src/unit/resources/user/service.test.ts @@ -1,7 +1,7 @@ import { expect, test, beforeEach } from 'vitest'; -import type { UserResourceService } from '../../../../../src/api/resources/user/service.js'; -import { UserResourceServiceImpl } from '../../../../../src/api/resources/user/service.js'; -import { UserModel } from '../../../../../src/database/models/user.model.js'; +import type { UserResourceService } from '../../../../../src/features/users/resources/user/service.js'; +import { UserResourceServiceImpl } from '../../../../../src/features/users/resources/user/service.js'; +import { UserModel } from '../../../../../src/features/users/models/user.model.js'; import { mockedEntityRepository } from '../../../../mocks/repository.js'; let userResourceService: UserResourceService; diff --git a/tests/src/unit/services/auth.test.ts b/tests/src/unit/services/auth.test.ts index 7fa8dd5b..ba9ce91b 100644 --- a/tests/src/unit/services/auth.test.ts +++ b/tests/src/unit/services/auth.test.ts @@ -1,7 +1,7 @@ import 'reflect-metadata'; import { expect, test, vi, beforeEach, afterAll, beforeAll } from 'vitest'; import { hash } from 'bcrypt'; -import { AuthService } from '../../../../src/api/services/auth.service.js'; +import { AuthService } from '../../../../src/features/auth/services/auth.service.js'; let service: AuthService; diff --git a/tests/src/unit/services/configuration.test.ts b/tests/src/unit/services/configuration.test.ts index d98818f5..79030215 100644 --- a/tests/src/unit/services/configuration.test.ts +++ b/tests/src/unit/services/configuration.test.ts @@ -1,9 +1,9 @@ import 'reflect-metadata'; import { afterEach, beforeEach, expect, test, vi } from 'vitest'; -import type { ConfigurationService } from '../../../../src/api/services/configuration.service.js'; -import { ConfigurationServiceImpl } from '../../../../src/api/services/configuration.service.js'; +import type { ConfigurationService } from '../../../../src/services/configuration.service.js'; +import { ConfigurationServiceImpl } from '../../../../src/services/configuration.service.js'; import * as exports from 'ts-dotenv'; -import { ConfigurationNotLoadedError } from '../../../../src/api/errors/configuration-not-loaded.js'; +import { ConfigurationNotLoadedError } from '../../../../src/errors/configuration-not-loaded.js'; let configurationService: ConfigurationService<{}>; diff --git a/tests/src/unit/services/logger.test.ts b/tests/src/unit/services/logger.test.ts index bfcb8b03..4865388f 100644 --- a/tests/src/unit/services/logger.test.ts +++ b/tests/src/unit/services/logger.test.ts @@ -1,8 +1,8 @@ /* eslint-disable no-console */ import 'reflect-metadata'; import { expect, test, vi, afterEach, beforeEach, afterAll } from 'vitest'; -import type { LoggerService } from '../../../../src/api/services/logger.service.js'; -import { LoggerServiceImpl } from '../../../../src/api/services/logger.service.js'; +import type { LoggerService } from '../../../../src/services/logger.service.js'; +import { LoggerServiceImpl } from '../../../../src/services/logger.service.js'; let loggerService: LoggerService; diff --git a/tests/src/unit/services/user.test.ts b/tests/src/unit/services/user.test.ts index e1460282..290d0059 100644 --- a/tests/src/unit/services/user.test.ts +++ b/tests/src/unit/services/user.test.ts @@ -1,8 +1,8 @@ import 'reflect-metadata'; -import { mockedEntityRepository } from 'tests/mocks/repository.js'; import { afterEach, beforeEach, expect, test, vi } from 'vitest'; -import { InvalidBearerTokenError } from '../../../../src/api/errors/web/invalid-bearer-token.js'; -import { UserService } from '../../../../src/api/services/user.service.js'; +import { InvalidBearerTokenError } from '../../../../src/features/auth/errors/invalid-bearer-token.js'; +import { UserService } from '../../../../src/features/users/services/user.service.js'; +import { mockedEntityRepository } from '../../../mocks/repository.js'; let userService: UserService; diff --git a/tests/src/unit/utils/date.test.ts b/tests/src/unit/utils/date.test.ts index 595704de..5e1c7b5e 100644 --- a/tests/src/unit/utils/date.test.ts +++ b/tests/src/unit/utils/date.test.ts @@ -1,5 +1,5 @@ import { expect, test, vi } from 'vitest'; -import { unixTimestamp } from '../../../../src/api/utils/date.js'; +import { unixTimestamp } from '../../../../src/utils/date.js'; test('it returns current date in unix timestamp in milliseconds', () => { vi.useFakeTimers(); diff --git a/tests/src/unit/utils/json-api-query-to-find-options.test.ts b/tests/src/unit/utils/json-api-query-to-find-options.test.ts index 52151743..632ef3ef 100644 --- a/tests/src/unit/utils/json-api-query-to-find-options.test.ts +++ b/tests/src/unit/utils/json-api-query-to-find-options.test.ts @@ -1,7 +1,7 @@ import type { FindOptions } from '@mikro-orm/core'; import type { JsonApiQuery } from '@triptyk/nfw-resources'; import { expect, test } from 'vitest'; -import { jsonApiQueryToFindOptions } from '../../../../src/api/utils/query/json-api-query-to-find-options.js'; +import { jsonApiQueryToFindOptions } from '../../../../src/utils/query/json-api-query-to-find-options.js'; test('jsonApiQueryToMikroORM', () => { const query: JsonApiQuery = { diff --git a/tests/utils/setup-acceptance-test.ts b/tests/utils/setup-acceptance-test.ts index 50424e95..6032a3ab 100644 --- a/tests/utils/setup-acceptance-test.ts +++ b/tests/utils/setup-acceptance-test.ts @@ -1,8 +1,8 @@ import 'reflect-metadata'; import { container } from '@triptyk/nfw-core'; -import { Application } from 'app/application.js'; -import { DatabaseConnectionImpl } from 'app/database/connection.js'; -import { DatabaseSeeder } from 'app/database/seeders/test/test.seeder.js'; +import { Application } from '../../src/application.js'; +import { DatabaseConnectionImpl } from '../../src/database/connection.js'; +import { DatabaseSeeder } from '../../src/database/seeders/test/test.seeder.js'; export async function setupAcceptance () { const application = container.resolve(Application); diff --git a/tsconfig.json b/tsconfig.json index b7932407..1678da94 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,6 @@ { "compilerOptions": { "lib": ["ESNEXT"], - "baseUrl": ".", "strict": true, "target": "ESNext", "moduleResolution": "NodeNext", @@ -14,11 +13,7 @@ "verbatimModuleSyntax": true, "declaration": true, "outDir": "./dist", - "forceConsistentCasingInFileNames": true, - "paths": { - "tests/*": ["tests/*"], - "app/*": ["src/*"] - } + "forceConsistentCasingInFileNames": true }, - "include": ["src/**/*", "tests/**/*", "vitest.workspace.ts"] + "include": ["src/**/*", "tests/**/*", "vitest.workspace.ts", "config/**/*.ts"] } diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 847c837a..64655b6a 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -1,24 +1,21 @@ -import tsconfigPaths from 'vite-tsconfig-paths'; import { defineWorkspace } from 'vitest/dist/config.js'; // Cannot split integration and acceptance https://github.com/vitest-dev/vitest/issues/3255 export default defineWorkspace([ { - plugins: [tsconfigPaths()], + plugins: [], test: { name: 'unit', - include: ['tests/src/unit/**/*.test.ts'], - logHeapUsage: true + include: ['tests/src/unit/**/*.test.ts'] }, }, { - plugins: [tsconfigPaths()], + plugins: [], test: { name: 'integration-acceptance', include: ['tests/src/{integration,acceptance}/**/*.test.ts'], singleThread: true, - globals: true, - logHeapUsage: true + globals: true } } ]);