@postxl/generators 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +50 -0
- package/dist/backend-actions/actions-provider.mock.d.ts +7 -0
- package/dist/backend-actions/actions-provider.mock.js +75 -0
- package/dist/backend-actions/actions-provider.mock.js.map +1 -0
- package/dist/backend-actions/actions.generator.d.ts +130 -0
- package/dist/backend-actions/actions.generator.js +204 -0
- package/dist/backend-actions/actions.generator.js.map +1 -0
- package/dist/backend-actions/generators/action-types.generator.d.ts +2 -0
- package/dist/backend-actions/generators/action-types.generator.js +47 -0
- package/dist/backend-actions/generators/action-types.generator.js.map +1 -0
- package/dist/backend-actions/generators/actions-config-class.generator.d.ts +2 -0
- package/dist/backend-actions/generators/actions-config-class.generator.js +25 -0
- package/dist/backend-actions/generators/actions-config-class.generator.js.map +1 -0
- package/dist/backend-actions/generators/actions-module.generator.d.ts +2 -0
- package/dist/backend-actions/generators/actions-module.generator.js +47 -0
- package/dist/backend-actions/generators/actions-module.generator.js.map +1 -0
- package/dist/backend-actions/generators/authorization-service.generator.d.ts +2 -0
- package/dist/backend-actions/generators/authorization-service.generator.js +35 -0
- package/dist/backend-actions/generators/authorization-service.generator.js.map +1 -0
- package/dist/backend-actions/generators/dispatcher-service.generator.d.ts +2 -0
- package/dist/backend-actions/generators/dispatcher-service.generator.js +97 -0
- package/dist/backend-actions/generators/dispatcher-service.generator.js.map +1 -0
- package/dist/backend-actions/generators/execution-class.generator.d.ts +2 -0
- package/dist/backend-actions/generators/execution-class.generator.js +561 -0
- package/dist/backend-actions/generators/execution-class.generator.js.map +1 -0
- package/dist/backend-actions/generators/execution-interface.generator.d.ts +2 -0
- package/dist/backend-actions/generators/execution-interface.generator.js +237 -0
- package/dist/backend-actions/generators/execution-interface.generator.js.map +1 -0
- package/dist/backend-actions/index.d.ts +9 -0
- package/dist/backend-actions/index.js +43 -0
- package/dist/backend-actions/index.js.map +1 -0
- package/dist/backend-actions/template/README.md +21 -0
- package/dist/backend-actions/template/src/execution/types.ts +85 -0
- package/dist/backend-authentication/authentication.generator.d.ts +29 -0
- package/dist/backend-authentication/authentication.generator.js +145 -0
- package/dist/backend-authentication/authentication.generator.js.map +1 -0
- package/dist/backend-authentication/generators/auth-guard.generator.d.ts +2 -0
- package/dist/backend-authentication/generators/auth-guard.generator.js +121 -0
- package/dist/backend-authentication/generators/auth-guard.generator.js.map +1 -0
- package/dist/backend-authentication/generators/authentication-module.generator.d.ts +2 -0
- package/dist/backend-authentication/generators/authentication-module.generator.js +79 -0
- package/dist/backend-authentication/generators/authentication-module.generator.js.map +1 -0
- package/dist/backend-authentication/generators/authentication-service.generator.d.ts +2 -0
- package/dist/backend-authentication/generators/authentication-service.generator.js +393 -0
- package/dist/backend-authentication/generators/authentication-service.generator.js.map +1 -0
- package/dist/backend-authentication/generators/authentication-types.generator.d.ts +2 -0
- package/dist/backend-authentication/generators/authentication-types.generator.js +64 -0
- package/dist/backend-authentication/generators/authentication-types.generator.js.map +1 -0
- package/dist/backend-authentication/index.d.ts +4 -0
- package/dist/backend-authentication/index.js +40 -0
- package/dist/backend-authentication/index.js.map +1 -0
- package/dist/backend-authentication/template/README.md +35 -0
- package/dist/backend-authentication/template/assets/auth.png +0 -0
- package/dist/backend-authentication/template/assets/cookie-validation.png +0 -0
- package/dist/backend-authentication/template/assets/page-request.png +0 -0
- package/dist/backend-authentication/template/docs/auth.mmd +42 -0
- package/dist/backend-authentication/template/docs/cookie-validation.mmd +0 -0
- package/dist/backend-authentication/template/docs/page-request.mmd +42 -0
- package/dist/backend-authentication/template/src/authentication.config.ts +51 -0
- package/dist/backend-authentication/template/src/authentication.controller.ts +105 -0
- package/dist/backend-authentication/template/src/authentication.mock.service.ts +108 -0
- package/dist/backend-authentication/template/src/utils.ts +13 -0
- package/dist/backend-authentication/template/src/viewer.decorator.ts +13 -0
- package/dist/backend-core/backend.generator.d.ts +3 -0
- package/dist/backend-core/backend.generator.js +154 -0
- package/dist/backend-core/backend.generator.js.map +1 -0
- package/dist/backend-core/generators/api-config.generator.d.ts +2 -0
- package/dist/backend-core/generators/api-config.generator.js +72 -0
- package/dist/backend-core/generators/api-config.generator.js.map +1 -0
- package/dist/backend-core/generators/api-module.generator.d.ts +2 -0
- package/dist/backend-core/generators/api-module.generator.js +53 -0
- package/dist/backend-core/generators/api-module.generator.js.map +1 -0
- package/dist/backend-core/generators/dotenv-example.generator.d.ts +2 -0
- package/dist/backend-core/generators/dotenv-example.generator.js +38 -0
- package/dist/backend-core/generators/dotenv-example.generator.js.map +1 -0
- package/dist/backend-core/generators/main.generator.d.ts +2 -0
- package/dist/backend-core/generators/main.generator.js +153 -0
- package/dist/backend-core/generators/main.generator.js.map +1 -0
- package/dist/backend-core/generators/tsconfig.generator.d.ts +2 -0
- package/dist/backend-core/generators/tsconfig.generator.js +59 -0
- package/dist/backend-core/generators/tsconfig.generator.js.map +1 -0
- package/dist/backend-core/index.d.ts +3 -0
- package/dist/backend-core/index.js +20 -0
- package/dist/backend-core/index.js.map +1 -0
- package/dist/backend-core/modules/backend-module-utils.generator.d.ts +3 -0
- package/dist/backend-core/modules/backend-module-utils.generator.js +65 -0
- package/dist/backend-core/modules/backend-module-utils.generator.js.map +1 -0
- package/dist/backend-core/modules/backend-module-xlport.generator.d.ts +3 -0
- package/dist/backend-core/modules/backend-module-xlport.generator.js +80 -0
- package/dist/backend-core/modules/backend-module-xlport.generator.js.map +1 -0
- package/dist/backend-core/template/README.md +97 -0
- package/dist/backend-core/template/apps/api/README.md +3 -0
- package/dist/backend-core/template/apps/api/src/api.controller.ts +14 -0
- package/dist/backend-core/template/apps/api/src/console.logger.ts +55 -0
- package/dist/backend-core/template/apps/api/src/e2e.ts +458 -0
- package/dist/backend-core/template/apps/api/test/base.test.ts +7 -0
- package/dist/backend-core/template/apps/api/tsconfig.app.json +9 -0
- package/dist/backend-core/template/jest.config.ts +39 -0
- package/dist/backend-core/template/libs/e2e/src/e2e.controller.ts +30 -0
- package/dist/backend-core/template/libs/e2e/src/e2e.module.ts +18 -0
- package/dist/backend-core/template/libs/e2e/src/test-data.service.ts +20 -0
- package/dist/backend-core/template/libs/utils/src/pagination.test.ts +58 -0
- package/dist/backend-core/template/libs/utils/src/pagination.ts +68 -0
- package/dist/backend-core/template/libs/utils/tsconfig.lib.json +9 -0
- package/dist/backend-core/template/libs/xlport/README.md +90 -0
- package/dist/backend-core/template/libs/xlport/src/xlport.config.ts +8 -0
- package/dist/backend-core/template/libs/xlport/src/xlport.module.ts +20 -0
- package/dist/backend-core/template/libs/xlport/src/xlport.service.ts +171 -0
- package/dist/backend-core/template/libs/xlport/tsconfig.lib.json +9 -0
- package/dist/backend-core/template/nest-cli.json +22 -0
- package/dist/backend-core/template/tsconfig.build.json +4 -0
- package/dist/backend-core/types.d.ts +145 -0
- package/dist/backend-core/types.js +3 -0
- package/dist/backend-core/types.js.map +1 -0
- package/dist/backend-data-management/data-management.generator.d.ts +18 -0
- package/dist/backend-data-management/data-management.generator.js +104 -0
- package/dist/backend-data-management/data-management.generator.js.map +1 -0
- package/dist/backend-data-management/generators/data-management-service.generator.d.ts +8 -0
- package/dist/backend-data-management/generators/data-management-service.generator.js +330 -0
- package/dist/backend-data-management/generators/data-management-service.generator.js.map +1 -0
- package/dist/backend-data-management/index.d.ts +2 -0
- package/dist/backend-data-management/index.js +22 -0
- package/dist/backend-data-management/index.js.map +1 -0
- package/dist/backend-data-management/template/data-management.controller.ts +242 -0
- package/dist/backend-data-management/template/data-management.module.ts +15 -0
- package/dist/backend-database-prisma/generators/database-config.generator.d.ts +2 -0
- package/dist/backend-database-prisma/generators/database-config.generator.js +18 -0
- package/dist/backend-database-prisma/generators/database-config.generator.js.map +1 -0
- package/dist/backend-database-prisma/generators/database-module.generator.d.ts +2 -0
- package/dist/backend-database-prisma/generators/database-module.generator.js +66 -0
- package/dist/backend-database-prisma/generators/database-module.generator.js.map +1 -0
- package/dist/backend-database-prisma/generators/database-service.generator.d.ts +2 -0
- package/dist/backend-database-prisma/generators/database-service.generator.js +45 -0
- package/dist/backend-database-prisma/generators/database-service.generator.js.map +1 -0
- package/dist/backend-database-prisma/generators/index.generator.d.ts +2 -0
- package/dist/backend-database-prisma/generators/index.generator.js +12 -0
- package/dist/backend-database-prisma/generators/index.generator.js.map +1 -0
- package/dist/backend-database-prisma/generators/prisma-schema.generator.d.ts +2 -0
- package/dist/backend-database-prisma/generators/prisma-schema.generator.js +224 -0
- package/dist/backend-database-prisma/generators/prisma-schema.generator.js.map +1 -0
- package/dist/backend-database-prisma/index.d.ts +5 -0
- package/dist/backend-database-prisma/index.js +41 -0
- package/dist/backend-database-prisma/index.js.map +1 -0
- package/dist/backend-database-prisma/prisma.generator.d.ts +29 -0
- package/dist/backend-database-prisma/prisma.generator.js +123 -0
- package/dist/backend-database-prisma/prisma.generator.js.map +1 -0
- package/dist/backend-database-prisma/prisma.utils.d.ts +9 -0
- package/dist/backend-database-prisma/prisma.utils.js +27 -0
- package/dist/backend-database-prisma/prisma.utils.js.map +1 -0
- package/dist/backend-database-prisma/template/prisma.config.ts +14 -0
- package/dist/backend-e2e/backend-e2e.generator.d.ts +23 -0
- package/dist/backend-e2e/backend-e2e.generator.js +139 -0
- package/dist/backend-e2e/backend-e2e.generator.js.map +1 -0
- package/dist/backend-e2e/generators/e2e-controller.generator.d.ts +2 -0
- package/dist/backend-e2e/generators/e2e-controller.generator.js +70 -0
- package/dist/backend-e2e/generators/e2e-controller.generator.js.map +1 -0
- package/dist/backend-e2e/generators/e2e-module.generator.d.ts +2 -0
- package/dist/backend-e2e/generators/e2e-module.generator.js +64 -0
- package/dist/backend-e2e/generators/e2e-module.generator.js.map +1 -0
- package/dist/backend-e2e/generators/e2e-service.generator.d.ts +2 -0
- package/dist/backend-e2e/generators/e2e-service.generator.js +99 -0
- package/dist/backend-e2e/generators/e2e-service.generator.js.map +1 -0
- package/dist/backend-e2e/index.d.ts +4 -0
- package/dist/backend-e2e/index.js +40 -0
- package/dist/backend-e2e/index.js.map +1 -0
- package/dist/backend-import/generators/convert-functions.generator.d.ts +5 -0
- package/dist/backend-import/generators/convert-functions.generator.js +600 -0
- package/dist/backend-import/generators/convert-functions.generator.js.map +1 -0
- package/dist/backend-import/generators/detect-delta/detect-delta-all-models.generator.d.ts +2 -0
- package/dist/backend-import/generators/detect-delta/detect-delta-all-models.generator.js +128 -0
- package/dist/backend-import/generators/detect-delta/detect-delta-all-models.generator.js.map +1 -0
- package/dist/backend-import/generators/detect-delta/detect-delta-functions.generator.d.ts +2 -0
- package/dist/backend-import/generators/detect-delta/detect-delta-functions.generator.js +391 -0
- package/dist/backend-import/generators/detect-delta/detect-delta-functions.generator.js.map +1 -0
- package/dist/backend-import/generators/detect-delta/model-function.generator.d.ts +2 -0
- package/dist/backend-import/generators/detect-delta/model-function.generator.js +321 -0
- package/dist/backend-import/generators/detect-delta/model-function.generator.js.map +1 -0
- package/dist/backend-import/generators/detect-delta/types.generator.d.ts +2 -0
- package/dist/backend-import/generators/detect-delta/types.generator.js +149 -0
- package/dist/backend-import/generators/detect-delta/types.generator.js.map +1 -0
- package/dist/backend-import/generators/import-module.generator.d.ts +2 -0
- package/dist/backend-import/generators/import-module.generator.js +58 -0
- package/dist/backend-import/generators/import-module.generator.js.map +1 -0
- package/dist/backend-import/generators/import-service.generator.d.ts +2 -0
- package/dist/backend-import/generators/import-service.generator.js +304 -0
- package/dist/backend-import/generators/import-service.generator.js.map +1 -0
- package/dist/backend-import/import.generator.d.ts +228 -0
- package/dist/backend-import/import.generator.js +255 -0
- package/dist/backend-import/import.generator.js.map +1 -0
- package/dist/backend-import/index.d.ts +5 -0
- package/dist/backend-import/index.js +40 -0
- package/dist/backend-import/index.js.map +1 -0
- package/dist/backend-import/template/README.md +52 -0
- package/dist/backend-repositories/generators/bulk-mutation-types.generator.d.ts +2 -0
- package/dist/backend-repositories/generators/bulk-mutation-types.generator.js +42 -0
- package/dist/backend-repositories/generators/bulk-mutation-types.generator.js.map +1 -0
- package/dist/backend-repositories/generators/data-service.generator.d.ts +2 -0
- package/dist/backend-repositories/generators/data-service.generator.js +289 -0
- package/dist/backend-repositories/generators/data-service.generator.js.map +1 -0
- package/dist/backend-repositories/generators/model-repository.generator.d.ts +14 -0
- package/dist/backend-repositories/generators/model-repository.generator.js +1936 -0
- package/dist/backend-repositories/generators/model-repository.generator.js.map +1 -0
- package/dist/backend-repositories/generators/repository-interface.generator.d.ts +2 -0
- package/dist/backend-repositories/generators/repository-interface.generator.js +55 -0
- package/dist/backend-repositories/generators/repository-interface.generator.js.map +1 -0
- package/dist/backend-repositories/generators/repository-module.generator.d.ts +2 -0
- package/dist/backend-repositories/generators/repository-module.generator.js +143 -0
- package/dist/backend-repositories/generators/repository-module.generator.js.map +1 -0
- package/dist/backend-repositories/index.d.ts +5 -0
- package/dist/backend-repositories/index.js +40 -0
- package/dist/backend-repositories/index.js.map +1 -0
- package/dist/backend-repositories/model.types.d.ts +69 -0
- package/dist/backend-repositories/model.types.js +17 -0
- package/dist/backend-repositories/model.types.js.map +1 -0
- package/dist/backend-repositories/repositories.generator.d.ts +46 -0
- package/dist/backend-repositories/repositories.generator.js +256 -0
- package/dist/backend-repositories/repositories.generator.js.map +1 -0
- package/dist/backend-rest-api/generators/model-controller.generator.d.ts +5 -0
- package/dist/backend-rest-api/generators/model-controller.generator.js +100 -0
- package/dist/backend-rest-api/generators/model-controller.generator.js.map +1 -0
- package/dist/backend-rest-api/generators/rest-api-module.generator.d.ts +2 -0
- package/dist/backend-rest-api/generators/rest-api-module.generator.js +62 -0
- package/dist/backend-rest-api/generators/rest-api-module.generator.js.map +1 -0
- package/dist/backend-rest-api/generators/zod-exception-filter.generator.d.ts +1 -0
- package/dist/backend-rest-api/generators/zod-exception-filter.generator.js +28 -0
- package/dist/backend-rest-api/generators/zod-exception-filter.generator.js.map +1 -0
- package/dist/backend-rest-api/index.d.ts +5 -0
- package/dist/backend-rest-api/index.js +40 -0
- package/dist/backend-rest-api/index.js.map +1 -0
- package/dist/backend-rest-api/rest-api.generator.d.ts +24 -0
- package/dist/backend-rest-api/rest-api.generator.js +113 -0
- package/dist/backend-rest-api/rest-api.generator.js.map +1 -0
- package/dist/backend-rest-api/template/zod-exception.filter.ts +21 -0
- package/dist/backend-router-trpc/generators/app-routes.generator.d.ts +4 -0
- package/dist/backend-router-trpc/generators/app-routes.generator.js +74 -0
- package/dist/backend-router-trpc/generators/app-routes.generator.js.map +1 -0
- package/dist/backend-router-trpc/generators/audit-log-route.generator.d.ts +7 -0
- package/dist/backend-router-trpc/generators/audit-log-route.generator.js +611 -0
- package/dist/backend-router-trpc/generators/audit-log-route.generator.js.map +1 -0
- package/dist/backend-router-trpc/generators/middleware.generator.d.ts +2 -0
- package/dist/backend-router-trpc/generators/middleware.generator.js +100 -0
- package/dist/backend-router-trpc/generators/middleware.generator.js.map +1 -0
- package/dist/backend-router-trpc/generators/model-routes.generator.d.ts +8 -0
- package/dist/backend-router-trpc/generators/model-routes.generator.js +88 -0
- package/dist/backend-router-trpc/generators/model-routes.generator.js.map +1 -0
- package/dist/backend-router-trpc/generators/trpc-plugin.generator.d.ts +2 -0
- package/dist/backend-router-trpc/generators/trpc-plugin.generator.js +141 -0
- package/dist/backend-router-trpc/generators/trpc-plugin.generator.js.map +1 -0
- package/dist/backend-router-trpc/generators/trpc-router-module.generator.d.ts +2 -0
- package/dist/backend-router-trpc/generators/trpc-router-module.generator.js +60 -0
- package/dist/backend-router-trpc/generators/trpc-router-module.generator.js.map +1 -0
- package/dist/backend-router-trpc/generators/trpc-shared.generator.d.ts +2 -0
- package/dist/backend-router-trpc/generators/trpc-shared.generator.js +134 -0
- package/dist/backend-router-trpc/generators/trpc-shared.generator.js.map +1 -0
- package/dist/backend-router-trpc/index.d.ts +5 -0
- package/dist/backend-router-trpc/index.js +40 -0
- package/dist/backend-router-trpc/index.js.map +1 -0
- package/dist/backend-router-trpc/router-trpc.generator.d.ts +108 -0
- package/dist/backend-router-trpc/router-trpc.generator.js +189 -0
- package/dist/backend-router-trpc/router-trpc.generator.js.map +1 -0
- package/dist/backend-router-trpc/template/viewer.router.ts +25 -0
- package/dist/backend-s3/generators/s3.config.generator.d.ts +2 -0
- package/dist/backend-s3/generators/s3.config.generator.js +24 -0
- package/dist/backend-s3/generators/s3.config.generator.js.map +1 -0
- package/dist/backend-s3/generators/s3.module.generator.d.ts +2 -0
- package/dist/backend-s3/generators/s3.module.generator.js +33 -0
- package/dist/backend-s3/generators/s3.module.generator.js.map +1 -0
- package/dist/backend-s3/generators/s3.service.generator.d.ts +2 -0
- package/dist/backend-s3/generators/s3.service.generator.js +116 -0
- package/dist/backend-s3/generators/s3.service.generator.js.map +1 -0
- package/dist/backend-s3/index.d.ts +4 -0
- package/dist/backend-s3/index.js +40 -0
- package/dist/backend-s3/index.js.map +1 -0
- package/dist/backend-s3/s3.generator.d.ts +19 -0
- package/dist/backend-s3/s3.generator.js +125 -0
- package/dist/backend-s3/s3.generator.js.map +1 -0
- package/dist/backend-seed/generators/seed-module.generator.d.ts +2 -0
- package/dist/backend-seed/generators/seed-module.generator.js +60 -0
- package/dist/backend-seed/generators/seed-module.generator.js.map +1 -0
- package/dist/backend-seed/generators/seed-service.generator.d.ts +2 -0
- package/dist/backend-seed/generators/seed-service.generator.js +176 -0
- package/dist/backend-seed/generators/seed-service.generator.js.map +1 -0
- package/dist/backend-seed/index.d.ts +4 -0
- package/dist/backend-seed/index.js +40 -0
- package/dist/backend-seed/index.js.map +1 -0
- package/dist/backend-seed/seed.generator.d.ts +19 -0
- package/dist/backend-seed/seed.generator.js +95 -0
- package/dist/backend-seed/seed.generator.js.map +1 -0
- package/dist/backend-seed/template/src/actions.ts +90 -0
- package/dist/backend-seed/template/tsconfig.lib.json +9 -0
- package/dist/backend-update/bulk-service.generator.d.ts +2 -0
- package/dist/backend-update/bulk-service.generator.js +277 -0
- package/dist/backend-update/bulk-service.generator.js.map +1 -0
- package/dist/backend-update/index.d.ts +5 -0
- package/dist/backend-update/index.js +40 -0
- package/dist/backend-update/index.js.map +1 -0
- package/dist/backend-update/model-update-service.generator.d.ts +5 -0
- package/dist/backend-update/model-update-service.generator.js +757 -0
- package/dist/backend-update/model-update-service.generator.js.map +1 -0
- package/dist/backend-update/update-actions.decoders.d.ts +15 -0
- package/dist/backend-update/update-actions.decoders.js +37 -0
- package/dist/backend-update/update-actions.decoders.js.map +1 -0
- package/dist/backend-update/update-module.generator.d.ts +2 -0
- package/dist/backend-update/update-module.generator.js +69 -0
- package/dist/backend-update/update-module.generator.js.map +1 -0
- package/dist/backend-update/update-service.generator.d.ts +2 -0
- package/dist/backend-update/update-service.generator.js +94 -0
- package/dist/backend-update/update-service.generator.js.map +1 -0
- package/dist/backend-update/update.generator.d.ts +138 -0
- package/dist/backend-update/update.generator.js +302 -0
- package/dist/backend-update/update.generator.js.map +1 -0
- package/dist/backend-view/index.d.ts +5 -0
- package/dist/backend-view/index.js +40 -0
- package/dist/backend-view/index.js.map +1 -0
- package/dist/backend-view/model-view-service.generator.d.ts +11 -0
- package/dist/backend-view/model-view-service.generator.js +196 -0
- package/dist/backend-view/model-view-service.generator.js.map +1 -0
- package/dist/backend-view/view-module.generator.d.ts +2 -0
- package/dist/backend-view/view-module.generator.js +62 -0
- package/dist/backend-view/view-module.generator.js.map +1 -0
- package/dist/backend-view/view-service.generator.d.ts +2 -0
- package/dist/backend-view/view-service.generator.js +56 -0
- package/dist/backend-view/view-service.generator.js.map +1 -0
- package/dist/backend-view/view.generator.d.ts +32 -0
- package/dist/backend-view/view.generator.js +100 -0
- package/dist/backend-view/view.generator.js.map +1 -0
- package/dist/base/base.generator.d.ts +26 -0
- package/dist/base/base.generator.js +138 -0
- package/dist/base/base.generator.js.map +1 -0
- package/dist/base/index.d.ts +1 -0
- package/dist/base/index.js +18 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/template/.nvmrc +1 -0
- package/dist/base/template/.prettierignore +5 -0
- package/dist/base/template/.turboignore +1 -0
- package/dist/base/template/.vscode/extensions.json +16 -0
- package/dist/base/template/.vscode/launch.json +15 -0
- package/dist/base/template/.vscode/settings.json +73 -0
- package/dist/base/template/README.md +115 -0
- package/dist/base/template/eslint.config.mjs +194 -0
- package/dist/base/template/jest.config.ts +7 -0
- package/dist/base/template/prettier.config.js +10 -0
- package/dist/base/template/scripts/setup.sh +25 -0
- package/dist/base/template/sonar-project.properties +94 -0
- package/dist/base/template/tsconfig.json +12 -0
- package/dist/decoders/datamodel-decoder.generator.d.ts +7 -0
- package/dist/decoders/datamodel-decoder.generator.js +134 -0
- package/dist/decoders/datamodel-decoder.generator.js.map +1 -0
- package/dist/decoders/decoders.generator.d.ts +133 -0
- package/dist/decoders/decoders.generator.js +424 -0
- package/dist/decoders/decoders.generator.js.map +1 -0
- package/dist/decoders/discriminated-union.decoder.generator.d.ts +12 -0
- package/dist/decoders/discriminated-union.decoder.generator.js +205 -0
- package/dist/decoders/discriminated-union.decoder.generator.js.map +1 -0
- package/dist/decoders/enum-decoder.generator.d.ts +5 -0
- package/dist/decoders/enum-decoder.generator.js +71 -0
- package/dist/decoders/enum-decoder.generator.js.map +1 -0
- package/dist/decoders/excel-field-decoder.helper.d.ts +17 -0
- package/dist/decoders/excel-field-decoder.helper.js +178 -0
- package/dist/decoders/excel-field-decoder.helper.js.map +1 -0
- package/dist/decoders/field-decoder.helper.d.ts +50 -0
- package/dist/decoders/field-decoder.helper.js +113 -0
- package/dist/decoders/field-decoder.helper.js.map +1 -0
- package/dist/decoders/index.d.ts +4 -0
- package/dist/decoders/index.js +40 -0
- package/dist/decoders/index.js.map +1 -0
- package/dist/decoders/model-decoder.generator.d.ts +5 -0
- package/dist/decoders/model-decoder.generator.js +197 -0
- package/dist/decoders/model-decoder.generator.js.map +1 -0
- package/dist/decoders/shared.d.ts +51 -0
- package/dist/decoders/shared.js +140 -0
- package/dist/decoders/shared.js.map +1 -0
- package/dist/devops/devops.generator.d.ts +66 -0
- package/dist/devops/devops.generator.js +127 -0
- package/dist/devops/devops.generator.js.map +1 -0
- package/dist/devops/generators/backend-build-sh.generator.d.ts +2 -0
- package/dist/devops/generators/backend-build-sh.generator.js +49 -0
- package/dist/devops/generators/backend-build-sh.generator.js.map +1 -0
- package/dist/devops/generators/backend-dockerfile.generator.d.ts +2 -0
- package/dist/devops/generators/backend-dockerfile.generator.js +67 -0
- package/dist/devops/generators/backend-dockerfile.generator.js.map +1 -0
- package/dist/devops/generators/backend-start-api-sh.generator.d.ts +2 -0
- package/dist/devops/generators/backend-start-api-sh.generator.js +18 -0
- package/dist/devops/generators/backend-start-api-sh.generator.js.map +1 -0
- package/dist/devops/generators/bitbucket-pipelines-yml.generator.d.ts +2 -0
- package/dist/devops/generators/bitbucket-pipelines-yml.generator.js +105 -0
- package/dist/devops/generators/bitbucket-pipelines-yml.generator.js.map +1 -0
- package/dist/devops/generators/configure-keycloak-sh.generator.d.ts +2 -0
- package/dist/devops/generators/configure-keycloak-sh.generator.js +158 -0
- package/dist/devops/generators/configure-keycloak-sh.generator.js.map +1 -0
- package/dist/devops/generators/docker-compose-yml.generator.d.ts +2 -0
- package/dist/devops/generators/docker-compose-yml.generator.js +78 -0
- package/dist/devops/generators/docker-compose-yml.generator.js.map +1 -0
- package/dist/devops/generators/e2e-yml.generator.d.ts +2 -0
- package/dist/devops/generators/e2e-yml.generator.js +195 -0
- package/dist/devops/generators/e2e-yml.generator.js.map +1 -0
- package/dist/devops/generators/frontend-build-sh.generator.d.ts +2 -0
- package/dist/devops/generators/frontend-build-sh.generator.js +45 -0
- package/dist/devops/generators/frontend-build-sh.generator.js.map +1 -0
- package/dist/devops/generators/frontend-dockerfile.generator.d.ts +2 -0
- package/dist/devops/generators/frontend-dockerfile.generator.js +75 -0
- package/dist/devops/generators/frontend-dockerfile.generator.js.map +1 -0
- package/dist/devops/generators/jenkinsfile.generator.d.ts +2 -0
- package/dist/devops/generators/jenkinsfile.generator.js +147 -0
- package/dist/devops/generators/jenkinsfile.generator.js.map +1 -0
- package/dist/devops/generators/root-dotenv-example.generator.d.ts +2 -0
- package/dist/devops/generators/root-dotenv-example.generator.js +10 -0
- package/dist/devops/generators/root-dotenv-example.generator.js.map +1 -0
- package/dist/devops/index.d.ts +4 -0
- package/dist/devops/index.js +40 -0
- package/dist/devops/index.js.map +1 -0
- package/dist/devops/template/.github/workflows/test.yml +45 -0
- package/dist/devops/template/docker/backend/migrate.sh +10 -0
- package/dist/devops/template/docker/backend/start.api.sh +8 -0
- package/dist/devops/template/docker/frontend/entrypoint.sh +18 -0
- package/dist/devops/template/docker/frontend/frontend.conf +17 -0
- package/dist/devops/template/docker/keycloak/Dockerfile +17 -0
- package/dist/devops/template/docker/keycloak/localization.en.json +5 -0
- package/dist/devops/template/docker/keycloak/protocol-mappers.json +28 -0
- package/dist/devops/template/docker/keycloak/user-attributes.json +142 -0
- package/dist/e2e/e2e.generator.d.ts +19 -0
- package/dist/e2e/e2e.generator.js +92 -0
- package/dist/e2e/e2e.generator.js.map +1 -0
- package/dist/e2e/generators/lib/test-id-collector.d.ts +48 -0
- package/dist/e2e/generators/lib/test-id-collector.js +65 -0
- package/dist/e2e/generators/lib/test-id-collector.js.map +1 -0
- package/dist/e2e/generators/lib/test-id-generator.d.ts +5 -0
- package/dist/e2e/generators/lib/test-id-generator.js +67 -0
- package/dist/e2e/generators/lib/test-id-generator.js.map +1 -0
- package/dist/e2e/generators/model-test-id.generator.d.ts +5 -0
- package/dist/e2e/generators/model-test-id.generator.js +19 -0
- package/dist/e2e/generators/model-test-id.generator.js.map +1 -0
- package/dist/e2e/generators/package-json.generator.d.ts +2 -0
- package/dist/e2e/generators/package-json.generator.js +29 -0
- package/dist/e2e/generators/package-json.generator.js.map +1 -0
- package/dist/e2e/index.d.ts +4 -0
- package/dist/e2e/index.js +40 -0
- package/dist/e2e/index.js.map +1 -0
- package/dist/e2e/template/e2e/.env.example +11 -0
- package/dist/e2e/template/e2e/Dockerfile +8 -0
- package/dist/e2e/template/e2e/README.md +87 -0
- package/dist/e2e/template/e2e/fixtures/global-setup.ts +3 -0
- package/dist/e2e/template/e2e/fixtures/global-teardown.ts +21 -0
- package/dist/e2e/template/e2e/fixtures/handle-backend.ts +35 -0
- package/dist/e2e/template/e2e/fixtures/set-date-script.js +28 -0
- package/dist/e2e/template/e2e/fixtures/set-fixed-date.ts +12 -0
- package/dist/e2e/template/e2e/fixtures/test-fixtures.ts +132 -0
- package/dist/e2e/template/e2e/package.json +22 -0
- package/dist/e2e/template/e2e/playwright.config.ts +161 -0
- package/dist/e2e/template/e2e/specs/example-backend-isolation.spec.ts +59 -0
- package/dist/e2e/template/e2e/specs/example.spec.ts +77 -0
- package/dist/e2e/template/e2e/specs/example.spec.ts-snapshots/Navigate-to-homepage-and-take-snapshot-1-chromium-linux.png +0 -0
- package/dist/e2e/template/e2e/support/checkbox-click.ts +20 -0
- package/dist/e2e/template/e2e/support/get-backend-mode.ts +10 -0
- package/dist/e2e/template/e2e/support/map.utils.ts +98 -0
- package/dist/e2e/template/e2e/support/mask-toast.ts +20 -0
- package/dist/e2e/template/e2e/support/model-test-ids.ts +4 -0
- package/dist/e2e/template/e2e/support/mouse-annotations.ts +162 -0
- package/dist/e2e/template/e2e/support/page-stability.ts +86 -0
- package/dist/e2e/template/e2e/support/reset-data.ts +38 -0
- package/dist/e2e/template/e2e/support/set-data.ts +44 -0
- package/dist/e2e/template/e2e/support/wait-for-page-loaded.ts +28 -0
- package/dist/e2e/template/e2e/tsconfig.json +51 -0
- package/dist/e2e/template/scripts/docker.sh +17 -0
- package/dist/frontend-admin/admin.generator.d.ts +75 -0
- package/dist/frontend-admin/admin.generator.js +132 -0
- package/dist/frontend-admin/admin.generator.js.map +1 -0
- package/dist/frontend-admin/generators/admin-overview-page.generator.d.ts +7 -0
- package/dist/frontend-admin/generators/admin-overview-page.generator.js +110 -0
- package/dist/frontend-admin/generators/admin-overview-page.generator.js.map +1 -0
- package/dist/frontend-admin/generators/admin-sidebar.generator.d.ts +7 -0
- package/dist/frontend-admin/generators/admin-sidebar.generator.js +196 -0
- package/dist/frontend-admin/generators/admin-sidebar.generator.js.map +1 -0
- package/dist/frontend-admin/generators/audit-log-sidebar.generator.d.ts +8 -0
- package/dist/frontend-admin/generators/audit-log-sidebar.generator.js +629 -0
- package/dist/frontend-admin/generators/audit-log-sidebar.generator.js.map +1 -0
- package/dist/frontend-admin/generators/data-management-page.generator.d.ts +7 -0
- package/dist/frontend-admin/generators/data-management-page.generator.js +778 -0
- package/dist/frontend-admin/generators/data-management-page.generator.js.map +1 -0
- package/dist/frontend-admin/generators/model-admin-page.generator.d.ts +8 -0
- package/dist/frontend-admin/generators/model-admin-page.generator.js +231 -0
- package/dist/frontend-admin/generators/model-admin-page.generator.js.map +1 -0
- package/dist/frontend-admin/index.d.ts +5 -0
- package/dist/frontend-admin/index.js +40 -0
- package/dist/frontend-admin/index.js.map +1 -0
- package/dist/frontend-admin/utils.d.ts +24 -0
- package/dist/frontend-admin/utils.js +122 -0
- package/dist/frontend-admin/utils.js.map +1 -0
- package/dist/frontend-core/frontend.generator.d.ts +87 -0
- package/dist/frontend-core/frontend.generator.js +400 -0
- package/dist/frontend-core/frontend.generator.js.map +1 -0
- package/dist/frontend-core/generators/tsconfig.generator.d.ts +2 -0
- package/dist/frontend-core/generators/tsconfig.generator.js +55 -0
- package/dist/frontend-core/generators/tsconfig.generator.js.map +1 -0
- package/dist/frontend-core/index.d.ts +2 -0
- package/dist/frontend-core/index.js +19 -0
- package/dist/frontend-core/index.js.map +1 -0
- package/dist/frontend-core/scripts/generate-types.d.ts +1 -0
- package/dist/frontend-core/scripts/generate-types.js +59 -0
- package/dist/frontend-core/scripts/generate-types.js.map +1 -0
- package/dist/frontend-core/template/.env.example +44 -0
- package/dist/frontend-core/template/.prettierignore +4 -0
- package/dist/frontend-core/template/.storybook/main.ts +27 -0
- package/dist/frontend-core/template/.storybook/preview.ts +16 -0
- package/dist/frontend-core/template/.storybook/vitest.setup.ts +18 -0
- package/dist/frontend-core/template/README.md +488 -0
- package/dist/frontend-core/template/components.json +21 -0
- package/dist/frontend-core/template/index.html +11 -0
- package/dist/frontend-core/template/public/android-chrome-192x192.png +0 -0
- package/dist/frontend-core/template/public/android-chrome-512x512.png +0 -0
- package/dist/frontend-core/template/public/apple-touch-icon.png +0 -0
- package/dist/frontend-core/template/public/favicon-16x16.png +0 -0
- package/dist/frontend-core/template/public/favicon-32x32.png +0 -0
- package/dist/frontend-core/template/public/favicon.ico +0 -0
- package/dist/frontend-core/template/public/flags/AC.svg +39 -0
- package/dist/frontend-core/template/public/flags/AD.svg +32 -0
- package/dist/frontend-core/template/public/flags/AE.svg +7 -0
- package/dist/frontend-core/template/public/flags/AF.svg +9 -0
- package/dist/frontend-core/template/public/flags/AG.svg +13 -0
- package/dist/frontend-core/template/public/flags/AI.svg +31 -0
- package/dist/frontend-core/template/public/flags/AL.svg +22 -0
- package/dist/frontend-core/template/public/flags/AM.svg +6 -0
- package/dist/frontend-core/template/public/flags/AO.svg +24 -0
- package/dist/frontend-core/template/public/flags/AQ.svg +6 -0
- package/dist/frontend-core/template/public/flags/AR.svg +7 -0
- package/dist/frontend-core/template/public/flags/AS.svg +9 -0
- package/dist/frontend-core/template/public/flags/AT.svg +6 -0
- package/dist/frontend-core/template/public/flags/AU.svg +36 -0
- package/dist/frontend-core/template/public/flags/AW.svg +12 -0
- package/dist/frontend-core/template/public/flags/AX.svg +8 -0
- package/dist/frontend-core/template/public/flags/AZ.svg +13 -0
- package/dist/frontend-core/template/public/flags/BA.svg +23 -0
- package/dist/frontend-core/template/public/flags/BB.svg +11 -0
- package/dist/frontend-core/template/public/flags/BD.svg +5 -0
- package/dist/frontend-core/template/public/flags/BE.svg +7 -0
- package/dist/frontend-core/template/public/flags/BF.svg +7 -0
- package/dist/frontend-core/template/public/flags/BG.svg +7 -0
- package/dist/frontend-core/template/public/flags/BH.svg +8 -0
- package/dist/frontend-core/template/public/flags/BI.svg +21 -0
- package/dist/frontend-core/template/public/flags/BJ.svg +7 -0
- package/dist/frontend-core/template/public/flags/BL.svg +48 -0
- package/dist/frontend-core/template/public/flags/BM.svg +24 -0
- package/dist/frontend-core/template/public/flags/BN.svg +17 -0
- package/dist/frontend-core/template/public/flags/BO.svg +1 -0
- package/dist/frontend-core/template/public/flags/BQ.svg +9 -0
- package/dist/frontend-core/template/public/flags/BR.svg +10 -0
- package/dist/frontend-core/template/public/flags/BS.svg +10 -0
- package/dist/frontend-core/template/public/flags/BT.svg +7 -0
- package/dist/frontend-core/template/public/flags/BV.svg +10 -0
- package/dist/frontend-core/template/public/flags/BW.svg +10 -0
- package/dist/frontend-core/template/public/flags/BY.svg +19 -0
- package/dist/frontend-core/template/public/flags/BZ.svg +17 -0
- package/dist/frontend-core/template/public/flags/CA.svg +11 -0
- package/dist/frontend-core/template/public/flags/CC.svg +25 -0
- package/dist/frontend-core/template/public/flags/CD.svg +8 -0
- package/dist/frontend-core/template/public/flags/CF.svg +18 -0
- package/dist/frontend-core/template/public/flags/CG.svg +7 -0
- package/dist/frontend-core/template/public/flags/CH.svg +6 -0
- package/dist/frontend-core/template/public/flags/CI.svg +7 -0
- package/dist/frontend-core/template/public/flags/CK.svg +26 -0
- package/dist/frontend-core/template/public/flags/CL.svg +7 -0
- package/dist/frontend-core/template/public/flags/CM.svg +10 -0
- package/dist/frontend-core/template/public/flags/CN.svg +16 -0
- package/dist/frontend-core/template/public/flags/CO.svg +7 -0
- package/dist/frontend-core/template/public/flags/CR.svg +10 -0
- package/dist/frontend-core/template/public/flags/CU.svg +14 -0
- package/dist/frontend-core/template/public/flags/CV.svg +31 -0
- package/dist/frontend-core/template/public/flags/CW.svg +11 -0
- package/dist/frontend-core/template/public/flags/CX.svg +25 -0
- package/dist/frontend-core/template/public/flags/CY.svg +35 -0
- package/dist/frontend-core/template/public/flags/CZ.svg +7 -0
- package/dist/frontend-core/template/public/flags/DE.svg +7 -0
- package/dist/frontend-core/template/public/flags/DJ.svg +8 -0
- package/dist/frontend-core/template/public/flags/DK.svg +6 -0
- package/dist/frontend-core/template/public/flags/DM.svg +38 -0
- package/dist/frontend-core/template/public/flags/DO.svg +14 -0
- package/dist/frontend-core/template/public/flags/DZ.svg +12 -0
- package/dist/frontend-core/template/public/flags/EC.svg +12 -0
- package/dist/frontend-core/template/public/flags/EE.svg +7 -0
- package/dist/frontend-core/template/public/flags/EG.svg +10 -0
- package/dist/frontend-core/template/public/flags/EH.svg +13 -0
- package/dist/frontend-core/template/public/flags/ER.svg +17 -0
- package/dist/frontend-core/template/public/flags/ES.svg +13 -0
- package/dist/frontend-core/template/public/flags/ET.svg +24 -0
- package/dist/frontend-core/template/public/flags/EU.svg +1 -0
- package/dist/frontend-core/template/public/flags/FI.svg +6 -0
- package/dist/frontend-core/template/public/flags/FJ.svg +22 -0
- package/dist/frontend-core/template/public/flags/FK.svg +41 -0
- package/dist/frontend-core/template/public/flags/FM.svg +14 -0
- package/dist/frontend-core/template/public/flags/FO.svg +8 -0
- package/dist/frontend-core/template/public/flags/FR.svg +7 -0
- package/dist/frontend-core/template/public/flags/G.svg +4 -0
- package/dist/frontend-core/template/public/flags/GA.svg +7 -0
- package/dist/frontend-core/template/public/flags/GB.svg +30 -0
- package/dist/frontend-core/template/public/flags/GD.svg +32 -0
- package/dist/frontend-core/template/public/flags/GE-AB.svg +20 -0
- package/dist/frontend-core/template/public/flags/GE-OS.svg +6 -0
- package/dist/frontend-core/template/public/flags/GE.svg +9 -0
- package/dist/frontend-core/template/public/flags/GF.svg +6 -0
- package/dist/frontend-core/template/public/flags/GG.svg +6 -0
- package/dist/frontend-core/template/public/flags/GH.svg +8 -0
- package/dist/frontend-core/template/public/flags/GI.svg +19 -0
- package/dist/frontend-core/template/public/flags/GL.svg +7 -0
- package/dist/frontend-core/template/public/flags/GM.svg +7 -0
- package/dist/frontend-core/template/public/flags/GN.svg +6 -0
- package/dist/frontend-core/template/public/flags/GP.svg +7 -0
- package/dist/frontend-core/template/public/flags/GQ.svg +25 -0
- package/dist/frontend-core/template/public/flags/GR.svg +16 -0
- package/dist/frontend-core/template/public/flags/GS.svg +35 -0
- package/dist/frontend-core/template/public/flags/GT.svg +13 -0
- package/dist/frontend-core/template/public/flags/GU.svg +16 -0
- package/dist/frontend-core/template/public/flags/GW.svg +8 -0
- package/dist/frontend-core/template/public/flags/GY.svg +8 -0
- package/dist/frontend-core/template/public/flags/HK.svg +1 -0
- package/dist/frontend-core/template/public/flags/HM.svg +28 -0
- package/dist/frontend-core/template/public/flags/HN.svg +18 -0
- package/dist/frontend-core/template/public/flags/HR.svg +32 -0
- package/dist/frontend-core/template/public/flags/HT.svg +11 -0
- package/dist/frontend-core/template/public/flags/HU.svg +7 -0
- package/dist/frontend-core/template/public/flags/IC.svg +6 -0
- package/dist/frontend-core/template/public/flags/ID.svg +6 -0
- package/dist/frontend-core/template/public/flags/IE.svg +7 -0
- package/dist/frontend-core/template/public/flags/IL.svg +12 -0
- package/dist/frontend-core/template/public/flags/IM.svg +17 -0
- package/dist/frontend-core/template/public/flags/IN.svg +11 -0
- package/dist/frontend-core/template/public/flags/IO.svg +70 -0
- package/dist/frontend-core/template/public/flags/IQ.svg +13 -0
- package/dist/frontend-core/template/public/flags/IR.svg +37 -0
- package/dist/frontend-core/template/public/flags/IS.svg +7 -0
- package/dist/frontend-core/template/public/flags/IT.svg +7 -0
- package/dist/frontend-core/template/public/flags/JE.svg +9 -0
- package/dist/frontend-core/template/public/flags/JM.svg +9 -0
- package/dist/frontend-core/template/public/flags/JO.svg +9 -0
- package/dist/frontend-core/template/public/flags/JP.svg +6 -0
- package/dist/frontend-core/template/public/flags/KE.svg +18 -0
- package/dist/frontend-core/template/public/flags/KG.svg +21 -0
- package/dist/frontend-core/template/public/flags/KH.svg +10 -0
- package/dist/frontend-core/template/public/flags/KI.svg +24 -0
- package/dist/frontend-core/template/public/flags/KM.svg +16 -0
- package/dist/frontend-core/template/public/flags/KN.svg +13 -0
- package/dist/frontend-core/template/public/flags/KP.svg +13 -0
- package/dist/frontend-core/template/public/flags/KR.svg +21 -0
- package/dist/frontend-core/template/public/flags/KW.svg +8 -0
- package/dist/frontend-core/template/public/flags/KY.svg +24 -0
- package/dist/frontend-core/template/public/flags/KZ.svg +28 -0
- package/dist/frontend-core/template/public/flags/LA.svg +9 -0
- package/dist/frontend-core/template/public/flags/LB.svg +15 -0
- package/dist/frontend-core/template/public/flags/LC.svg +7 -0
- package/dist/frontend-core/template/public/flags/LI.svg +8 -0
- package/dist/frontend-core/template/public/flags/LICENSE +22 -0
- package/dist/frontend-core/template/public/flags/LK.svg +30 -0
- package/dist/frontend-core/template/public/flags/LR.svg +13 -0
- package/dist/frontend-core/template/public/flags/LS.svg +10 -0
- package/dist/frontend-core/template/public/flags/LT.svg +7 -0
- package/dist/frontend-core/template/public/flags/LU.svg +7 -0
- package/dist/frontend-core/template/public/flags/LV.svg +8 -0
- package/dist/frontend-core/template/public/flags/LY.svg +11 -0
- package/dist/frontend-core/template/public/flags/MA.svg +6 -0
- package/dist/frontend-core/template/public/flags/MC.svg +6 -0
- package/dist/frontend-core/template/public/flags/MD.svg +8 -0
- package/dist/frontend-core/template/public/flags/ME.svg +26 -0
- package/dist/frontend-core/template/public/flags/MF.svg +7 -0
- package/dist/frontend-core/template/public/flags/MG.svg +7 -0
- package/dist/frontend-core/template/public/flags/MH.svg +9 -0
- package/dist/frontend-core/template/public/flags/MK.svg +17 -0
- package/dist/frontend-core/template/public/flags/ML.svg +7 -0
- package/dist/frontend-core/template/public/flags/MM.svg +8 -0
- package/dist/frontend-core/template/public/flags/MN.svg +17 -0
- package/dist/frontend-core/template/public/flags/MO.svg +17 -0
- package/dist/frontend-core/template/public/flags/MP.svg +12 -0
- package/dist/frontend-core/template/public/flags/MQ.svg +44 -0
- package/dist/frontend-core/template/public/flags/MR.svg +9 -0
- package/dist/frontend-core/template/public/flags/MS.svg +21 -0
- package/dist/frontend-core/template/public/flags/MT.svg +7 -0
- package/dist/frontend-core/template/public/flags/MU.svg +8 -0
- package/dist/frontend-core/template/public/flags/MV.svg +7 -0
- package/dist/frontend-core/template/public/flags/MW.svg +8 -0
- package/dist/frontend-core/template/public/flags/MX.svg +11 -0
- package/dist/frontend-core/template/public/flags/MY.svg +19 -0
- package/dist/frontend-core/template/public/flags/MZ.svg +10 -0
- package/dist/frontend-core/template/public/flags/NA.svg +9 -0
- package/dist/frontend-core/template/public/flags/NC.svg +16 -0
- package/dist/frontend-core/template/public/flags/NE.svg +8 -0
- package/dist/frontend-core/template/public/flags/NF.svg +10 -0
- package/dist/frontend-core/template/public/flags/NG.svg +9 -0
- package/dist/frontend-core/template/public/flags/NI.svg +13 -0
- package/dist/frontend-core/template/public/flags/NL.svg +7 -0
- package/dist/frontend-core/template/public/flags/NO.svg +7 -0
- package/dist/frontend-core/template/public/flags/NP.svg +12 -0
- package/dist/frontend-core/template/public/flags/NR.svg +7 -0
- package/dist/frontend-core/template/public/flags/NU.svg +47 -0
- package/dist/frontend-core/template/public/flags/NZ.svg +25 -0
- package/dist/frontend-core/template/public/flags/OM.svg +12 -0
- package/dist/frontend-core/template/public/flags/PA.svg +9 -0
- package/dist/frontend-core/template/public/flags/PE.svg +9 -0
- package/dist/frontend-core/template/public/flags/PF.svg +16 -0
- package/dist/frontend-core/template/public/flags/PG.svg +14 -0
- package/dist/frontend-core/template/public/flags/PH.svg +15 -0
- package/dist/frontend-core/template/public/flags/PK.svg +13 -0
- package/dist/frontend-core/template/public/flags/PL.svg +9 -0
- package/dist/frontend-core/template/public/flags/PM.svg +7 -0
- package/dist/frontend-core/template/public/flags/PN.svg +23 -0
- package/dist/frontend-core/template/public/flags/PR.svg +12 -0
- package/dist/frontend-core/template/public/flags/PS.svg +8 -0
- package/dist/frontend-core/template/public/flags/PT.svg +9 -0
- package/dist/frontend-core/template/public/flags/PW.svg +6 -0
- package/dist/frontend-core/template/public/flags/PY.svg +9 -0
- package/dist/frontend-core/template/public/flags/QA.svg +7 -0
- package/dist/frontend-core/template/public/flags/RE.svg +7 -0
- package/dist/frontend-core/template/public/flags/README.md +1 -0
- package/dist/frontend-core/template/public/flags/RO.svg +7 -0
- package/dist/frontend-core/template/public/flags/RS.svg +13 -0
- package/dist/frontend-core/template/public/flags/RU.svg +8 -0
- package/dist/frontend-core/template/public/flags/RW.svg +8 -0
- package/dist/frontend-core/template/public/flags/SA.svg +12 -0
- package/dist/frontend-core/template/public/flags/SB.svg +14 -0
- package/dist/frontend-core/template/public/flags/SC.svg +9 -0
- package/dist/frontend-core/template/public/flags/SD.svg +8 -0
- package/dist/frontend-core/template/public/flags/SE.svg +6 -0
- package/dist/frontend-core/template/public/flags/SG.svg +14 -0
- package/dist/frontend-core/template/public/flags/SH.svg +32 -0
- package/dist/frontend-core/template/public/flags/SI.svg +10 -0
- package/dist/frontend-core/template/public/flags/SJ.svg +7 -0
- package/dist/frontend-core/template/public/flags/SK.svg +11 -0
- package/dist/frontend-core/template/public/flags/SL.svg +7 -0
- package/dist/frontend-core/template/public/flags/SM.svg +11 -0
- package/dist/frontend-core/template/public/flags/SN.svg +10 -0
- package/dist/frontend-core/template/public/flags/SO.svg +6 -0
- package/dist/frontend-core/template/public/flags/SR.svg +11 -0
- package/dist/frontend-core/template/public/flags/SS.svg +10 -0
- package/dist/frontend-core/template/public/flags/ST.svg +12 -0
- package/dist/frontend-core/template/public/flags/SV.svg +12 -0
- package/dist/frontend-core/template/public/flags/SX.svg +14 -0
- package/dist/frontend-core/template/public/flags/SY.svg +11 -0
- package/dist/frontend-core/template/public/flags/SZ.svg +12 -0
- package/dist/frontend-core/template/public/flags/TA.svg +38 -0
- package/dist/frontend-core/template/public/flags/TC.svg +24 -0
- package/dist/frontend-core/template/public/flags/TD.svg +7 -0
- package/dist/frontend-core/template/public/flags/TF.svg +14 -0
- package/dist/frontend-core/template/public/flags/TG.svg +12 -0
- package/dist/frontend-core/template/public/flags/TH.svg +10 -0
- package/dist/frontend-core/template/public/flags/TJ.svg +17 -0
- package/dist/frontend-core/template/public/flags/TK.svg +15 -0
- package/dist/frontend-core/template/public/flags/TL.svg +8 -0
- package/dist/frontend-core/template/public/flags/TM.svg +34 -0
- package/dist/frontend-core/template/public/flags/TN.svg +10 -0
- package/dist/frontend-core/template/public/flags/TO.svg +7 -0
- package/dist/frontend-core/template/public/flags/TR.svg +8 -0
- package/dist/frontend-core/template/public/flags/TT.svg +7 -0
- package/dist/frontend-core/template/public/flags/TV.svg +21 -0
- package/dist/frontend-core/template/public/flags/TW.svg +9 -0
- package/dist/frontend-core/template/public/flags/TZ.svg +8 -0
- package/dist/frontend-core/template/public/flags/UA.svg +6 -0
- package/dist/frontend-core/template/public/flags/UG.svg +15 -0
- package/dist/frontend-core/template/public/flags/UK.svg +30 -0
- package/dist/frontend-core/template/public/flags/UM.svg +40 -0
- package/dist/frontend-core/template/public/flags/US.svg +40 -0
- package/dist/frontend-core/template/public/flags/UY.svg +17 -0
- package/dist/frontend-core/template/public/flags/UZ.svg +26 -0
- package/dist/frontend-core/template/public/flags/VA.svg +8 -0
- package/dist/frontend-core/template/public/flags/VC.svg +12 -0
- package/dist/frontend-core/template/public/flags/VE.svg +21 -0
- package/dist/frontend-core/template/public/flags/VG.svg +33 -0
- package/dist/frontend-core/template/public/flags/VI.svg +31 -0
- package/dist/frontend-core/template/public/flags/VN.svg +6 -0
- package/dist/frontend-core/template/public/flags/VU.svg +14 -0
- package/dist/frontend-core/template/public/flags/WF.svg +9 -0
- package/dist/frontend-core/template/public/flags/WS.svg +13 -0
- package/dist/frontend-core/template/public/flags/XK.svg +20 -0
- package/dist/frontend-core/template/public/flags/YE.svg +7 -0
- package/dist/frontend-core/template/public/flags/YT.svg +22 -0
- package/dist/frontend-core/template/public/flags/ZA.svg +10 -0
- package/dist/frontend-core/template/public/flags/ZM.svg +9 -0
- package/dist/frontend-core/template/public/flags/ZW.svg +19 -0
- package/dist/frontend-core/template/public/silent-check-sso.html +12 -0
- package/dist/frontend-core/template/public/site.webmanifest +1 -0
- package/dist/frontend-core/template/src/components/ui/accordion/accordion.stories.tsx +47 -0
- package/dist/frontend-core/template/src/components/ui/accordion/accordion.tsx +52 -0
- package/dist/frontend-core/template/src/components/ui/admin-sidebar/admin-sidebar.tsx +195 -0
- package/dist/frontend-core/template/src/components/ui/alert/alert.stories.tsx +61 -0
- package/dist/frontend-core/template/src/components/ui/alert/alert.tsx +45 -0
- package/dist/frontend-core/template/src/components/ui/alert-dialog/alert-dialog.stories.tsx +52 -0
- package/dist/frontend-core/template/src/components/ui/alert-dialog/alert-dialog.tsx +105 -0
- package/dist/frontend-core/template/src/components/ui/avatar/avatar.stories.tsx +30 -0
- package/dist/frontend-core/template/src/components/ui/avatar/avatar.tsx +39 -0
- package/dist/frontend-core/template/src/components/ui/badge/badge.stories.tsx +78 -0
- package/dist/frontend-core/template/src/components/ui/badge/badge.tsx +48 -0
- package/dist/frontend-core/template/src/components/ui/breadcrumb/breadcrumb.stories.tsx +67 -0
- package/dist/frontend-core/template/src/components/ui/breadcrumb/breadcrumb.tsx +85 -0
- package/dist/frontend-core/template/src/components/ui/button/button.stories.tsx +150 -0
- package/dist/frontend-core/template/src/components/ui/button/button.tsx +68 -0
- package/dist/frontend-core/template/src/components/ui/calendar/calendar.stories.tsx +160 -0
- package/dist/frontend-core/template/src/components/ui/calendar/calendar.tsx +293 -0
- package/dist/frontend-core/template/src/components/ui/card/card.stories.tsx +77 -0
- package/dist/frontend-core/template/src/components/ui/card/card.tsx +45 -0
- package/dist/frontend-core/template/src/components/ui/card-hover/card-hover.stories.tsx +29 -0
- package/dist/frontend-core/template/src/components/ui/card-hover/card-hover.tsx +28 -0
- package/dist/frontend-core/template/src/components/ui/carousel/carousel.stories.tsx +154 -0
- package/dist/frontend-core/template/src/components/ui/carousel/carousel.tsx +227 -0
- package/dist/frontend-core/template/src/components/ui/chart/base.tsx +304 -0
- package/dist/frontend-core/template/src/components/ui/chart/index.ts +2 -0
- package/dist/frontend-core/template/src/components/ui/chart/line.stories.tsx +230 -0
- package/dist/frontend-core/template/src/components/ui/chart/line.tsx +121 -0
- package/dist/frontend-core/template/src/components/ui/chart/util.ts +3 -0
- package/dist/frontend-core/template/src/components/ui/checkbox/checkbox.stories.tsx +105 -0
- package/dist/frontend-core/template/src/components/ui/checkbox/checkbox.tsx +79 -0
- package/dist/frontend-core/template/src/components/ui/checkbox/shadcn-checkbox.stories.tsx +90 -0
- package/dist/frontend-core/template/src/components/ui/checkbox/shadcn-checkbox.tsx +54 -0
- package/dist/frontend-core/template/src/components/ui/collapse/collapse.stories.tsx +52 -0
- package/dist/frontend-core/template/src/components/ui/collapse/collapse.tsx +9 -0
- package/dist/frontend-core/template/src/components/ui/combobox/combobox.stories.tsx +207 -0
- package/dist/frontend-core/template/src/components/ui/combobox/combobox.tsx +79 -0
- package/dist/frontend-core/template/src/components/ui/command/command.stories.tsx +186 -0
- package/dist/frontend-core/template/src/components/ui/command/command.tsx +165 -0
- package/dist/frontend-core/template/src/components/ui/command-palette/command-palette.stories.tsx +160 -0
- package/dist/frontend-core/template/src/components/ui/command-palette/command-palette.tsx +134 -0
- package/dist/frontend-core/template/src/components/ui/content-frame/content-frame.stories.tsx +198 -0
- package/dist/frontend-core/template/src/components/ui/content-frame/content-frame.tsx +100 -0
- package/dist/frontend-core/template/src/components/ui/context-menu/context-menu.stories.tsx +78 -0
- package/dist/frontend-core/template/src/components/ui/context-menu/context-menu.tsx +179 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/cell-variant-types.ts +11 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/checkbox-cell.tsx +112 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/date-cell.tsx +158 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/gantt-cell.tsx +80 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/long-text-cell.tsx +179 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/multi-select-cell.tsx +284 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/number-cell.tsx +167 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/react-node-cell.tsx +32 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/select-cell.tsx +175 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/short-text-cell.tsx +137 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/utils/gantt-timeline.tsx +91 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/cell-variants/utils/gantt-timerange-picker.tsx +330 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-cell-wrapper.tsx +212 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-cell.tsx +156 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-column-header.tsx +317 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-context-menu.tsx +262 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-row.tsx +123 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-search.tsx +211 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-types.ts +151 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-utils.ts +78 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid-view-menu.tsx +360 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/data-grid.tsx +217 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/hooks/use-callback-ref.ts +22 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/hooks/use-data-grid.tsx +1888 -0
- package/dist/frontend-core/template/src/components/ui/data-grid/hooks/use-debounced-callback.ts +19 -0
- package/dist/frontend-core/template/src/components/ui/data-table/context-menu-simple.tsx +141 -0
- package/dist/frontend-core/template/src/components/ui/data-table/data-table.stories.tsx +146 -0
- package/dist/frontend-core/template/src/components/ui/data-table/data-table.tsx +448 -0
- package/dist/frontend-core/template/src/components/ui/data-table/renderers/country-array-cell-renderer.tsx +77 -0
- package/dist/frontend-core/template/src/components/ui/data-table/renderers/country-cell-renderer.tsx +56 -0
- package/dist/frontend-core/template/src/components/ui/data-table/renderers/favorite-cell-renderer.tsx +68 -0
- package/dist/frontend-core/template/src/components/ui/data-table/renderers/links-cell-renderer.tsx +205 -0
- package/dist/frontend-core/template/src/components/ui/data-table/utils/columns.ts +351 -0
- package/dist/frontend-core/template/src/components/ui/data-table/utils/data-table.utils.ts +49 -0
- package/dist/frontend-core/template/src/components/ui/date-picker/date-picker.stories.tsx +149 -0
- package/dist/frontend-core/template/src/components/ui/date-picker/date-picker.tsx +30 -0
- package/dist/frontend-core/template/src/components/ui/dialog/dialog.stories.tsx +80 -0
- package/dist/frontend-core/template/src/components/ui/dialog/dialog.tsx +134 -0
- package/dist/frontend-core/template/src/components/ui/drawer/drawer.stories.tsx +104 -0
- package/dist/frontend-core/template/src/components/ui/drawer/drawer.tsx +87 -0
- package/dist/frontend-core/template/src/components/ui/dropdown-menu/dropdown-menu.stories.tsx +168 -0
- package/dist/frontend-core/template/src/components/ui/dropdown-menu/dropdown-menu.tsx +225 -0
- package/dist/frontend-core/template/src/components/ui/input/input.stories.tsx +141 -0
- package/dist/frontend-core/template/src/components/ui/input/input.tsx +47 -0
- package/dist/frontend-core/template/src/components/ui/label/label.stories.tsx +41 -0
- package/dist/frontend-core/template/src/components/ui/label/label.tsx +20 -0
- package/dist/frontend-core/template/src/components/ui/loader/loader.stories.tsx +45 -0
- package/dist/frontend-core/template/src/components/ui/loader/loader.tsx +17 -0
- package/dist/frontend-core/template/src/components/ui/mark-value-renderer/mark-value-renderer.stories.tsx +114 -0
- package/dist/frontend-core/template/src/components/ui/mark-value-renderer/mark-value-renderer.tsx +48 -0
- package/dist/frontend-core/template/src/components/ui/menubar/menu.stories.tsx +134 -0
- package/dist/frontend-core/template/src/components/ui/menubar/menubar.tsx +208 -0
- package/dist/frontend-core/template/src/components/ui/modal/modal.stories.tsx +297 -0
- package/dist/frontend-core/template/src/components/ui/modal/modal.tsx +80 -0
- package/dist/frontend-core/template/src/components/ui/navigation-menu/navigation-menu.stories.tsx +213 -0
- package/dist/frontend-core/template/src/components/ui/navigation-menu/navigation-menu.tsx +142 -0
- package/dist/frontend-core/template/src/components/ui/pagination/pagination.stories.tsx +49 -0
- package/dist/frontend-core/template/src/components/ui/pagination/pagination.tsx +84 -0
- package/dist/frontend-core/template/src/components/ui/popover/popover.stories.tsx +82 -0
- package/dist/frontend-core/template/src/components/ui/popover/popover.tsx +55 -0
- package/dist/frontend-core/template/src/components/ui/progress/progress.stories.tsx +80 -0
- package/dist/frontend-core/template/src/components/ui/progress/progress.tsx +17 -0
- package/dist/frontend-core/template/src/components/ui/radio-group/radio-group.stories.tsx +154 -0
- package/dist/frontend-core/template/src/components/ui/radio-group/radio-group.tsx +68 -0
- package/dist/frontend-core/template/src/components/ui/resizable/resizable.stories.tsx +73 -0
- package/dist/frontend-core/template/src/components/ui/resizable/resizeable.tsx +38 -0
- package/dist/frontend-core/template/src/components/ui/scroll-area/scroll-area.stories.tsx +55 -0
- package/dist/frontend-core/template/src/components/ui/scroll-area/scroll-area.tsx +39 -0
- package/dist/frontend-core/template/src/components/ui/select/select.stories.tsx +297 -0
- package/dist/frontend-core/template/src/components/ui/select/select.tsx +227 -0
- package/dist/frontend-core/template/src/components/ui/separator/separator.tsx +21 -0
- package/dist/frontend-core/template/src/components/ui/separator/seperator.stories.tsx +25 -0
- package/dist/frontend-core/template/src/components/ui/sheet/sheet.stories.tsx +45 -0
- package/dist/frontend-core/template/src/components/ui/sheet/sheet.tsx +107 -0
- package/dist/frontend-core/template/src/components/ui/skeleton/skeleton.stories.tsx +26 -0
- package/dist/frontend-core/template/src/components/ui/skeleton/skeleton.tsx +7 -0
- package/dist/frontend-core/template/src/components/ui/slider/slider.stories.tsx +101 -0
- package/dist/frontend-core/template/src/components/ui/slider/slider.tsx +98 -0
- package/dist/frontend-core/template/src/components/ui/spinner/spinner.stories.tsx +19 -0
- package/dist/frontend-core/template/src/components/ui/spinner/spinner.tsx +21 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/engine.ts +411 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/format.ts +79 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/index.tsx +201 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/model.json +2877 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/model.xlsm +0 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/parser.ts +307 -0
- package/dist/frontend-core/template/src/components/ui/spreadsheet/types.ts +69 -0
- package/dist/frontend-core/template/src/components/ui/switch/switch.stories.tsx +33 -0
- package/dist/frontend-core/template/src/components/ui/switch/switch.tsx +28 -0
- package/dist/frontend-core/template/src/components/ui/tabs/tabs.stories.tsx +215 -0
- package/dist/frontend-core/template/src/components/ui/tabs/tabs.tsx +70 -0
- package/dist/frontend-core/template/src/components/ui/textarea/textarea.stories.tsx +138 -0
- package/dist/frontend-core/template/src/components/ui/textarea/textarea.tsx +40 -0
- package/dist/frontend-core/template/src/components/ui/toast/toast.mdx +31 -0
- package/dist/frontend-core/template/src/components/ui/toast/toast.stories.tsx +89 -0
- package/dist/frontend-core/template/src/components/ui/toggle/toggle.stories.tsx +65 -0
- package/dist/frontend-core/template/src/components/ui/toggle/toggle.tsx +38 -0
- package/dist/frontend-core/template/src/components/ui/toggle-group/toggle-group.stories.tsx +85 -0
- package/dist/frontend-core/template/src/components/ui/toggle-group/toggle-group.tsx +54 -0
- package/dist/frontend-core/template/src/components/ui/tooltip/tooltip.stories.tsx +29 -0
- package/dist/frontend-core/template/src/components/ui/tooltip/tooltip.tsx +29 -0
- package/dist/frontend-core/template/src/context-providers/auth-context-provider.tsx +210 -0
- package/dist/frontend-core/template/src/context-providers/theme-context-provider.tsx +107 -0
- package/dist/frontend-core/template/src/hooks/useDelay.ts +17 -0
- package/dist/frontend-core/template/src/hooks/useFontsLoaded.ts +17 -0
- package/dist/frontend-core/template/src/hooks/useMediaQuery.ts +28 -0
- package/dist/frontend-core/template/src/hooks/useScreenSize.ts +37 -0
- package/dist/frontend-core/template/src/hooks/useScrollLock.tsx +93 -0
- package/dist/frontend-core/template/src/hooks/useWindowFocus.ts +30 -0
- package/dist/frontend-core/template/src/lib/color.ts +277 -0
- package/dist/frontend-core/template/src/lib/compose-refs.ts +62 -0
- package/dist/frontend-core/template/src/lib/config.ts +77 -0
- package/dist/frontend-core/template/src/lib/query-client.ts +25 -0
- package/dist/frontend-core/template/src/lib/react.ts +25 -0
- package/dist/frontend-core/template/src/lib/router.tsx +26 -0
- package/dist/frontend-core/template/src/lib/types.ts +9 -0
- package/dist/frontend-core/template/src/lib/utils.ts +33 -0
- package/dist/frontend-core/template/src/main.tsx +48 -0
- package/dist/frontend-core/template/src/pages/dashboard/dashboard.page.tsx +97 -0
- package/dist/frontend-core/template/src/pages/error/default-error.page.tsx +20 -0
- package/dist/frontend-core/template/src/pages/error/not-found-error.page.tsx +17 -0
- package/dist/frontend-core/template/src/pages/login/login.page.tsx +50 -0
- package/dist/frontend-core/template/src/pages/root-document.tsx +62 -0
- package/dist/frontend-core/template/src/pages/unauthorized/unauthorized.page.tsx +12 -0
- package/dist/frontend-core/template/src/routes/__root.tsx +79 -0
- package/dist/frontend-core/template/src/routes/_auth-routes/dashboard.lazy.tsx +6 -0
- package/dist/frontend-core/template/src/routes/_auth-routes.tsx +19 -0
- package/dist/frontend-core/template/src/routes/index.tsx +8 -0
- package/dist/frontend-core/template/src/routes/login.tsx +6 -0
- package/dist/frontend-core/template/src/routes/unauthorized.tsx +6 -0
- package/dist/frontend-core/template/src/stories/Configure.mdx +363 -0
- package/dist/frontend-core/template/src/stories/assets/accessibility.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/accessibility.svg +1 -0
- package/dist/frontend-core/template/src/stories/assets/addon-library.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/assets.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/avif-test-image.avif +0 -0
- package/dist/frontend-core/template/src/stories/assets/context.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/discord.svg +1 -0
- package/dist/frontend-core/template/src/stories/assets/docs.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/figma-plugin.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/github.svg +1 -0
- package/dist/frontend-core/template/src/stories/assets/share.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/styling.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/testing.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/theming.png +0 -0
- package/dist/frontend-core/template/src/stories/assets/tutorials.svg +1 -0
- package/dist/frontend-core/template/src/stories/assets/youtube.svg +1 -0
- package/dist/frontend-core/template/src/styles/styles.css +33 -0
- package/dist/frontend-core/template/src/styles/theme-default.css +183 -0
- package/dist/frontend-core/template/src/vite-env.d.ts +2 -0
- package/dist/frontend-core/template/tsconfig.json +103 -0
- package/dist/frontend-core/template/vite.config.ts +167 -0
- package/dist/frontend-core/template/vitest.shims.d.ts +1 -0
- package/dist/frontend-core/types/component.d.ts +1 -0
- package/dist/frontend-core/types/component.js +3 -0
- package/dist/frontend-core/types/component.js.map +1 -0
- package/dist/frontend-core/types/contextprovider.d.ts +1 -0
- package/dist/frontend-core/types/contextprovider.js +3 -0
- package/dist/frontend-core/types/contextprovider.js.map +1 -0
- package/dist/frontend-core/types/hook.d.ts +1 -0
- package/dist/frontend-core/types/hook.js +3 -0
- package/dist/frontend-core/types/hook.js.map +1 -0
- package/dist/frontend-core/types.d.ts +35 -0
- package/dist/frontend-core/types.js +3 -0
- package/dist/frontend-core/types.js.map +1 -0
- package/dist/frontend-forms/forms.generator.d.ts +54 -0
- package/dist/frontend-forms/forms.generator.js +190 -0
- package/dist/frontend-forms/forms.generator.js.map +1 -0
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.d.ts +11 -0
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.js +310 -0
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.js.map +1 -0
- package/dist/frontend-forms/generators/discriminated-union/inputs.generator.d.ts +7 -0
- package/dist/frontend-forms/generators/discriminated-union/inputs.generator.js +69 -0
- package/dist/frontend-forms/generators/discriminated-union/inputs.generator.js.map +1 -0
- package/dist/frontend-forms/generators/enum/inputs.generator.d.ts +5 -0
- package/dist/frontend-forms/generators/enum/inputs.generator.js +69 -0
- package/dist/frontend-forms/generators/enum/inputs.generator.js.map +1 -0
- package/dist/frontend-forms/generators/model/forms.generator.d.ts +11 -0
- package/dist/frontend-forms/generators/model/forms.generator.js +549 -0
- package/dist/frontend-forms/generators/model/forms.generator.js.map +1 -0
- package/dist/frontend-forms/generators/model/inputs.generator.d.ts +5 -0
- package/dist/frontend-forms/generators/model/inputs.generator.js +148 -0
- package/dist/frontend-forms/generators/model/inputs.generator.js.map +1 -0
- package/dist/frontend-forms/index.d.ts +5 -0
- package/dist/frontend-forms/index.js +40 -0
- package/dist/frontend-forms/index.js.map +1 -0
- package/dist/frontend-forms/template/src/components/ui/field/field.tsx +226 -0
- package/dist/frontend-tables/generators/model-context.generator.d.ts +5 -0
- package/dist/frontend-tables/generators/model-context.generator.js +72 -0
- package/dist/frontend-tables/generators/model-context.generator.js.map +1 -0
- package/dist/frontend-tables/generators/model-table.generator.d.ts +5 -0
- package/dist/frontend-tables/generators/model-table.generator.js +339 -0
- package/dist/frontend-tables/generators/model-table.generator.js.map +1 -0
- package/dist/frontend-tables/index.d.ts +5 -0
- package/dist/frontend-tables/index.js +40 -0
- package/dist/frontend-tables/index.js.map +1 -0
- package/dist/frontend-tables/tables.generator.d.ts +49 -0
- package/dist/frontend-tables/tables.generator.js +104 -0
- package/dist/frontend-tables/tables.generator.js.map +1 -0
- package/dist/frontend-trpc-client/generators/model-hook.generator.d.ts +5 -0
- package/dist/frontend-trpc-client/generators/model-hook.generator.js +107 -0
- package/dist/frontend-trpc-client/generators/model-hook.generator.js.map +1 -0
- package/dist/frontend-trpc-client/generators/trpc-client.generator.d.ts +5 -0
- package/dist/frontend-trpc-client/generators/trpc-client.generator.js +64 -0
- package/dist/frontend-trpc-client/generators/trpc-client.generator.js.map +1 -0
- package/dist/frontend-trpc-client/index.d.ts +4 -0
- package/dist/frontend-trpc-client/index.js +40 -0
- package/dist/frontend-trpc-client/index.js.map +1 -0
- package/dist/frontend-trpc-client/trpc-client.generator.d.ts +82 -0
- package/dist/frontend-trpc-client/trpc-client.generator.js +125 -0
- package/dist/frontend-trpc-client/trpc-client.generator.js.map +1 -0
- package/dist/generators.d.ts +2 -0
- package/dist/generators.js +59 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -0
- package/dist/mock-data/generators/data-mocker.generator.d.ts +2 -0
- package/dist/mock-data/generators/data-mocker.generator.js +235 -0
- package/dist/mock-data/generators/data-mocker.generator.js.map +1 -0
- package/dist/mock-data/generators/id-tracker.generator.d.ts +2 -0
- package/dist/mock-data/generators/id-tracker.generator.js +101 -0
- package/dist/mock-data/generators/id-tracker.generator.js.map +1 -0
- package/dist/mock-data/generators/model-stub.generator.d.ts +10 -0
- package/dist/mock-data/generators/model-stub.generator.js +179 -0
- package/dist/mock-data/generators/model-stub.generator.js.map +1 -0
- package/dist/mock-data/index.d.ts +4 -0
- package/dist/mock-data/index.js +40 -0
- package/dist/mock-data/index.js.map +1 -0
- package/dist/mock-data/mock-data.generator.d.ts +34 -0
- package/dist/mock-data/mock-data.generator.js +121 -0
- package/dist/mock-data/mock-data.generator.js.map +1 -0
- package/dist/seed-data/generator/excel-template.generator.d.ts +8 -0
- package/dist/seed-data/generator/excel-template.generator.js +221 -0
- package/dist/seed-data/generator/excel-template.generator.js.map +1 -0
- package/dist/seed-data/generator/model-seed-data.generator.d.ts +15 -0
- package/dist/seed-data/generator/model-seed-data.generator.js +231 -0
- package/dist/seed-data/generator/model-seed-data.generator.js.map +1 -0
- package/dist/seed-data/generator/seed-migration-types.generator.d.ts +2 -0
- package/dist/seed-data/generator/seed-migration-types.generator.js +44 -0
- package/dist/seed-data/generator/seed-migration-types.generator.js.map +1 -0
- package/dist/seed-data/generator/seed-migrations.generator.d.ts +2 -0
- package/dist/seed-data/generator/seed-migrations.generator.js +57 -0
- package/dist/seed-data/generator/seed-migrations.generator.js.map +1 -0
- package/dist/seed-data/index.d.ts +5 -0
- package/dist/seed-data/index.js +40 -0
- package/dist/seed-data/index.js.map +1 -0
- package/dist/seed-data/seed-data.generator.d.ts +74 -0
- package/dist/seed-data/seed-data.generator.js +131 -0
- package/dist/seed-data/seed-data.generator.js.map +1 -0
- package/dist/types/generators/discriminated-union.generator.d.ts +6 -0
- package/dist/types/generators/discriminated-union.generator.js +86 -0
- package/dist/types/generators/discriminated-union.generator.js.map +1 -0
- package/dist/types/generators/dto-types.generator.d.ts +2 -0
- package/dist/types/generators/dto-types.generator.js +32 -0
- package/dist/types/generators/dto-types.generator.js.map +1 -0
- package/dist/types/generators/enum-type.generator.d.ts +2 -0
- package/dist/types/generators/enum-type.generator.js +65 -0
- package/dist/types/generators/enum-type.generator.js.map +1 -0
- package/dist/types/generators/model-type.generator.d.ts +13 -0
- package/dist/types/generators/model-type.generator.js +171 -0
- package/dist/types/generators/model-type.generator.js.map +1 -0
- package/dist/types/generators/models.generator.d.ts +2 -0
- package/dist/types/generators/models.generator.js +9 -0
- package/dist/types/generators/models.generator.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/types.generator.d.ts +179 -0
- package/dist/types/types.generator.js +220 -0
- package/dist/types/types.generator.js.map +1 -0
- package/dist/types/types.generator.mock.d.ts +2 -0
- package/dist/types/types.generator.mock.js +16 -0
- package/dist/types/types.generator.mock.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,1936 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateRepository_InMemory = exports.generateRepository_DatabaseDirect = exports.generateRepository_DatabaseCached = void 0;
|
|
37
|
+
const Generator = __importStar(require("@postxl/generator"));
|
|
38
|
+
const schema_1 = require("@postxl/schema");
|
|
39
|
+
const utils_1 = require("@postxl/utils");
|
|
40
|
+
/**
|
|
41
|
+
* Generates repository data structure for a given model that persists the data in the database and caches it in memory.
|
|
42
|
+
*/
|
|
43
|
+
const generateRepository_DatabaseCached = (model, context) => {
|
|
44
|
+
const { repository, types } = model;
|
|
45
|
+
const imports = new Generator.ImportGenerator({ path: repository.location })
|
|
46
|
+
.addType(types)
|
|
47
|
+
.addType(types.dto.create)
|
|
48
|
+
.addType(types.dto.update)
|
|
49
|
+
.addType(types.dto.upsert)
|
|
50
|
+
.addType(types.dto.clone)
|
|
51
|
+
.addType(types.id)
|
|
52
|
+
.addImport({
|
|
53
|
+
from: types.location,
|
|
54
|
+
items: [types.id.toBranded.name],
|
|
55
|
+
})
|
|
56
|
+
.addType(context.actions.execution.interface)
|
|
57
|
+
.addType(context.repositories.interface)
|
|
58
|
+
.add(context.database.service)
|
|
59
|
+
.add(model.decoder.flattened.decoder.parseFunction)
|
|
60
|
+
.add(model.decoder.flattened.encoder)
|
|
61
|
+
.addImport({
|
|
62
|
+
from: Generator.toPackageName('@postxl/utils'),
|
|
63
|
+
items: [
|
|
64
|
+
Generator.toFunctionName('format'),
|
|
65
|
+
Generator.toFunctionName('pluralize'),
|
|
66
|
+
Generator.toFunctionName('assertArray'),
|
|
67
|
+
],
|
|
68
|
+
})
|
|
69
|
+
.addImport({ from: Generator.toPackageName('async-mutex'), items: [Generator.toClassName('Mutex')] });
|
|
70
|
+
const params = { model, context, imports };
|
|
71
|
+
const idBlocks = generateIdBlocks_Database(params);
|
|
72
|
+
const defaultValueBlocks = generateDefaultBlocks(params);
|
|
73
|
+
const uniqueStringFieldsBlocks = generateUniqueFieldsBlocks_Cached(params);
|
|
74
|
+
const maxLengthBlocks = generateMaxLengthBlocks(params);
|
|
75
|
+
const validationBlocks = generateValidationBlocks(params);
|
|
76
|
+
const indexBlocks = generateIndexBlocks_Cached(params);
|
|
77
|
+
const relationsBlocks = generateRelationsBlocks_Cached(params);
|
|
78
|
+
const fields = Array.from(model.fields.values());
|
|
79
|
+
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_Database(params);
|
|
80
|
+
const idField = model.idField;
|
|
81
|
+
/**
|
|
82
|
+
* In case of Action or ActionOperation model, we do not want to log the actions, as this would lead to an endless recursion
|
|
83
|
+
*/
|
|
84
|
+
const skipExecutionLogging = model.name == schema_1.standardModelName_Action || model.name == schema_1.standardModelName_ActionOperation;
|
|
85
|
+
return `
|
|
86
|
+
import { Injectable, Logger } from '@nestjs/common'
|
|
87
|
+
${imports.generate()}
|
|
88
|
+
|
|
89
|
+
type Filter = {
|
|
90
|
+
predicate: (item: ${model.types.name}) => boolean,
|
|
91
|
+
// This is only relevant for the database implementation
|
|
92
|
+
prisma: any
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Injectable()
|
|
96
|
+
export class ${repository.name} implements Repository<${model.types.name}, ${idField.unbrandedTypeName}> {
|
|
97
|
+
protected data: Map<${model.types.id.name}, ${model.types.name}> = new Map()
|
|
98
|
+
protected logger = new Logger(${repository.name}.name)
|
|
99
|
+
|
|
100
|
+
${relationsBlocks.mapDeclarations.join('\n')}
|
|
101
|
+
|
|
102
|
+
${defaultValueBlocks.publicVariableDeclaration}
|
|
103
|
+
|
|
104
|
+
${idBlocks.generateNextIdFunctionName}
|
|
105
|
+
|
|
106
|
+
protected uniqueIds = {
|
|
107
|
+
${uniqueStringFieldsBlocks.mapDeclarations.join(',\n')}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
${indexBlocks.nestedMapDeclarations.join('\n')}
|
|
111
|
+
|
|
112
|
+
${userRepositorySpecificBlocks.rootUserNameConst}
|
|
113
|
+
|
|
114
|
+
${userRepositorySpecificBlocks.getterBlock}
|
|
115
|
+
|
|
116
|
+
private readonly mutex = new Mutex()
|
|
117
|
+
|
|
118
|
+
constructor(protected db: ${context.database.service.name}) {}
|
|
119
|
+
|
|
120
|
+
public async init(${defaultValueBlocks.init.ignoreErrorVariableDeclaration}) {
|
|
121
|
+
this.data.clear()
|
|
122
|
+
|
|
123
|
+
${relationsBlocks.clearCode.join('\n')}
|
|
124
|
+
|
|
125
|
+
${uniqueStringFieldsBlocks.clearCode.join('\n')}
|
|
126
|
+
|
|
127
|
+
${defaultValueBlocks.init.resetCode}
|
|
128
|
+
|
|
129
|
+
${indexBlocks.initCode.join('\n')}
|
|
130
|
+
|
|
131
|
+
const data = await this.db.${repository.prismaClientName}.findMany({})
|
|
132
|
+
|
|
133
|
+
for (const rawItem of data) {
|
|
134
|
+
const item = ${model.decoder.flattened.decoder.parseFunction.name}(rawItem)
|
|
135
|
+
this.set(item)
|
|
136
|
+
|
|
137
|
+
${defaultValueBlocks.init.setCode}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
${idBlocks.initCode}
|
|
141
|
+
|
|
142
|
+
${defaultValueBlocks.init.checkCode}
|
|
143
|
+
|
|
144
|
+
${userRepositorySpecificBlocks.initCall}
|
|
145
|
+
|
|
146
|
+
this.logger.log(\`\${format(this.data.size)} \${pluralize('${model.types.name}', this.data.size)} loaded\`)
|
|
147
|
+
${indexBlocks.initLogCode.join('\n')}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
${userRepositorySpecificBlocks.rootUserInitializeBlock}
|
|
151
|
+
|
|
152
|
+
public async get(id: ${model.types.id.name} | null): Promise<${model.types.name} | null> {
|
|
153
|
+
if (id === null) {
|
|
154
|
+
return Promise.resolve(null) // NOSONAR - keep all validations async to adhere to the same interface
|
|
155
|
+
}
|
|
156
|
+
await this.mutex.waitForUnlock()
|
|
157
|
+
return Promise.resolve(this.data.get(id) ?? null) // NOSONAR - keep all validations async to adhere to the same interface
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public async getAll(): Promise<Map<${model.types.id.name}, ${model.types.name}>> {
|
|
161
|
+
await this.mutex.waitForUnlock()
|
|
162
|
+
return Promise.resolve(new Map(this.data)) // NOSONAR - keep all validations async to adhere to the same interface
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public async getAllAsArray(): Promise<${model.types.name}[]> {
|
|
166
|
+
await this.mutex.waitForUnlock()
|
|
167
|
+
return Promise.resolve(Array.from(this.data.values())) // NOSONAR - keep all validations async to adhere to the same interface
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
${indexBlocks.getterFunctions.join('\n')}
|
|
171
|
+
|
|
172
|
+
${uniqueStringFieldsBlocks.getByFunctions.join('\n')}
|
|
173
|
+
|
|
174
|
+
public async filter({ predicate }: Filter): Promise<${model.types.name}[]> {
|
|
175
|
+
await this.mutex.waitForUnlock()
|
|
176
|
+
return (await this.getAllAsArray()).filter(predicate)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public async findFirst({ predicate }: Filter): Promise<${model.types.name} | null> {
|
|
180
|
+
await this.mutex.waitForUnlock()
|
|
181
|
+
return (await this.getAllAsArray()).find(predicate) ?? null
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public async count(): Promise<number> {
|
|
185
|
+
await this.mutex.waitForUnlock()
|
|
186
|
+
return Promise.resolve(this.data.size) // NOSONAR - keep all validations async to adhere to the same interface
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
${Generator.toJsDocComment([
|
|
190
|
+
`Checks that item has the ${idField.name} field.`,
|
|
191
|
+
`In case none exists, ${idBlocks.verifyFunctionComment}`,
|
|
192
|
+
uniqueStringFieldsBlocks.verifyFunctionComment,
|
|
193
|
+
maxLengthBlocks.verifyFunctionComment,
|
|
194
|
+
])}
|
|
195
|
+
private verifyItem(
|
|
196
|
+
item: ${idBlocks.verifyFunctionParameterType}
|
|
197
|
+
): ${idBlocks.createFunctionParameterType} {
|
|
198
|
+
${idBlocks.verifyCode}
|
|
199
|
+
|
|
200
|
+
${maxLengthBlocks.verifyCode.join('\n')}
|
|
201
|
+
|
|
202
|
+
${uniqueStringFieldsBlocks.verifyCode.join('\n')}
|
|
203
|
+
|
|
204
|
+
${validationBlocks.verifyCode.join('\n')}
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
${Generator.toJsDocComment([`Creates a new ${model.userFriendlyName} and returns it.`])}
|
|
209
|
+
public async create(
|
|
210
|
+
{ item${skipIf(skipExecutionLogging, ', execution')} }: { item: ${model.types.dto.create.name}, execution: ${context.actions.execution.interface.name} }
|
|
211
|
+
): Promise<${model.types.name}> {
|
|
212
|
+
|
|
213
|
+
${skipIf(skipExecutionLogging, `const actionOperationId = await execution.${context.actions.execution.mutations.create.start}({
|
|
214
|
+
model: '${model.types.scopeName}',
|
|
215
|
+
createObject: item
|
|
216
|
+
})`)}
|
|
217
|
+
|
|
218
|
+
const release = await this.mutex.acquire()
|
|
219
|
+
${skipIf(!skipExecutionLogging, '// eslint-disable-next-line no-useless-catch')}
|
|
220
|
+
try {
|
|
221
|
+
this.verifyItem(item)
|
|
222
|
+
const newItem = ${model.decoder.flattened.decoder.parseFunction.name}(
|
|
223
|
+
await this.db.${repository.prismaClientName}.create({
|
|
224
|
+
data: ${model.decoder.flattened.encoder.name}(item),
|
|
225
|
+
}),
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
this.set(newItem)
|
|
229
|
+
release()
|
|
230
|
+
|
|
231
|
+
${skipIf(skipExecutionLogging, `await execution.${context.actions.execution.mutations.create.finish}({ actionOperationId, createdObject: newItem, entityId: newItem.id })`)}
|
|
232
|
+
return newItem
|
|
233
|
+
} catch (error) {
|
|
234
|
+
release()
|
|
235
|
+
${skipIf(skipExecutionLogging, `await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })`)}
|
|
236
|
+
throw error
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
${Generator.toJsDocComment([`Creates multiple new ${model.internalPluralName} and returns them.`])}
|
|
241
|
+
public async createMany(
|
|
242
|
+
{items, execution}: { items: ${model.types.dto.create.name}[], execution: ${context.actions.execution.interface.name} }
|
|
243
|
+
): Promise<${model.types.name}[]> {
|
|
244
|
+
const actionOperationId = await execution.${context.actions.execution.mutations.createMany.start}({
|
|
245
|
+
model: '${model.types.scopeName}',
|
|
246
|
+
createObjects: items
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
const release = await this.mutex.acquire()
|
|
250
|
+
try {
|
|
251
|
+
assertArray(items, this.verifyItem.bind(this))
|
|
252
|
+
|
|
253
|
+
const dbItems = await this.db.${repository.prismaClientName}.createManyAndReturn({ data: items.map(i => ${model.decoder.flattened.encoder.name}(i)) })
|
|
254
|
+
|
|
255
|
+
const result = dbItems.map((item) => ${model.decoder.flattened.decoder.parseFunction.name}(item))
|
|
256
|
+
|
|
257
|
+
for (const item of result) {
|
|
258
|
+
this.set(item)
|
|
259
|
+
}
|
|
260
|
+
release()
|
|
261
|
+
|
|
262
|
+
await execution.${context.actions.execution.mutations.createMany.finish}({
|
|
263
|
+
actionOperationId,
|
|
264
|
+
createdObjects: result,
|
|
265
|
+
entityIds: dbItems.map((i) => i.id),
|
|
266
|
+
})
|
|
267
|
+
return result
|
|
268
|
+
} catch (error) {
|
|
269
|
+
release()
|
|
270
|
+
await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })
|
|
271
|
+
throw error
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
${Generator.toJsDocComment([`Updates a ${model.userFriendlyName} and returns it.`])}
|
|
276
|
+
public async update(
|
|
277
|
+
{ item, execution }: { item: ${model.types.dto.update.name}, execution: ${context.actions.execution.interface.name} }
|
|
278
|
+
): Promise<${model.types.name}> {
|
|
279
|
+
const existingItem = await this.get(item.${idField.name})
|
|
280
|
+
if (!existingItem) {
|
|
281
|
+
throw new Error(\`Could not update ${model.userFriendlyName} with id \${item.id}. Not found!\`)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const actionOperationId = await execution.${context.actions.execution.mutations.update.start}({
|
|
285
|
+
model: '${model.types.scopeName}',
|
|
286
|
+
entityId: item.id,
|
|
287
|
+
sourceObject: existingItem,
|
|
288
|
+
updateObject: item,
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
const release = await this.mutex.acquire()
|
|
292
|
+
try {
|
|
293
|
+
${maxLengthBlocks.updateCode.join('\n')}
|
|
294
|
+
|
|
295
|
+
${uniqueStringFieldsBlocks.updateCode.join('\n')}
|
|
296
|
+
|
|
297
|
+
const newItem = ${model.decoder.flattened.decoder.parseFunction.name}(
|
|
298
|
+
await this.db.${repository.prismaClientName}.update({
|
|
299
|
+
where: {
|
|
300
|
+
${idField.databaseName}: item.${idField.name},
|
|
301
|
+
},
|
|
302
|
+
data: {
|
|
303
|
+
${[...fields.values()]
|
|
304
|
+
.filter((f) => f.kind !== 'id' && !f.isReadonly)
|
|
305
|
+
.map((f) => getFieldUpdateAssignment(f))
|
|
306
|
+
.join(',\n')}
|
|
307
|
+
},
|
|
308
|
+
}),
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
this.remove(existingItem)
|
|
312
|
+
this.set(newItem)
|
|
313
|
+
release()
|
|
314
|
+
|
|
315
|
+
await execution.${context.actions.execution.mutations.update.finish}({ actionOperationId, updatedObject: newItem })
|
|
316
|
+
return newItem
|
|
317
|
+
} catch (error) {
|
|
318
|
+
release()
|
|
319
|
+
await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })
|
|
320
|
+
throw error
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
${Generator.toJsDocComment([`Updates multiple ${model.internalPluralName} and returns them.`])}
|
|
325
|
+
public async updateMany(
|
|
326
|
+
{ items, execution }: { items: ${model.types.dto.update.name}[], execution: ${context.actions.execution.interface.name} }
|
|
327
|
+
): Promise<${model.types.name}[]> {
|
|
328
|
+
const result: ${model.types.name}[] = []
|
|
329
|
+
for (const item of items) {
|
|
330
|
+
try {
|
|
331
|
+
const updated = await this.update({ item, execution })
|
|
332
|
+
result.push(updated)
|
|
333
|
+
} catch {
|
|
334
|
+
/* empty */
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return result
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
${Generator.toJsDocComment([`Creates or updates a ${model.userFriendlyName} and returns it.`])}
|
|
341
|
+
public async upsert(
|
|
342
|
+
{ item, execution }: { item: ${model.types.dto.upsert.name}, execution: ${context.actions.execution.interface.name} }
|
|
343
|
+
): Promise<${model.types.name}> {
|
|
344
|
+
const existingItem = item.${model.idField.name} ? (await this.get(item.${model.idField.name})) : null
|
|
345
|
+
if (existingItem) {
|
|
346
|
+
return this.update({ item: item as ${model.types.dto.update.name}, execution })
|
|
347
|
+
} else {
|
|
348
|
+
return this.create({ item: item as ${model.types.dto.create.name}, execution })
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
${Generator.toJsDocComment([`Creates or updates multiple ${model.internalPluralName} and returns them.`])}
|
|
353
|
+
public async upsertMany(
|
|
354
|
+
{ items, execution }: { items: ${model.types.dto.upsert.name}[], execution: ${context.actions.execution.interface.name} }
|
|
355
|
+
): Promise<${model.types.name}[]> {
|
|
356
|
+
const result: ${model.types.name}[] = []
|
|
357
|
+
for (const item of items) {
|
|
358
|
+
try {
|
|
359
|
+
const updated = await this.upsert({ item, execution })
|
|
360
|
+
result.push(updated)
|
|
361
|
+
} catch {
|
|
362
|
+
/* empty */
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return result
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
${Generator.toJsDocComment([`Deletes a ${model.userFriendlyName} and returns its id.`])}
|
|
369
|
+
public async delete(
|
|
370
|
+
{ id, execution }: { id: ${model.types.id.name}, execution: ${context.actions.execution.interface.name} }
|
|
371
|
+
): Promise<${model.types.id.name}> {
|
|
372
|
+
const existingItem = await this.get(id)
|
|
373
|
+
if (!existingItem) {
|
|
374
|
+
throw new Error(\`Could not delete ${model.types.name} with id \${id}. Not found!\`)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const actionOperationId = await execution.${context.actions.execution.mutations.delete.start}({
|
|
378
|
+
model: '${model.types.scopeName}',
|
|
379
|
+
entityId: id,
|
|
380
|
+
sourceObject: existingItem,
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
const release = await this.mutex.acquire()
|
|
384
|
+
try {
|
|
385
|
+
|
|
386
|
+
await this.db.${repository.prismaClientName}.delete({ where: { ${idField.databaseName}:id } })
|
|
387
|
+
|
|
388
|
+
this.remove(existingItem)
|
|
389
|
+
release()
|
|
390
|
+
await execution.${context.actions.execution.mutations.delete.finish}({ actionOperationId })
|
|
391
|
+
return id
|
|
392
|
+
} catch (error) {
|
|
393
|
+
release()
|
|
394
|
+
await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })
|
|
395
|
+
throw error
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
${Generator.toJsDocComment([`Deletes multiple ${model.internalPluralName} and returns their ids.`])}
|
|
400
|
+
public async deleteMany(
|
|
401
|
+
{ ids, execution }: { ids: ${model.types.id.name}[], execution: ${context.actions.execution.interface.name} }
|
|
402
|
+
): Promise<${model.types.id.name}[]> {
|
|
403
|
+
const deletedIds: ${model.types.id.name}[] = []
|
|
404
|
+
for (const id of ids) {
|
|
405
|
+
try {
|
|
406
|
+
await this.delete({ id, execution })
|
|
407
|
+
deletedIds.push(id)
|
|
408
|
+
} catch {
|
|
409
|
+
/* empty */
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return deletedIds
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
${Generator.toJsDocComment([`Creates a new ${model.userFriendlyName} shallow clone and returns it.`])}
|
|
416
|
+
public async clone({ id, item, execution }: {
|
|
417
|
+
id: ${model.types.id.name}
|
|
418
|
+
item: (item: ${model.types.name}) => ${model.types.dto.clone.name},
|
|
419
|
+
execution: ${context.actions.execution.interface.name}
|
|
420
|
+
}): Promise<${model.types.name}> {
|
|
421
|
+
const source = await this.get(id)
|
|
422
|
+
if (!source) {
|
|
423
|
+
throw new Error(\`${model.userFriendlyName} with id \${id} not found\`)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const { id: _, ...data } = { ...source, ...item(source) }
|
|
427
|
+
|
|
428
|
+
return await this.create({ item: data, execution })
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
${relationsBlocks.getterFunctions.join('\n')}
|
|
432
|
+
|
|
433
|
+
${maxLengthBlocks.ensureMaxLengthFunctions.join('\n')}
|
|
434
|
+
|
|
435
|
+
${uniqueStringFieldsBlocks.ensureUniqueFunctions.join('\n\n')}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Function that adds/updates a given item to the internal data store, indexes, etc.
|
|
439
|
+
*/
|
|
440
|
+
private set(item: ${model.types.name}): void {
|
|
441
|
+
${idBlocks.setCode}
|
|
442
|
+
|
|
443
|
+
this.data.set(item.id, item)
|
|
444
|
+
|
|
445
|
+
${uniqueStringFieldsBlocks.setCode.join('\n')}
|
|
446
|
+
|
|
447
|
+
${relationsBlocks.setCode.join('\n')}
|
|
448
|
+
|
|
449
|
+
${indexBlocks.setCode.join('\n')}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Function that removes a given item from the internal data store, indexes, etc.
|
|
454
|
+
*/
|
|
455
|
+
private remove(item: ${model.types.name}): void {
|
|
456
|
+
this.data.delete(item.id)
|
|
457
|
+
${uniqueStringFieldsBlocks.removeCode.join('\n')}
|
|
458
|
+
|
|
459
|
+
${relationsBlocks.removeCode.join('\n')}
|
|
460
|
+
|
|
461
|
+
${indexBlocks.removeCode.join('\n')}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
`;
|
|
466
|
+
};
|
|
467
|
+
exports.generateRepository_DatabaseCached = generateRepository_DatabaseCached;
|
|
468
|
+
/**
|
|
469
|
+
* Generates repository data structure for a given model that persists the data in the database and does not use any in-memory caching.
|
|
470
|
+
*/
|
|
471
|
+
const generateRepository_DatabaseDirect = (model, context) => {
|
|
472
|
+
const { types, repository } = model;
|
|
473
|
+
const imports = new Generator.ImportGenerator({ path: repository.location })
|
|
474
|
+
.addType(types)
|
|
475
|
+
.addType(types.dto.create)
|
|
476
|
+
.addType(types.dto.update)
|
|
477
|
+
.addType(types.dto.upsert)
|
|
478
|
+
.addType(types.dto.clone)
|
|
479
|
+
.addType(types.id)
|
|
480
|
+
.addImport({
|
|
481
|
+
from: types.location,
|
|
482
|
+
items: [types.id.toBranded.name],
|
|
483
|
+
})
|
|
484
|
+
.addType(context.actions.execution.interface)
|
|
485
|
+
.addType(context.repositories.interface)
|
|
486
|
+
.add(context.database.service)
|
|
487
|
+
.add(model.decoder.flattened.decoder.parseFunction)
|
|
488
|
+
.add(model.decoder.flattened.encoder)
|
|
489
|
+
.addImport({
|
|
490
|
+
from: Generator.toPackageName('@postxl/utils'),
|
|
491
|
+
items: [
|
|
492
|
+
Generator.toFunctionName('format'),
|
|
493
|
+
Generator.toFunctionName('pluralize'),
|
|
494
|
+
Generator.toFunctionName('assertArray'),
|
|
495
|
+
],
|
|
496
|
+
})
|
|
497
|
+
.addImport({ from: context.database.prismaClient.location, items: [Generator.toFunctionName('Prisma')] })
|
|
498
|
+
.addImport({ from: Generator.toPackageName('async-mutex'), items: [Generator.toClassName('Mutex')] });
|
|
499
|
+
const params = { model, context, imports };
|
|
500
|
+
const idBlocks = generateIdBlocks_Database(params);
|
|
501
|
+
const defaultValueBlocks = generateDefaultBlocks(params);
|
|
502
|
+
const uniqueStringFieldsBlocks = generateUniqueFieldsBlocks_Database(params);
|
|
503
|
+
const maxLengthBlocks = generateMaxLengthBlocks(params);
|
|
504
|
+
const validationBlocks = generateValidationBlocks(params);
|
|
505
|
+
const indexBlocks = generateIndexBlocks_Database(params);
|
|
506
|
+
const relationsBlocks = generateRelationsBlocks_Database(params);
|
|
507
|
+
const fields = Array.from(model.fields.values());
|
|
508
|
+
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_Database(params);
|
|
509
|
+
const idField = model.idField;
|
|
510
|
+
const hasSetFunction = idBlocks.setCode.length > 0;
|
|
511
|
+
const setFunction = hasSetFunction
|
|
512
|
+
? `
|
|
513
|
+
/**
|
|
514
|
+
* Function that adds/updates a given item to the internal data store, indexes, etc.
|
|
515
|
+
*/
|
|
516
|
+
private set(item: ${model.types.name}): void {
|
|
517
|
+
${idBlocks.setCode}
|
|
518
|
+
}`
|
|
519
|
+
: '';
|
|
520
|
+
/**
|
|
521
|
+
* In case of Action or ActionOperation model, we do not want to log the actions, as this would lead to an endless recursion
|
|
522
|
+
*/
|
|
523
|
+
const skipExecutionLogging = model.name == schema_1.standardModelName_Action || model.name == schema_1.standardModelName_ActionOperation;
|
|
524
|
+
return `
|
|
525
|
+
import { Injectable, Logger } from '@nestjs/common'
|
|
526
|
+
${imports.generate()}
|
|
527
|
+
|
|
528
|
+
type Filter = {
|
|
529
|
+
predicate: (item: ${model.types.name}) => boolean,
|
|
530
|
+
prisma: Prisma.${model.types.name}WhereInput
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
@Injectable()
|
|
534
|
+
export class ${repository.name} implements Repository<${model.types.name}, ${idField.unbrandedTypeName}> {
|
|
535
|
+
protected logger = new Logger(${repository.name}.name)
|
|
536
|
+
|
|
537
|
+
${defaultValueBlocks.publicVariableDeclaration}
|
|
538
|
+
|
|
539
|
+
${idBlocks.generateNextIdFunctionName}
|
|
540
|
+
|
|
541
|
+
protected uniqueIds = {
|
|
542
|
+
${uniqueStringFieldsBlocks.mapDeclarations.join(',\n')}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
${userRepositorySpecificBlocks.rootUserNameConst}
|
|
546
|
+
|
|
547
|
+
${userRepositorySpecificBlocks.getterBlock}
|
|
548
|
+
|
|
549
|
+
private readonly mutex = new Mutex()
|
|
550
|
+
|
|
551
|
+
constructor(protected db: ${context.database.service.name}) {}
|
|
552
|
+
|
|
553
|
+
public async init(${defaultValueBlocks.init.ignoreErrorVariableDeclaration}) {
|
|
554
|
+
|
|
555
|
+
${uniqueStringFieldsBlocks.clearCode.join('\n')}
|
|
556
|
+
|
|
557
|
+
${defaultValueBlocks.init.resetCode}
|
|
558
|
+
${defaultValueBlocks.init.setCode}
|
|
559
|
+
${defaultValueBlocks.init.checkCode}
|
|
560
|
+
|
|
561
|
+
${userRepositorySpecificBlocks.initCall}
|
|
562
|
+
|
|
563
|
+
const count = await this.db.${repository.prismaClientName}.count()
|
|
564
|
+
|
|
565
|
+
this.logger.log(\`Database contains \${format(count)} \${pluralize('${model.types.name}', count)}, no data was cached\`)
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
${userRepositorySpecificBlocks.rootUserInitializeBlock}
|
|
569
|
+
|
|
570
|
+
public async get(id: ${model.types.id.name} | null): Promise<${model.types.name} | null> {
|
|
571
|
+
if (id === null) {
|
|
572
|
+
return Promise.resolve(null) // NOSONAR - keep all validations async to adhere to the same interface
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
await this.mutex.waitForUnlock()
|
|
576
|
+
|
|
577
|
+
const result = await this.db.${repository.prismaClientName}.findUnique({ where: { ${idField.databaseName}: id } })
|
|
578
|
+
return result ? ${model.decoder.flattened.decoder.parseFunction.name}(result) : null
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
public async getAll(): Promise<Map<${model.types.id.name}, ${model.types.name}>> {
|
|
582
|
+
const result = new Map<${model.types.id.name}, ${model.types.name}>()
|
|
583
|
+
|
|
584
|
+
await this.mutex.waitForUnlock()
|
|
585
|
+
|
|
586
|
+
const data = await this.db.${repository.prismaClientName}.findMany({})
|
|
587
|
+
for (const rawItem of data) {
|
|
588
|
+
const item = ${model.decoder.flattened.decoder.parseFunction.name}(rawItem)
|
|
589
|
+
result.set(item.id, item)
|
|
590
|
+
${hasSetFunction ? 'result.set(item.id, item)' : ''}
|
|
591
|
+
}
|
|
592
|
+
return result
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
public async getAllAsArray(): Promise<${model.types.name}[]> {
|
|
596
|
+
return Array.from((await this.getAll()).values())
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
${indexBlocks.getterFunctions.join('\n')}
|
|
600
|
+
|
|
601
|
+
${uniqueStringFieldsBlocks.getByFunctions.join('\n')}
|
|
602
|
+
|
|
603
|
+
public async filter({ prisma: where }: Filter): Promise<${model.types.name}[]> {
|
|
604
|
+
await this.mutex.waitForUnlock()
|
|
605
|
+
|
|
606
|
+
const data = await this.db.${repository.prismaClientName}.findMany({ where })
|
|
607
|
+
return data.map((item) => ${model.decoder.flattened.decoder.parseFunction.name}(item))
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
public async findFirst({ prisma: where }: Filter): Promise<${model.types.name} | null> {
|
|
611
|
+
await this.mutex.waitForUnlock()
|
|
612
|
+
const data = await this.db.${repository.prismaClientName}.findFirst({ where })
|
|
613
|
+
return data ? ${model.decoder.flattened.decoder.parseFunction.name}(data) : null
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
public async count(): Promise<number> {
|
|
617
|
+
await this.mutex.waitForUnlock()
|
|
618
|
+
return this.db.${repository.prismaClientName}.count()
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Ensures that item has an id.
|
|
623
|
+
*/
|
|
624
|
+
private assertId(item: ${idBlocks.verifyFunctionParameterType}): ${idBlocks.createFunctionParameterType} {
|
|
625
|
+
if (item.${idField.name} !== undefined && item.${idField.name} !== null) {
|
|
626
|
+
return
|
|
627
|
+
}
|
|
628
|
+
${idBlocks.verifyCode}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
${Generator.toJsDocComment([
|
|
632
|
+
`Checks that item has the ${idField.name} field.`,
|
|
633
|
+
`In case none exists, ${idBlocks.verifyFunctionComment}`,
|
|
634
|
+
uniqueStringFieldsBlocks.verifyFunctionComment,
|
|
635
|
+
maxLengthBlocks.verifyFunctionComment,
|
|
636
|
+
])}
|
|
637
|
+
private async verifyItem(item: ${idBlocks.verifyFunctionParameterType}): Promise<void> {
|
|
638
|
+
this.assertId(item)
|
|
639
|
+
|
|
640
|
+
${maxLengthBlocks.verifyCode.join('\n')}
|
|
641
|
+
|
|
642
|
+
${uniqueStringFieldsBlocks.verifyCode.join('\n')}
|
|
643
|
+
|
|
644
|
+
${validationBlocks.verifyCode.join('\n')}
|
|
645
|
+
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
${Generator.toJsDocComment([`Creates a new ${model.userFriendlyName} and returns it.`])}
|
|
649
|
+
public async create(
|
|
650
|
+
{ item${skipIf(skipExecutionLogging, ', execution')} }: { item: ${model.types.dto.create.name}, execution: ${context.actions.execution.interface.name} }
|
|
651
|
+
): Promise<${model.types.name}> {
|
|
652
|
+
${skipIf(skipExecutionLogging, `const actionOperationId = await execution.${context.actions.execution.mutations.create.start}({
|
|
653
|
+
model: '${model.types.scopeName}',
|
|
654
|
+
createObject: item
|
|
655
|
+
})`)}
|
|
656
|
+
|
|
657
|
+
const release = await this.mutex.acquire()
|
|
658
|
+
${skipIf(!skipExecutionLogging, '// eslint-disable-next-line no-useless-catch')}
|
|
659
|
+
try {
|
|
660
|
+
await this.verifyItem(item)
|
|
661
|
+
this.assertId(item)
|
|
662
|
+
const newItem = ${model.decoder.flattened.decoder.parseFunction.name}(
|
|
663
|
+
await this.db.${repository.prismaClientName}.create({
|
|
664
|
+
data: ${model.decoder.flattened.encoder.name}(item),
|
|
665
|
+
}),
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
${hasSetFunction ? 'this.set(newItem)' : ''}
|
|
669
|
+
${skipIf(skipExecutionLogging, `await execution.${context.actions.execution.mutations.create.finish}({ actionOperationId, createdObject: newItem, entityId: newItem.id })`)}
|
|
670
|
+
|
|
671
|
+
release()
|
|
672
|
+
|
|
673
|
+
return newItem
|
|
674
|
+
} catch (error) {
|
|
675
|
+
${skipIf(skipExecutionLogging, `await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })`)}
|
|
676
|
+
release()
|
|
677
|
+
throw error
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
${Generator.toJsDocComment([`Creates multiple new ${model.internalPluralName} and returns them.`])}
|
|
682
|
+
public async createMany(
|
|
683
|
+
{items, execution}: { items: ${model.types.dto.create.name}[], execution: ${context.actions.execution.interface.name} }
|
|
684
|
+
): Promise<${model.types.name}[]> {
|
|
685
|
+
const actionOperationId = await execution.${context.actions.execution.mutations.createMany.start}({
|
|
686
|
+
model: '${model.types.scopeName}',
|
|
687
|
+
createObjects: items
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
const release = await this.mutex.acquire()
|
|
691
|
+
try {
|
|
692
|
+
for (const item of items) {
|
|
693
|
+
await this.verifyItem(item)
|
|
694
|
+
}
|
|
695
|
+
assertArray(items, this.assertId.bind(this))
|
|
696
|
+
|
|
697
|
+
const dbItems = await this.db.${repository.prismaClientName}.createManyAndReturn({ data: items.map(i => ${model.decoder.flattened.encoder.name}(i)) })
|
|
698
|
+
|
|
699
|
+
const result = dbItems.map((item) => ${model.decoder.flattened.decoder.parseFunction.name}(item))
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
${hasSetFunction ? 'for (const item of result) { this.set(item) }' : ''}
|
|
703
|
+
release()
|
|
704
|
+
|
|
705
|
+
await execution.${context.actions.execution.mutations.createMany.finish}({
|
|
706
|
+
actionOperationId,
|
|
707
|
+
createdObjects: result,
|
|
708
|
+
entityIds: dbItems.map((i) => i.id),
|
|
709
|
+
})
|
|
710
|
+
return result
|
|
711
|
+
} catch (error) {
|
|
712
|
+
release()
|
|
713
|
+
await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })
|
|
714
|
+
throw error
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
${Generator.toJsDocComment([`Updates a ${model.userFriendlyName} and returns it.`])}
|
|
719
|
+
public async update(
|
|
720
|
+
{ item, execution }: { item: ${model.types.dto.update.name}, execution: ${context.actions.execution.interface.name} }
|
|
721
|
+
): Promise<${model.types.name}> {
|
|
722
|
+
const existingItem = await this.get(item.${idField.name})
|
|
723
|
+
if (!existingItem) {
|
|
724
|
+
throw new Error(\`Could not update ${model.userFriendlyName} with id \${item.id}. Not found!\`)
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
const actionOperationId = await execution.${context.actions.execution.mutations.update.start}({
|
|
728
|
+
model: '${model.types.scopeName}',
|
|
729
|
+
entityId: item.id,
|
|
730
|
+
sourceObject: existingItem,
|
|
731
|
+
updateObject: item,
|
|
732
|
+
})
|
|
733
|
+
|
|
734
|
+
const release = await this.mutex.acquire()
|
|
735
|
+
try {
|
|
736
|
+
${maxLengthBlocks.updateCode.join('\n')}
|
|
737
|
+
|
|
738
|
+
${uniqueStringFieldsBlocks.updateCode.join('\n')}
|
|
739
|
+
|
|
740
|
+
const newItem = ${model.decoder.flattened.decoder.parseFunction.name}(
|
|
741
|
+
await this.db.${repository.prismaClientName}.update({
|
|
742
|
+
where: {
|
|
743
|
+
${idField.databaseName}: item.${idField.name},
|
|
744
|
+
},
|
|
745
|
+
data: {
|
|
746
|
+
${[...fields.values()]
|
|
747
|
+
.filter((f) => f.kind !== 'id' && !f.isReadonly)
|
|
748
|
+
.map((f) => getFieldUpdateAssignment(f))
|
|
749
|
+
.join(',\n')}
|
|
750
|
+
},
|
|
751
|
+
}),
|
|
752
|
+
)
|
|
753
|
+
|
|
754
|
+
${hasSetFunction ? 'this.set(newItem)' : ''}
|
|
755
|
+
release()
|
|
756
|
+
|
|
757
|
+
await execution.${context.actions.execution.mutations.update.finish}({ actionOperationId, updatedObject: newItem })
|
|
758
|
+
return newItem
|
|
759
|
+
} catch (error) {
|
|
760
|
+
release()
|
|
761
|
+
await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })
|
|
762
|
+
throw error
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
${Generator.toJsDocComment([`Updates multiple ${model.internalPluralName} and returns them.`])}
|
|
767
|
+
public async updateMany(
|
|
768
|
+
{ items, execution }: { items: ${model.types.dto.update.name}[], execution: ${context.actions.execution.interface.name} }
|
|
769
|
+
): Promise<${model.types.name}[]> {
|
|
770
|
+
const result: ${model.types.name}[] = []
|
|
771
|
+
for (const item of items) {
|
|
772
|
+
try {
|
|
773
|
+
const updated = await this.update({ item, execution })
|
|
774
|
+
result.push(updated)
|
|
775
|
+
} catch {
|
|
776
|
+
/* empty */
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return result
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
${Generator.toJsDocComment([`Creates or updates a ${model.userFriendlyName} and returns it.`])}
|
|
783
|
+
public async upsert(
|
|
784
|
+
{ item, execution }: { item: ${model.types.dto.upsert.name}, execution: ${context.actions.execution.interface.name} }
|
|
785
|
+
): Promise<${model.types.name}> {
|
|
786
|
+
const existingItem = item.${model.idField.name} ? (await this.get(item.${model.idField.name})) : null
|
|
787
|
+
if (existingItem) {
|
|
788
|
+
return this.update({ item: item as ${model.types.dto.update.name}, execution })
|
|
789
|
+
} else {
|
|
790
|
+
return this.create({ item: item as ${model.types.dto.create.name}, execution })
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
${Generator.toJsDocComment([`Creates or updates multiple ${model.internalPluralName} and returns them.`])}
|
|
795
|
+
public async upsertMany(
|
|
796
|
+
{ items, execution }: { items: ${model.types.dto.upsert.name}[], execution: ${context.actions.execution.interface.name} }
|
|
797
|
+
): Promise<${model.types.name}[]> {
|
|
798
|
+
const result: ${model.types.name}[] = []
|
|
799
|
+
for (const item of items) {
|
|
800
|
+
try {
|
|
801
|
+
const updated = await this.upsert({ item, execution })
|
|
802
|
+
result.push(updated)
|
|
803
|
+
} catch {
|
|
804
|
+
/* empty */
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return result
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
${Generator.toJsDocComment([`Deletes a ${model.userFriendlyName} and returns its id.`])}
|
|
811
|
+
public async delete(
|
|
812
|
+
{ id, execution }: { id: ${model.types.id.name}, execution: ${context.actions.execution.interface.name} }
|
|
813
|
+
): Promise<${model.types.id.name}> {
|
|
814
|
+
const existingItem = await this.get(id)
|
|
815
|
+
if (!existingItem) {
|
|
816
|
+
throw new Error(\`Could not delete ${model.types.name} with id \${id}. Not found!\`)
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const actionOperationId = await execution.${context.actions.execution.mutations.delete.start}({
|
|
820
|
+
model: '${model.types.scopeName}',
|
|
821
|
+
entityId: id,
|
|
822
|
+
sourceObject: existingItem,
|
|
823
|
+
})
|
|
824
|
+
const release = await this.mutex.acquire()
|
|
825
|
+
try {
|
|
826
|
+
|
|
827
|
+
await this.db.${repository.prismaClientName}.delete({ where: { ${idField.databaseName}:id } })
|
|
828
|
+
release()
|
|
829
|
+
|
|
830
|
+
await execution.${context.actions.execution.mutations.delete.finish}({ actionOperationId })
|
|
831
|
+
return id
|
|
832
|
+
} catch (error) {
|
|
833
|
+
release()
|
|
834
|
+
await execution.${context.actions.execution.errorOperation}({ actionOperationId, error })
|
|
835
|
+
throw error
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
${Generator.toJsDocComment([`Deletes multiple ${model.internalPluralName} and returns their ids.`])}
|
|
840
|
+
public async deleteMany(
|
|
841
|
+
{ ids, execution }: { ids: ${model.types.id.name}[], execution: ${context.actions.execution.interface.name} }
|
|
842
|
+
): Promise<${model.types.id.name}[]> {
|
|
843
|
+
const deletedIds: ${model.types.id.name}[] = []
|
|
844
|
+
for (const id of ids) {
|
|
845
|
+
try {
|
|
846
|
+
await this.delete({ id, execution })
|
|
847
|
+
deletedIds.push(id)
|
|
848
|
+
} catch {
|
|
849
|
+
/* empty */
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return deletedIds
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
${Generator.toJsDocComment([`Creates a new ${model.userFriendlyName} shallow clone and returns it.`])}
|
|
856
|
+
public async clone({ id, item, execution }: {
|
|
857
|
+
id: ${model.types.id.name}
|
|
858
|
+
item: (item: ${model.types.name}) => ${model.types.dto.clone.name},
|
|
859
|
+
execution: ${context.actions.execution.interface.name}
|
|
860
|
+
}): Promise<${model.types.name}> {
|
|
861
|
+
const source = await this.get(id)
|
|
862
|
+
if (!source) {
|
|
863
|
+
throw new Error(\`${model.userFriendlyName} with id \${id} not found\`)
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
const { id: _, ...data } = { ...source, ...item(source) }
|
|
867
|
+
|
|
868
|
+
return await this.create({ item: data, execution })
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
${relationsBlocks.getterFunctions.join('\n')}
|
|
872
|
+
|
|
873
|
+
${maxLengthBlocks.ensureMaxLengthFunctions.join('\n')}
|
|
874
|
+
|
|
875
|
+
${uniqueStringFieldsBlocks.ensureUniqueFunctions.join('\n\n')}
|
|
876
|
+
|
|
877
|
+
${setFunction}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
`;
|
|
881
|
+
};
|
|
882
|
+
exports.generateRepository_DatabaseDirect = generateRepository_DatabaseDirect;
|
|
883
|
+
/**
|
|
884
|
+
* Generates repository data structure for a given model that persists the data in the database and caches it in memory.
|
|
885
|
+
*/
|
|
886
|
+
const generateRepository_InMemory = (model, context) => {
|
|
887
|
+
const { types, repository } = model;
|
|
888
|
+
const imports = new Generator.ImportGenerator({ path: repository.location })
|
|
889
|
+
.addType(types)
|
|
890
|
+
.addType(types.dto.create)
|
|
891
|
+
.addType(types.dto.update)
|
|
892
|
+
.addType(types.dto.upsert)
|
|
893
|
+
.addType(types.dto.clone)
|
|
894
|
+
.addType(types.id)
|
|
895
|
+
.addImport({
|
|
896
|
+
from: types.location,
|
|
897
|
+
items: [types.id.toBranded.name],
|
|
898
|
+
})
|
|
899
|
+
.addType(context.actions.execution.interface)
|
|
900
|
+
.addType(context.repositories.interface)
|
|
901
|
+
.addImport({ from: Generator.toPackageName('async-mutex'), items: [Generator.toFunctionName('Mutex')] });
|
|
902
|
+
const params = { model, context, imports };
|
|
903
|
+
const idBlocks = generateIdBlocks_InMemory(params);
|
|
904
|
+
const defaultValueBlocks = generateDefaultBlocks(params);
|
|
905
|
+
const uniqueStringFieldsBlocks = generateUniqueFieldsBlocks_Cached(params);
|
|
906
|
+
const maxLengthBlocks = generateMaxLengthBlocks(params);
|
|
907
|
+
const validationBlocks = generateValidationBlocks(params);
|
|
908
|
+
const indexBlocks = generateIndexBlocks_Cached(params);
|
|
909
|
+
const relationsBlocks = generateRelationsBlocks_Cached(params);
|
|
910
|
+
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_InMemory(params);
|
|
911
|
+
const idField = model.idField;
|
|
912
|
+
return `
|
|
913
|
+
import { Injectable, Logger } from '@nestjs/common'
|
|
914
|
+
${imports.generate()}
|
|
915
|
+
|
|
916
|
+
type Filter = {
|
|
917
|
+
predicate: (item: ${model.types.name}) => boolean,
|
|
918
|
+
// This is only relevant for the database implementation
|
|
919
|
+
prisma: any
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
@Injectable()
|
|
923
|
+
export class ${repository.name} implements Repository<${model.types.name}, ${idField.unbrandedTypeName}> {
|
|
924
|
+
protected data: Map<${model.types.id.name}, ${model.types.name}> = new Map()
|
|
925
|
+
protected logger = new Logger(${repository.name}.name)
|
|
926
|
+
|
|
927
|
+
${relationsBlocks.mapDeclarations.join('\n')}
|
|
928
|
+
|
|
929
|
+
${defaultValueBlocks.publicVariableDeclaration}
|
|
930
|
+
|
|
931
|
+
${idBlocks.generateNextIdFunctionName}
|
|
932
|
+
|
|
933
|
+
protected uniqueIds = {
|
|
934
|
+
${uniqueStringFieldsBlocks.mapDeclarations.join(',\n')}
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
${indexBlocks.nestedMapDeclarations.join('\n')}
|
|
938
|
+
|
|
939
|
+
${userRepositorySpecificBlocks.rootUserNameConst}
|
|
940
|
+
|
|
941
|
+
${userRepositorySpecificBlocks.getterBlock}
|
|
942
|
+
|
|
943
|
+
private readonly mutex = new Mutex()
|
|
944
|
+
|
|
945
|
+
${userRepositorySpecificBlocks.initCall === '' ? '// eslint-disable-next-line @typescript-eslint/require-await' : ''}
|
|
946
|
+
public async init(${defaultValueBlocks.init.ignoreErrorVariableDeclaration}) {
|
|
947
|
+
this.data.clear()
|
|
948
|
+
|
|
949
|
+
${relationsBlocks.clearCode.join('\n')}
|
|
950
|
+
|
|
951
|
+
${uniqueStringFieldsBlocks.clearCode.join('\n')}
|
|
952
|
+
|
|
953
|
+
${indexBlocks.initCode.join('\n')}
|
|
954
|
+
|
|
955
|
+
${idBlocks.initCode}
|
|
956
|
+
|
|
957
|
+
${userRepositorySpecificBlocks.initCall}
|
|
958
|
+
|
|
959
|
+
${indexBlocks.initLogCode.join('\n')}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
${userRepositorySpecificBlocks.rootUserInitializeBlock}
|
|
963
|
+
|
|
964
|
+
public async get(id: ${model.types.id.name} | null): Promise<${model.types.name} | null> {
|
|
965
|
+
if (id === null) {
|
|
966
|
+
return Promise.resolve(null) // NOSONAR - keep all validations async to adhere to the same interface
|
|
967
|
+
}
|
|
968
|
+
await this.mutex.waitForUnlock()
|
|
969
|
+
|
|
970
|
+
return Promise.resolve(this.data.get(id) ?? null) // NOSONAR - keep all validations async to adhere to the same interface
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
public async getAll(): Promise<Map<${model.types.id.name}, ${model.types.name}>> {
|
|
974
|
+
await this.mutex.waitForUnlock()
|
|
975
|
+
return Promise.resolve(new Map(this.data)) // NOSONAR - keep all validations async to adhere to the same interface
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
public async getAllAsArray(): Promise<${model.types.name}[]> {
|
|
979
|
+
await this.mutex.waitForUnlock()
|
|
980
|
+
return Promise.resolve(Array.from(this.data.values())) // NOSONAR - keep all validations async to adhere to the same interface
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
${indexBlocks.getterFunctions.join('\n')}
|
|
984
|
+
|
|
985
|
+
${uniqueStringFieldsBlocks.getByFunctions.join('\n')}
|
|
986
|
+
|
|
987
|
+
public async filter({ predicate }: Filter): Promise<${model.types.name}[]> {
|
|
988
|
+
return (await this.getAllAsArray()).filter(predicate)
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
public async findFirst({ predicate }: Filter): Promise<${model.types.name} | null> {
|
|
992
|
+
return (await this.getAllAsArray()).find(predicate) ?? null
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
public async count(): Promise<number> {
|
|
996
|
+
await this.mutex.waitForUnlock()
|
|
997
|
+
return Promise.resolve(this.data.size) // NOSONAR - keep all validations async to adhere to the same interface
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
${Generator.toJsDocComment([
|
|
1001
|
+
`Checks that item has the ${idField.name} field.`,
|
|
1002
|
+
`In case none exists, ${idBlocks.verifyFunctionComment}`,
|
|
1003
|
+
uniqueStringFieldsBlocks.verifyFunctionComment,
|
|
1004
|
+
maxLengthBlocks.verifyFunctionComment,
|
|
1005
|
+
])}
|
|
1006
|
+
private verifyItem(
|
|
1007
|
+
item: ${idBlocks.verifyFunctionParameterType}
|
|
1008
|
+
): ${idBlocks.createFunctionParameterType} {
|
|
1009
|
+
${idBlocks.verifyCode}
|
|
1010
|
+
|
|
1011
|
+
${maxLengthBlocks.verifyCode.join('\n')}
|
|
1012
|
+
|
|
1013
|
+
${uniqueStringFieldsBlocks.verifyCode.join('\n')}
|
|
1014
|
+
|
|
1015
|
+
${validationBlocks.verifyCode.join('\n')}
|
|
1016
|
+
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
${Generator.toJsDocComment([`Creates a new ${model.userFriendlyName} and returns it.`])}
|
|
1020
|
+
public async create(
|
|
1021
|
+
{ item }: { item: ${model.types.dto.create.name}, execution: ${context.actions.execution.interface.name} }
|
|
1022
|
+
): Promise<${model.types.name}> {
|
|
1023
|
+
const release = await this.mutex.acquire()
|
|
1024
|
+
try {
|
|
1025
|
+
this.verifyItem(item)
|
|
1026
|
+
this.set(item)
|
|
1027
|
+
release()
|
|
1028
|
+
return Promise.resolve(item) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1029
|
+
} catch (error) {
|
|
1030
|
+
release()
|
|
1031
|
+
throw error
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
${Generator.toJsDocComment([`Creates multiple new ${model.internalPluralName} and returns them.`])}
|
|
1036
|
+
public async createMany(
|
|
1037
|
+
{items}: { items: ${model.types.dto.create.name}[], execution: ${context.actions.execution.interface.name} }
|
|
1038
|
+
): Promise<${model.types.name}[]> {
|
|
1039
|
+
const result: ${model.types.name}[] = []
|
|
1040
|
+
const release = await this.mutex.acquire()
|
|
1041
|
+
try {
|
|
1042
|
+
for (const item of items) {
|
|
1043
|
+
this.verifyItem(item)
|
|
1044
|
+
this.set(item)
|
|
1045
|
+
result.push(item)
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
release()
|
|
1049
|
+
return Promise.resolve(result) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1050
|
+
} catch (error) {
|
|
1051
|
+
release()
|
|
1052
|
+
throw error
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
${Generator.toJsDocComment([`Updates a ${model.userFriendlyName} and returns it.`])}
|
|
1057
|
+
public async update(
|
|
1058
|
+
{ item }: { item: ${model.types.dto.update.name}, execution: ${context.actions.execution.interface.name} }
|
|
1059
|
+
): Promise<${model.types.name}> {
|
|
1060
|
+
const existingItem = await this.get(item.${idField.name})
|
|
1061
|
+
if (!existingItem) {
|
|
1062
|
+
throw new Error(\`Could not update ${model.userFriendlyName} with id \${item.id}. Not found!\`)
|
|
1063
|
+
}
|
|
1064
|
+
const release = await this.mutex.acquire()
|
|
1065
|
+
try {
|
|
1066
|
+
${maxLengthBlocks.updateCode.join('\n')}
|
|
1067
|
+
|
|
1068
|
+
${uniqueStringFieldsBlocks.updateCode.join('\n')}
|
|
1069
|
+
|
|
1070
|
+
const newItem = { ...existingItem, ...item }
|
|
1071
|
+
|
|
1072
|
+
this.remove(existingItem)
|
|
1073
|
+
this.set(newItem)
|
|
1074
|
+
|
|
1075
|
+
release()
|
|
1076
|
+
return Promise.resolve(newItem) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
release()
|
|
1079
|
+
throw error
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
${Generator.toJsDocComment([`Updates multiple ${model.internalPluralName} and returns them.`])}
|
|
1084
|
+
public async updateMany(
|
|
1085
|
+
{ items, execution }: { items: ${model.types.dto.update.name}[], execution: ${context.actions.execution.interface.name} }
|
|
1086
|
+
): Promise<${model.types.name}[]> {
|
|
1087
|
+
const result: ${model.types.name}[] = []
|
|
1088
|
+
for (const item of items) {
|
|
1089
|
+
try {
|
|
1090
|
+
const updated = await this.update({ item, execution })
|
|
1091
|
+
result.push(updated)
|
|
1092
|
+
} catch {
|
|
1093
|
+
/* empty */
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
return result
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
${Generator.toJsDocComment([`Creates or updates a ${model.userFriendlyName} and returns it.`])}
|
|
1100
|
+
public async upsert(
|
|
1101
|
+
{ item, execution }: { item: ${model.types.dto.upsert.name}, execution: ${context.actions.execution.interface.name} }
|
|
1102
|
+
): Promise<${model.types.name}> {
|
|
1103
|
+
const existingItem = item.${model.idField.name} ? (await this.get(item.${model.idField.name})) : null
|
|
1104
|
+
if (existingItem) {
|
|
1105
|
+
return this.update({ item: item as ${model.types.dto.update.name}, execution })
|
|
1106
|
+
} else {
|
|
1107
|
+
return this.create({ item: item as ${model.types.dto.create.name}, execution })
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
${Generator.toJsDocComment([`Creates or updates multiple ${model.internalPluralName} and returns them.`])}
|
|
1112
|
+
public async upsertMany(
|
|
1113
|
+
{ items, execution }: { items: ${model.types.dto.upsert.name}[], execution: ${context.actions.execution.interface.name} }
|
|
1114
|
+
): Promise<${model.types.name}[]> {
|
|
1115
|
+
const result: ${model.types.name}[] = []
|
|
1116
|
+
for (const item of items) {
|
|
1117
|
+
try {
|
|
1118
|
+
const updated = await this.upsert({ item, execution })
|
|
1119
|
+
result.push(updated)
|
|
1120
|
+
} catch {
|
|
1121
|
+
/* empty */
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return result
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
${Generator.toJsDocComment([`Deletes a ${model.userFriendlyName} and returns its id.`])}
|
|
1128
|
+
public async delete(
|
|
1129
|
+
{ id }: { id: ${model.types.id.name}, execution: ${context.actions.execution.interface.name} }
|
|
1130
|
+
): Promise<${model.types.id.name}> {
|
|
1131
|
+
const existingItem = await this.get(id)
|
|
1132
|
+
if (!existingItem) {
|
|
1133
|
+
throw new Error(\`Could not delete ${model.types.name} with id \${id}. Not found!\`)
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
const release = await this.mutex.acquire()
|
|
1137
|
+
try {
|
|
1138
|
+
this.remove(existingItem)
|
|
1139
|
+
release()
|
|
1140
|
+
return id
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
release()
|
|
1143
|
+
throw error
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
${Generator.toJsDocComment([`Deletes multiple ${model.internalPluralName} and returns their ids.`])}
|
|
1148
|
+
public async deleteMany(
|
|
1149
|
+
{ ids, execution }: { ids: ${model.types.id.name}[], execution: ${context.actions.execution.interface.name} }
|
|
1150
|
+
): Promise<${model.types.id.name}[]> {
|
|
1151
|
+
const deletedIds: ${model.types.id.name}[] = []
|
|
1152
|
+
for (const id of ids) {
|
|
1153
|
+
try {
|
|
1154
|
+
await this.delete({ id, execution })
|
|
1155
|
+
deletedIds.push(id)
|
|
1156
|
+
} catch {
|
|
1157
|
+
/* empty */
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return deletedIds
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
${Generator.toJsDocComment([`Creates a new ${model.userFriendlyName} shallow clone and returns it.`])}
|
|
1164
|
+
public async clone({ id, item, execution }: {
|
|
1165
|
+
id: ${model.types.id.name}
|
|
1166
|
+
item: (item: ${model.types.name}) => ${model.types.dto.clone.name},
|
|
1167
|
+
execution: ${context.actions.execution.interface.name}
|
|
1168
|
+
}): Promise<${model.types.name}> {
|
|
1169
|
+
const source = await this.get(id)
|
|
1170
|
+
if (!source) {
|
|
1171
|
+
throw new Error(\`${model.userFriendlyName} with id \${id} not found\`)
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
const { id: _, ...data } = { ...source, ...item(source) }
|
|
1175
|
+
|
|
1176
|
+
return await this.create({ item: data, execution })
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
${relationsBlocks.getterFunctions.join('\n')}
|
|
1180
|
+
|
|
1181
|
+
${maxLengthBlocks.ensureMaxLengthFunctions.join('\n')}
|
|
1182
|
+
|
|
1183
|
+
${uniqueStringFieldsBlocks.ensureUniqueFunctions.join('\n\n')}
|
|
1184
|
+
|
|
1185
|
+
/**
|
|
1186
|
+
* Function that adds/updates a given item to the internal data store, indexes, etc.
|
|
1187
|
+
*/
|
|
1188
|
+
private set(item: ${model.types.name}): void {
|
|
1189
|
+
${idBlocks.setCode}
|
|
1190
|
+
|
|
1191
|
+
this.data.set(item.id, item)
|
|
1192
|
+
|
|
1193
|
+
${uniqueStringFieldsBlocks.setCode.join('\n')}
|
|
1194
|
+
|
|
1195
|
+
${relationsBlocks.setCode.join('\n')}
|
|
1196
|
+
|
|
1197
|
+
${indexBlocks.setCode.join('\n')}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Function that removes a given item from the internal data store, indexes, etc.
|
|
1202
|
+
*/
|
|
1203
|
+
private remove(item: ${model.types.name}): void {
|
|
1204
|
+
this.data.delete(item.id)
|
|
1205
|
+
${uniqueStringFieldsBlocks.removeCode.join('\n')}
|
|
1206
|
+
|
|
1207
|
+
${relationsBlocks.removeCode.join('\n')}
|
|
1208
|
+
|
|
1209
|
+
${indexBlocks.removeCode.join('\n')}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
`;
|
|
1214
|
+
};
|
|
1215
|
+
exports.generateRepository_InMemory = generateRepository_InMemory;
|
|
1216
|
+
const blankUserRepositorySpecificBlocks = {
|
|
1217
|
+
rootUserNameConst: '',
|
|
1218
|
+
getterBlock: '',
|
|
1219
|
+
initCall: '',
|
|
1220
|
+
rootUserInitializeBlock: '',
|
|
1221
|
+
};
|
|
1222
|
+
function generateUserRepositorySpecificBlocks_Database({ model, context, imports, }) {
|
|
1223
|
+
if (model.name !== 'User') {
|
|
1224
|
+
return blankUserRepositorySpecificBlocks;
|
|
1225
|
+
}
|
|
1226
|
+
const { types, repository } = model;
|
|
1227
|
+
const rootUserValue = generateSharedRootUserBlocks({ model, context, imports });
|
|
1228
|
+
return {
|
|
1229
|
+
rootUserNameConst: `public static readonly ROOT_USER_ID = ${types.id.toBranded.name}('${context.schema.systemUser.id}')`,
|
|
1230
|
+
getterBlock: `
|
|
1231
|
+
// We initialize the root user in the init() function
|
|
1232
|
+
private _rootUser!: ${types.name}
|
|
1233
|
+
public get rootUser(): ${types.name} {
|
|
1234
|
+
return this._rootUser
|
|
1235
|
+
}`,
|
|
1236
|
+
initCall: `await this.initializeRootUser()`,
|
|
1237
|
+
rootUserInitializeBlock: `
|
|
1238
|
+
private async initializeRootUser(): Promise<void> {
|
|
1239
|
+
const existingRootUser = await this.get(${repository.name}.ROOT_USER_ID)
|
|
1240
|
+
if (existingRootUser) {
|
|
1241
|
+
this._rootUser = existingRootUser
|
|
1242
|
+
this.logger.log(\`Root user \${existingRootUser.id} loaded\`)
|
|
1243
|
+
return
|
|
1244
|
+
}
|
|
1245
|
+
this.logger.log('Creating root user ${context.schema.systemUser.id}')
|
|
1246
|
+
const release = await this.mutex.acquire()
|
|
1247
|
+
const rawUser = await this.db.${model.repository.prismaClientName}.create({
|
|
1248
|
+
data: ${model.decoder.flattened.encoder.name}(${rootUserValue} as unknown as any),
|
|
1249
|
+
})
|
|
1250
|
+
const newRootUser = ${model.decoder.flattened.decoder.parseFunction.name}(rawUser)
|
|
1251
|
+
this.set(newRootUser)
|
|
1252
|
+
this._rootUser = newRootUser
|
|
1253
|
+
release()
|
|
1254
|
+
}`,
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function generateUserRepositorySpecificBlocks_InMemory({ model, context, imports, }) {
|
|
1258
|
+
if (model.name !== 'User') {
|
|
1259
|
+
return blankUserRepositorySpecificBlocks;
|
|
1260
|
+
}
|
|
1261
|
+
const { types, repository } = model;
|
|
1262
|
+
const rootUserValue = generateSharedRootUserBlocks({ model, context, imports });
|
|
1263
|
+
return {
|
|
1264
|
+
rootUserNameConst: `public static readonly ROOT_USER_ID = ${types.id.toBranded.name}('${context.schema.systemUser.id}')`,
|
|
1265
|
+
getterBlock: `
|
|
1266
|
+
// We initialize the root user in the init() function
|
|
1267
|
+
private _rootUser!: ${types.name}
|
|
1268
|
+
public get rootUser(): ${types.name} {
|
|
1269
|
+
return this._rootUser
|
|
1270
|
+
}`,
|
|
1271
|
+
initCall: `await this.initializeRootUser()`,
|
|
1272
|
+
rootUserInitializeBlock: `
|
|
1273
|
+
private async initializeRootUser(): Promise<void> {
|
|
1274
|
+
const existingRootUser = await this.get(${repository.name}.ROOT_USER_ID)
|
|
1275
|
+
if (existingRootUser) {
|
|
1276
|
+
this._rootUser = existingRootUser
|
|
1277
|
+
return
|
|
1278
|
+
}
|
|
1279
|
+
const release = await this.mutex.acquire()
|
|
1280
|
+
const rawUser = ${rootUserValue}
|
|
1281
|
+
|
|
1282
|
+
this.verifyItem(rawUser)
|
|
1283
|
+
this.set(rawUser)
|
|
1284
|
+
this._rootUser = rawUser
|
|
1285
|
+
release()
|
|
1286
|
+
}`,
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
function generateSharedRootUserBlocks({ context }) {
|
|
1290
|
+
const rootUser = context.schema.systemUser;
|
|
1291
|
+
return JSON.stringify(rootUser);
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Generates code chunks responsible for verifying the Id validity of a model instance and generating the id
|
|
1295
|
+
* value of a model with auto-generated id.
|
|
1296
|
+
*/
|
|
1297
|
+
function generateIdBlocks_Database({ model, imports }) {
|
|
1298
|
+
const { idField, types, repository } = model;
|
|
1299
|
+
const generatedFields = [];
|
|
1300
|
+
const readonlyFields = [];
|
|
1301
|
+
for (const field of model.fields.values()) {
|
|
1302
|
+
if (field.kind === 'id') {
|
|
1303
|
+
generatedFields.push(field);
|
|
1304
|
+
}
|
|
1305
|
+
else if (field.isReadonly) {
|
|
1306
|
+
readonlyFields.push(field);
|
|
1307
|
+
generatedFields.push(field);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
const verifyFunctionParameterType = `(Omit<${types.name}, ${generatedFields.map((f) => `'${f.name}'`).join(' | ')}> & Partial<{${idField.name}: ${idField.unbrandedTypeName}}>)`;
|
|
1311
|
+
const createFunctionParameterType =
|
|
1312
|
+
// In case we have readonly fields, we need to omit them from the create function.
|
|
1313
|
+
readonlyFields.length === 0
|
|
1314
|
+
? `asserts item is ${types.name}`
|
|
1315
|
+
: `asserts item is Omit<${types.name}, ${readonlyFields.map((f) => `'${f.name}'`).join(' |')}>`;
|
|
1316
|
+
switch (idField.idType) {
|
|
1317
|
+
case 'Increment': {
|
|
1318
|
+
return {
|
|
1319
|
+
generateNextIdFunctionName: `
|
|
1320
|
+
protected currentMaxId = 0
|
|
1321
|
+
public generateNextId(): ${types.id.name} {
|
|
1322
|
+
return ${types.id.toBranded.name}(++this.currentMaxId)
|
|
1323
|
+
}`,
|
|
1324
|
+
initCode: `this.currentMaxId = (await this.db.${repository.prismaClientName}.aggregate({ _max: { ${idField.databaseName}: true } }))._max.${idField.databaseName} ?? 0`,
|
|
1325
|
+
verifyFunctionComment: 'the id is generated by increasing the highest former id and assigned to the item.',
|
|
1326
|
+
verifyFunctionParameterType,
|
|
1327
|
+
verifyCode: `item.${idField.name} = item.${idField.name} !==undefined ? ${types.id.toBranded.name}(item.${idField.name}) : this.generateNextId()`,
|
|
1328
|
+
createFunctionParameterType,
|
|
1329
|
+
setCode: `if (item.id > this.currentMaxId) { this.currentMaxId = item.id }`,
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
case 'UUID': {
|
|
1333
|
+
imports.addImport({
|
|
1334
|
+
from: Generator.toPackageName('node:crypto'),
|
|
1335
|
+
items: [Generator.toFunctionName('randomUUID')],
|
|
1336
|
+
});
|
|
1337
|
+
return {
|
|
1338
|
+
generateNextIdFunctionName: `
|
|
1339
|
+
public generateNextId(): ${types.id.name} {
|
|
1340
|
+
return ${types.id.toBranded.name}(randomUUID())
|
|
1341
|
+
}`,
|
|
1342
|
+
initCode: '',
|
|
1343
|
+
verifyFunctionComment: 'the id is generated by using randomUUID().',
|
|
1344
|
+
verifyFunctionParameterType,
|
|
1345
|
+
verifyCode: `item.${idField.name} = item.${idField.name} ? ${types.id.toBranded.name}(item.${idField.name}) : this.generateNextId()`,
|
|
1346
|
+
createFunctionParameterType,
|
|
1347
|
+
setCode: '',
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
default:
|
|
1351
|
+
throw new utils_1.ExhaustiveSwitchCheck(idField.idType);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Generates code chunks responsible for verifying the Id validity of a model instance and generating the id
|
|
1356
|
+
* value of a model with auto-generated id.
|
|
1357
|
+
*/
|
|
1358
|
+
function generateIdBlocks_InMemory({ model, imports }) {
|
|
1359
|
+
const { idField, types } = model;
|
|
1360
|
+
const generatedFields = [];
|
|
1361
|
+
let createdAtField = undefined;
|
|
1362
|
+
let updatedAtField = undefined;
|
|
1363
|
+
for (const field of model.fields.values()) {
|
|
1364
|
+
if (field.kind === 'id' || field.isReadonly) {
|
|
1365
|
+
generatedFields.push(field);
|
|
1366
|
+
}
|
|
1367
|
+
if (field.kind === 'scalar' && field.isCreatedAt) {
|
|
1368
|
+
createdAtField = field;
|
|
1369
|
+
}
|
|
1370
|
+
if (field.kind === 'scalar' && field.isUpdatedAt) {
|
|
1371
|
+
updatedAtField = field;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
const verifyFunctionParameterType = `(Omit<${types.name}, ${generatedFields.map((f) => `'${f.name}'`).join(' | ')}> & Partial<{${idField.name}: ${idField.unbrandedTypeName}}>)`;
|
|
1375
|
+
const verifyCodeDateFields = `
|
|
1376
|
+
${createdAtField ? `;(item as any).${createdAtField.name} = new Date()` : ''}
|
|
1377
|
+
${updatedAtField ? `;(item as any).${updatedAtField.name} = new Date()` : ''}`;
|
|
1378
|
+
const createFunctionParameterType = `asserts item is ${types.name}`;
|
|
1379
|
+
switch (idField.idType) {
|
|
1380
|
+
case 'Increment': {
|
|
1381
|
+
return {
|
|
1382
|
+
generateNextIdFunctionName: `
|
|
1383
|
+
protected currentMaxId = 0
|
|
1384
|
+
public generateNextId(): ${types.id.name} {
|
|
1385
|
+
return ${types.id.toBranded.name}(++this.currentMaxId)
|
|
1386
|
+
}`,
|
|
1387
|
+
initCode: `this.currentMaxId = 0`,
|
|
1388
|
+
verifyFunctionComment: 'the id is generated by increasing the highest former id and assigned to the item.',
|
|
1389
|
+
verifyFunctionParameterType,
|
|
1390
|
+
verifyCode: `item.${idField.name} = item.${idField.name} === undefined ? this.generateNextId() : ${types.id.toBranded.name}(item.${idField.name})` +
|
|
1391
|
+
verifyCodeDateFields,
|
|
1392
|
+
createFunctionParameterType,
|
|
1393
|
+
setCode: `if (item.id > this.currentMaxId) { this.currentMaxId = item.id }`,
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
case 'UUID': {
|
|
1397
|
+
imports.addImport({
|
|
1398
|
+
from: Generator.toPackageName('node:crypto'),
|
|
1399
|
+
items: [Generator.toFunctionName('randomUUID')],
|
|
1400
|
+
});
|
|
1401
|
+
return {
|
|
1402
|
+
generateNextIdFunctionName: `
|
|
1403
|
+
public generateNextId(): ${types.id.name} {
|
|
1404
|
+
return ${types.id.toBranded.name}(randomUUID())
|
|
1405
|
+
}`,
|
|
1406
|
+
initCode: '',
|
|
1407
|
+
verifyFunctionComment: 'the id is generated by using randomUUID().',
|
|
1408
|
+
verifyFunctionParameterType,
|
|
1409
|
+
verifyCode: `item.${idField.name} = item.${idField.name} ? ${types.id.toBranded.name}(item.${idField.name}) : this.generateNextId()` +
|
|
1410
|
+
verifyCodeDateFields,
|
|
1411
|
+
createFunctionParameterType,
|
|
1412
|
+
setCode: '',
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
default:
|
|
1416
|
+
throw new utils_1.ExhaustiveSwitchCheck(idField.idType);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Returns the code chunks that define the default value property and its initialization.
|
|
1421
|
+
*/
|
|
1422
|
+
function generateDefaultBlocks({ model }) {
|
|
1423
|
+
const { types, repository } = model;
|
|
1424
|
+
const defaultField = model.defaultField;
|
|
1425
|
+
if (!defaultField) {
|
|
1426
|
+
return {
|
|
1427
|
+
init: {
|
|
1428
|
+
ignoreErrorVariableDeclaration: '_ignoreError: boolean',
|
|
1429
|
+
resetCode: '',
|
|
1430
|
+
setCode: '',
|
|
1431
|
+
checkCode: '',
|
|
1432
|
+
},
|
|
1433
|
+
publicVariableDeclaration: '',
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
switch (repository.kind) {
|
|
1437
|
+
case 'DatabaseCached':
|
|
1438
|
+
return {
|
|
1439
|
+
init: {
|
|
1440
|
+
ignoreErrorVariableDeclaration: 'ignoreError: boolean',
|
|
1441
|
+
resetCode: `
|
|
1442
|
+
this.defaultValue = undefined!
|
|
1443
|
+
`,
|
|
1444
|
+
setCode: `
|
|
1445
|
+
if (item.${defaultField.name}) {
|
|
1446
|
+
if (this.defaultValue) {
|
|
1447
|
+
console.warn(\`More than one default ${model.userFriendlyName} found! \${this.defaultValue.id} and \${item.id}\`)
|
|
1448
|
+
}
|
|
1449
|
+
this.defaultValue = item
|
|
1450
|
+
}`,
|
|
1451
|
+
checkCode: `
|
|
1452
|
+
if (!this.defaultValue && !ignoreError) {
|
|
1453
|
+
throw new Error('No default ${model.userFriendlyName} found!')
|
|
1454
|
+
}`,
|
|
1455
|
+
},
|
|
1456
|
+
publicVariableDeclaration: `
|
|
1457
|
+
// We can safely skip the assignment here as this is done in the init function
|
|
1458
|
+
public defaultValue!: ${types.name}
|
|
1459
|
+
`,
|
|
1460
|
+
};
|
|
1461
|
+
case 'InMemory':
|
|
1462
|
+
return {
|
|
1463
|
+
init: {
|
|
1464
|
+
ignoreErrorVariableDeclaration: '_ignoreError: boolean',
|
|
1465
|
+
resetCode: `
|
|
1466
|
+
this.defaultValue = undefined!
|
|
1467
|
+
`,
|
|
1468
|
+
setCode: `
|
|
1469
|
+
if (item.${defaultField.name}) {
|
|
1470
|
+
if (this.defaultValue) {
|
|
1471
|
+
console.warn(\`More than one default ${model.userFriendlyName} found! \${this.defaultValue.id} and \${item.id}\`)
|
|
1472
|
+
}
|
|
1473
|
+
this.defaultValue = item
|
|
1474
|
+
}`,
|
|
1475
|
+
checkCode: `
|
|
1476
|
+
if (!this.defaultValue && !_ignoreError) {
|
|
1477
|
+
throw new Error('No default ${model.userFriendlyName} found!')
|
|
1478
|
+
}`,
|
|
1479
|
+
},
|
|
1480
|
+
publicVariableDeclaration: `
|
|
1481
|
+
// We can safely skip the assignment here as this is done in the init function
|
|
1482
|
+
public defaultValue!: ${types.name}
|
|
1483
|
+
`,
|
|
1484
|
+
};
|
|
1485
|
+
case 'DatabaseDirect':
|
|
1486
|
+
return {
|
|
1487
|
+
init: {
|
|
1488
|
+
ignoreErrorVariableDeclaration: 'ignoreError: boolean',
|
|
1489
|
+
resetCode: `
|
|
1490
|
+
this.defaultValue = undefined!
|
|
1491
|
+
`,
|
|
1492
|
+
setCode: `
|
|
1493
|
+
this.defaultValue = await this.db.${repository.prismaClientName}.findUnique({ where: { ${defaultField.databaseName}: true } })`,
|
|
1494
|
+
checkCode: `
|
|
1495
|
+
if (!this.defaultValue && !ignoreError) {
|
|
1496
|
+
throw new Error('No default ${model.userFriendlyName} found!')
|
|
1497
|
+
}`,
|
|
1498
|
+
},
|
|
1499
|
+
publicVariableDeclaration: `
|
|
1500
|
+
// We can safely skip the assignment here as this is done in the init function
|
|
1501
|
+
public defaultValue!: ${types.name}
|
|
1502
|
+
`,
|
|
1503
|
+
};
|
|
1504
|
+
default:
|
|
1505
|
+
throw new utils_1.ExhaustiveSwitchCheck(repository);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
function hasMaxLength(field) {
|
|
1509
|
+
return field.kind === 'scalar' && field.type === 'string' && field.validations.maxLength !== undefined;
|
|
1510
|
+
}
|
|
1511
|
+
function isUniqueField(field) {
|
|
1512
|
+
return field.isUnique;
|
|
1513
|
+
}
|
|
1514
|
+
function initUniqueIds() {
|
|
1515
|
+
return {
|
|
1516
|
+
mapDeclarations: [],
|
|
1517
|
+
getByFunctions: [],
|
|
1518
|
+
clearCode: [],
|
|
1519
|
+
verifyFunctionComment: '',
|
|
1520
|
+
verifyCode: [],
|
|
1521
|
+
updateCode: [],
|
|
1522
|
+
ensureUniqueFunctions: [],
|
|
1523
|
+
setCode: [],
|
|
1524
|
+
removeCode: [],
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Generates code chunks that enforce the uniqueness of a given field.
|
|
1529
|
+
*/
|
|
1530
|
+
function generateUniqueFieldsBlocks_Cached({ model }) {
|
|
1531
|
+
const fields = [];
|
|
1532
|
+
for (const field of model.fields.values()) {
|
|
1533
|
+
if (isUniqueField(field)) {
|
|
1534
|
+
fields.push(field);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
const result = initUniqueIds();
|
|
1538
|
+
for (const f of fields) {
|
|
1539
|
+
const returnType = `string${f.isRequired ? '' : ' | null'}`;
|
|
1540
|
+
result.mapDeclarations.push(`'${f.name}': new Map<string, ${model.types.name}>()`);
|
|
1541
|
+
result.getByFunctions.push(`
|
|
1542
|
+
|
|
1543
|
+
public async getBy${(0, utils_1.toPascalCase)(f.name)}(${f.name}: ${returnType}): Promise<${model.types.name} | undefined> {
|
|
1544
|
+
${f.isRequired
|
|
1545
|
+
? ''
|
|
1546
|
+
: `if (${f.name} === null) {
|
|
1547
|
+
return Promise.resolve(undefined) // NOSONAR
|
|
1548
|
+
}`}
|
|
1549
|
+
await this.mutex.waitForUnlock()
|
|
1550
|
+
return Promise.resolve(this.uniqueIds.${f.name}.get(${f.name})) // NOSONAR
|
|
1551
|
+
}`);
|
|
1552
|
+
result.clearCode.push(`this.uniqueIds.${f.name}.clear()`);
|
|
1553
|
+
result.verifyCode.push(`this.${getEnsureUniqueFnName(f)}(item)`);
|
|
1554
|
+
result.updateCode.push(`
|
|
1555
|
+
if (item.${f.name} !== undefined && existingItem.${f.name} !== item.${f.name}) {
|
|
1556
|
+
this.${getEnsureUniqueFnName(f)}(item)
|
|
1557
|
+
}`);
|
|
1558
|
+
result.ensureUniqueFunctions.push(`
|
|
1559
|
+
/**
|
|
1560
|
+
* Utility function that ensures that the ${f.name} field is unique
|
|
1561
|
+
*/
|
|
1562
|
+
private ${getEnsureUniqueFnName(f)}(item: { ${f.name}?: ${returnType} }) {
|
|
1563
|
+
if (item.${f.name} === null || item.${f.name} === undefined) { return }
|
|
1564
|
+
if (!this.uniqueIds.${f.name}.has(item.${f.name})) {
|
|
1565
|
+
return
|
|
1566
|
+
}
|
|
1567
|
+
let counter = 1
|
|
1568
|
+
|
|
1569
|
+
let ${f.name}: string
|
|
1570
|
+
const source${(0, utils_1.toPascalCase)(f.name)} =${hasMaxLength(f) ? `item.${f.name}.substring(0, ${f.validations.maxLength - 5})` : `item.${f.name}`}
|
|
1571
|
+
|
|
1572
|
+
do {
|
|
1573
|
+
${f.name} = \`\${source${(0, utils_1.toPascalCase)(f.name)}} (\${++counter})\`
|
|
1574
|
+
} while (this.uniqueIds.${f.name}.has(${f.name}))
|
|
1575
|
+
|
|
1576
|
+
this.logger.log(\`${model.types.name} ${f.name} "\${item.${f.name}}" already exists. Renaming to "\${${f.name}}")\`)
|
|
1577
|
+
item.${f.name} = ${f.name}
|
|
1578
|
+
}`);
|
|
1579
|
+
if (f.isRequired) {
|
|
1580
|
+
result.setCode.push(`this.uniqueIds.${f.name}.set(item.${f.name}, item)`);
|
|
1581
|
+
result.removeCode.push(`this.uniqueIds.${f.name}.delete(item.${f.name})`);
|
|
1582
|
+
}
|
|
1583
|
+
else {
|
|
1584
|
+
result.setCode.push(`if (item.${f.name} !== null) { this.uniqueIds.${f.name}.set(item.${f.name}, item) }`);
|
|
1585
|
+
result.removeCode.push(`if (item.${f.name} !== null) { this.uniqueIds.${f.name}.delete(item.${f.name}) }`);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
if (fields.length > 1) {
|
|
1589
|
+
result.verifyFunctionComment = `In case a value of the fields ${fields
|
|
1590
|
+
.map((f) => f.name)
|
|
1591
|
+
.join(', ')} is not unique, it is renamed.\n`;
|
|
1592
|
+
}
|
|
1593
|
+
else if (fields.length === 1) {
|
|
1594
|
+
result.verifyFunctionComment = `In case the value of the field ${fields[0].name} is not unique, it is renamed.\n`;
|
|
1595
|
+
}
|
|
1596
|
+
return result;
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Generates code chunks that enforce the uniqueness of a given field.
|
|
1600
|
+
*/
|
|
1601
|
+
function generateUniqueFieldsBlocks_Database({ model, }) {
|
|
1602
|
+
const { types, repository } = model;
|
|
1603
|
+
const fields = [];
|
|
1604
|
+
for (const field of model.fields.values()) {
|
|
1605
|
+
if (isUniqueField(field)) {
|
|
1606
|
+
fields.push(field);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
const result = initUniqueIds();
|
|
1610
|
+
for (const f of fields) {
|
|
1611
|
+
const returnType = `string${f.isRequired ? '' : ' | null'}`;
|
|
1612
|
+
result.getByFunctions.push(`
|
|
1613
|
+
|
|
1614
|
+
public async getBy${(0, utils_1.toPascalCase)(f.name)}(${f.name}: ${returnType}): Promise<${types.name} | undefined> {
|
|
1615
|
+
${f.isRequired ? '' : `if (${f.name} === null) { return undefined }`}
|
|
1616
|
+
await this.mutex.waitForUnlock()
|
|
1617
|
+
const result = await this.db.${repository.prismaClientName}.findUnique({ where: { ${f.databaseName}: ${f.name} } })
|
|
1618
|
+
if (result === null) {
|
|
1619
|
+
return undefined
|
|
1620
|
+
}
|
|
1621
|
+
return ${model.decoder.flattened.decoder.parseFunction.name}(result)
|
|
1622
|
+
}`);
|
|
1623
|
+
result.verifyCode.push(`await this.${getEnsureUniqueFnName(f)}(item)`);
|
|
1624
|
+
result.updateCode.push(`
|
|
1625
|
+
if (item.${f.name} !== undefined && existingItem.${f.name} !== item.${f.name}) {
|
|
1626
|
+
await this.${getEnsureUniqueFnName(f)}(item)
|
|
1627
|
+
}`);
|
|
1628
|
+
result.ensureUniqueFunctions.push(`
|
|
1629
|
+
/**
|
|
1630
|
+
* Utility function that ensures that the ${f.name} field is unique
|
|
1631
|
+
*/
|
|
1632
|
+
private async ${getEnsureUniqueFnName(f)}(item: { ${f.name}: ${returnType} }) {
|
|
1633
|
+
if (item.${f.name} === undefined) { return }
|
|
1634
|
+
let counter = 1
|
|
1635
|
+
|
|
1636
|
+
let ${f.name}: string = item.${f.name}
|
|
1637
|
+
const source${(0, utils_1.toPascalCase)(f.name)} =${hasMaxLength(f) ? `item.${f.name}.substring(0, ${f.validations.maxLength - 5})` : `item.${f.name}`}
|
|
1638
|
+
|
|
1639
|
+
while ((await this.db.${repository.prismaClientName}.findUnique({ where: { ${f.databaseName}: ${f.name} } })) !== null) {
|
|
1640
|
+
${f.name} = \`\${source${(0, utils_1.toPascalCase)(f.name)}} (\${++counter})\`
|
|
1641
|
+
}
|
|
1642
|
+
if (counter !== 1) {
|
|
1643
|
+
this.logger.log(\`${types.name} ${f.name} "\${item.${f.name}}" already exists. Renaming to "\${${f.name}}")\`)
|
|
1644
|
+
item.${f.name} = ${f.name}
|
|
1645
|
+
}
|
|
1646
|
+
}`);
|
|
1647
|
+
}
|
|
1648
|
+
if (fields.length > 1) {
|
|
1649
|
+
result.verifyFunctionComment = `In case a value of the fields ${fields
|
|
1650
|
+
.map((f) => f.name)
|
|
1651
|
+
.join(', ')} is not unique, it is renamed.\n`;
|
|
1652
|
+
}
|
|
1653
|
+
else if (fields.length === 1) {
|
|
1654
|
+
result.verifyFunctionComment = `In case the value of the field ${fields[0].name} is not unique, it is renamed.\n`;
|
|
1655
|
+
}
|
|
1656
|
+
return result;
|
|
1657
|
+
}
|
|
1658
|
+
function getEnsureUniqueFnName(field) {
|
|
1659
|
+
return `ensureUnique${(0, utils_1.toPascalCase)(field.name)}`;
|
|
1660
|
+
}
|
|
1661
|
+
function generateMaxLengthBlocks({ model }) {
|
|
1662
|
+
const fields = [];
|
|
1663
|
+
for (const field of model.fields.values()) {
|
|
1664
|
+
if (hasMaxLength(field)) {
|
|
1665
|
+
fields.push(field);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
const result = {
|
|
1669
|
+
verifyFunctionComment: '',
|
|
1670
|
+
verifyCode: [],
|
|
1671
|
+
updateCode: [],
|
|
1672
|
+
ensureMaxLengthFunctions: [],
|
|
1673
|
+
};
|
|
1674
|
+
for (const f of fields) {
|
|
1675
|
+
result.verifyCode.push(`this.${getEnsureMaxLengthFnName(f)}(item)`);
|
|
1676
|
+
result.updateCode.push(`
|
|
1677
|
+
if (item.${f.name} !== undefined && existingItem.${f.name} !== item.${f.name}) {
|
|
1678
|
+
this.${getEnsureMaxLengthFnName(f)}(item)
|
|
1679
|
+
}`);
|
|
1680
|
+
result.ensureMaxLengthFunctions.push(`
|
|
1681
|
+
/**
|
|
1682
|
+
* Utility function that ensures that the ${f.name} field has a max length of ${f.validations.maxLength}
|
|
1683
|
+
*/
|
|
1684
|
+
private ${getEnsureMaxLengthFnName(f)}(item: { ${f.name}?: string }) {
|
|
1685
|
+
if (item.${f.name} === undefined) {
|
|
1686
|
+
return
|
|
1687
|
+
}
|
|
1688
|
+
if (item.${f.name}.length <= ${f.validations.maxLength}) {
|
|
1689
|
+
return
|
|
1690
|
+
}
|
|
1691
|
+
item.${f.name} = item.${f.name}.substring(0, ${f.validations.maxLength - 4}) + \`...\`
|
|
1692
|
+
}`);
|
|
1693
|
+
}
|
|
1694
|
+
if (fields.length > 1) {
|
|
1695
|
+
result.verifyFunctionComment = `In case a value of the fields ${fields
|
|
1696
|
+
.map((f) => f.name)
|
|
1697
|
+
.join(', ')} exceeds its max length, it is truncated.\n`;
|
|
1698
|
+
}
|
|
1699
|
+
else if (fields.length === 1) {
|
|
1700
|
+
result.verifyFunctionComment = `In case the value of the field ${fields[0].name} exceeds its max length, it is truncated.\n`;
|
|
1701
|
+
}
|
|
1702
|
+
return result;
|
|
1703
|
+
}
|
|
1704
|
+
function getEnsureMaxLengthFnName(field) {
|
|
1705
|
+
return `ensureMaxLength${(0, utils_1.toPascalCase)(field.name)}`;
|
|
1706
|
+
}
|
|
1707
|
+
function generateValidationBlocks({ model }) {
|
|
1708
|
+
const result = {
|
|
1709
|
+
verifyCode: [],
|
|
1710
|
+
};
|
|
1711
|
+
for (const f of model.fields.values()) {
|
|
1712
|
+
if (f.kind !== 'scalar' || f.type !== 'number') {
|
|
1713
|
+
continue;
|
|
1714
|
+
}
|
|
1715
|
+
const itemExists = f.isRequired ? '' : `item.${f.name} !== null && `;
|
|
1716
|
+
if (f.validations.type === 'int') {
|
|
1717
|
+
result.verifyCode.push(`
|
|
1718
|
+
// ensure that ${f.name} is an integer
|
|
1719
|
+
if (${itemExists}item.${f.name} !== Math.floor(item.${f.name})) {
|
|
1720
|
+
throw new Error(\`Invalid value for field ${f.name}: \${item.${f.name}}. Value must be an integer.\`)
|
|
1721
|
+
}`);
|
|
1722
|
+
}
|
|
1723
|
+
if (f.validations.min !== undefined) {
|
|
1724
|
+
result.verifyCode.push(`
|
|
1725
|
+
// ensure that ${f.name} is at least ${f.validations.min}
|
|
1726
|
+
if (${itemExists}item.${f.name} < ${f.validations.min}) {
|
|
1727
|
+
throw new Error(\`Invalid value for field ${f.name}: \${item.${f.name}}. Value must be at least ${f.validations.min}.\`)
|
|
1728
|
+
}`);
|
|
1729
|
+
}
|
|
1730
|
+
if (f.validations.max !== undefined) {
|
|
1731
|
+
result.verifyCode.push(`
|
|
1732
|
+
// ensure that ${f.name} is at most ${f.validations.max}
|
|
1733
|
+
if (${itemExists}item.${f.name} > ${f.validations.max}) {
|
|
1734
|
+
throw new Error(\`Invalid value for field ${f.name}: \${item.${f.name}}. Value must be at most ${f.validations.max}.\`)
|
|
1735
|
+
}`);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
return result;
|
|
1739
|
+
}
|
|
1740
|
+
function initIndexBlockOptions() {
|
|
1741
|
+
return {
|
|
1742
|
+
nestedMapDeclarations: [],
|
|
1743
|
+
initCode: [],
|
|
1744
|
+
initLogCode: [],
|
|
1745
|
+
getterFunctions: [],
|
|
1746
|
+
setCode: [],
|
|
1747
|
+
removeCode: [],
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
function generateIndexBlocks_Database({ model, imports, }) {
|
|
1751
|
+
const { types, repository } = model;
|
|
1752
|
+
const result = initIndexBlockOptions();
|
|
1753
|
+
const indexes = model.indexes;
|
|
1754
|
+
if (indexes.length === 0) {
|
|
1755
|
+
return result;
|
|
1756
|
+
}
|
|
1757
|
+
imports.addImport({ items: [Generator.toClassName('NestedMap')], from: Generator.toPackageName('@postxl/utils') });
|
|
1758
|
+
for (const index of indexes) {
|
|
1759
|
+
const i = getIndexDefinition({ index, model });
|
|
1760
|
+
result.getterFunctions.push(`
|
|
1761
|
+
public async getFrom${indexes.length === 1 ? 'Index' : (0, utils_1.toPascalCase)(i.name)}
|
|
1762
|
+
({ ${i.fields.map((f) => f.name).join(',')} }: { ${i.fields
|
|
1763
|
+
.map((f) => `${f.name} : ${f.type}`)
|
|
1764
|
+
.join(';')} }): ${types.name} | null {
|
|
1765
|
+
return this.db.${repository.prismaClientName}.findUnique({ where: { ${i.fields.map((f) => f.name).join(',')} } }) ? ${model.decoder.flattened.decoder.parseFunction.name}(await this.db.${repository.prismaClientName}.findUnique({ where: { ${i.fields.map((f) => f.name).join(',')} } })) : null
|
|
1766
|
+
}`);
|
|
1767
|
+
}
|
|
1768
|
+
return result;
|
|
1769
|
+
}
|
|
1770
|
+
function generateIndexBlocks_Cached({ model, imports, }) {
|
|
1771
|
+
const result = initIndexBlockOptions();
|
|
1772
|
+
const indexes = model.indexes;
|
|
1773
|
+
if (indexes.length === 0) {
|
|
1774
|
+
return result;
|
|
1775
|
+
}
|
|
1776
|
+
imports.addImport({ items: [Generator.toClassName('NestedMap')], from: Generator.toPackageName('@postxl/utils') });
|
|
1777
|
+
for (const index of indexes) {
|
|
1778
|
+
const i = getIndexDefinition({ index, model });
|
|
1779
|
+
result.nestedMapDeclarations.push(`
|
|
1780
|
+
protected ${i.name} = new NestedMap<${i.fields.map((f) => f.type).join(',')}, ${model.types.name}>(
|
|
1781
|
+
${i.fields.map((f) => `(x) => x.${f.name}`).join(',')}
|
|
1782
|
+
)`);
|
|
1783
|
+
result.initCode.push(`this.${i.name}.clear()`);
|
|
1784
|
+
result.initLogCode.push(`this.logger.log(\`\${this.${i.name}.size} ${model.types.name} loaded into index ${i.name}\`)`);
|
|
1785
|
+
result.getterFunctions.push(`
|
|
1786
|
+
public getFrom${indexes.length === 1 ? 'Index' : (0, utils_1.toPascalCase)(i.name)}
|
|
1787
|
+
({ ${i.fields.map((f) => f.name).join(',')} }: { ${i.fields
|
|
1788
|
+
.map((f) => `${f.name} : ${f.type}`)
|
|
1789
|
+
.join(';')} }): ${model.types.name} | null {
|
|
1790
|
+
return this.${i.name}.get(${i.fields.map((f) => f.name).join(',')}) ?? null
|
|
1791
|
+
}`);
|
|
1792
|
+
result.setCode.push(`this.${i.name}.set(item)`);
|
|
1793
|
+
result.removeCode.push(`this.${i.name}.delete(item)`);
|
|
1794
|
+
}
|
|
1795
|
+
return result;
|
|
1796
|
+
}
|
|
1797
|
+
function getIndexDefinition({ index, model, }) {
|
|
1798
|
+
const name = (0, utils_1.toCamelCase)(`${index.map((f) => (0, utils_1.toPascalCase)(f)).join('')}Index`);
|
|
1799
|
+
const fields = [];
|
|
1800
|
+
for (const fieldName of index) {
|
|
1801
|
+
const field = model.fields.get(fieldName);
|
|
1802
|
+
if (!field) {
|
|
1803
|
+
throw new Error(`Index field ${fieldName} not found in model ${model.name}`);
|
|
1804
|
+
}
|
|
1805
|
+
if (field.kind !== 'relation') {
|
|
1806
|
+
throw new Error(`Index field ${fieldName} is not a relation in model ${model.name}`);
|
|
1807
|
+
}
|
|
1808
|
+
fields.push(field);
|
|
1809
|
+
}
|
|
1810
|
+
return { name, fields };
|
|
1811
|
+
}
|
|
1812
|
+
function initRelationsBlockOptions() {
|
|
1813
|
+
return {
|
|
1814
|
+
mapDeclarations: [],
|
|
1815
|
+
clearCode: [],
|
|
1816
|
+
getterFunctions: [],
|
|
1817
|
+
setCode: [],
|
|
1818
|
+
removeCode: [],
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
function generateRelationsBlocks_Cached({ model, context, imports }) {
|
|
1822
|
+
const relations = Array.from(model.fields.values()).filter((f) => f.kind === 'relation');
|
|
1823
|
+
const result = initRelationsBlockOptions();
|
|
1824
|
+
for (const r of relations) {
|
|
1825
|
+
const relationModel = context.models.get(r.referencedModelName);
|
|
1826
|
+
imports.addType(relationModel.types.id);
|
|
1827
|
+
result.mapDeclarations.push(`protected ${r.name}Map: Map<${relationModel.types.id.name}, Map<${model.types.id.name}, ${model.types.name}>> = new Map()`);
|
|
1828
|
+
result.clearCode.push(`this.${r.name}Map.clear()`);
|
|
1829
|
+
result.getterFunctions.push(`
|
|
1830
|
+
/**
|
|
1831
|
+
* Function to retrieve all ${model.internalPluralName} that are related to a ${r.name}
|
|
1832
|
+
*/
|
|
1833
|
+
public async getItemsFor${(0, utils_1.toPascalCase)(r.name)}(
|
|
1834
|
+
id: ${relationModel.types.id.name}
|
|
1835
|
+
): Promise<Map<${model.types.id.name}, ${model.types.name}>> {
|
|
1836
|
+
const result = this.${r.name}Map.get(id)
|
|
1837
|
+
if (!result) {
|
|
1838
|
+
return Promise.resolve(new Map<${model.types.id.name}, ${model.types.name}>()) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1839
|
+
}
|
|
1840
|
+
return Promise.resolve(new Map(result)) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
/**
|
|
1844
|
+
* Function to retrieve all ${model.types.id.name}s that are related to a ${r.name}
|
|
1845
|
+
*/
|
|
1846
|
+
public async getIdsFor${(0, utils_1.toPascalCase)(r.name)}(
|
|
1847
|
+
id: ${relationModel.types.id.name}
|
|
1848
|
+
): Promise<${model.types.id.name}[]> {
|
|
1849
|
+
const s = this.${r.name}Map.get(id)
|
|
1850
|
+
if (!s) {
|
|
1851
|
+
return Promise.resolve([]) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
return Promise.resolve(Array.from(s.keys())) // NOSONAR - keep all validations async to adhere to the same interface
|
|
1855
|
+
}`);
|
|
1856
|
+
result.setCode.push(`
|
|
1857
|
+
${r.isRequired ? '' : `if (item.${r.name}) {`}
|
|
1858
|
+
let ${r.name}Map = this.${r.name}Map.get(item.${r.name})
|
|
1859
|
+
if (!${r.name}Map) {
|
|
1860
|
+
${r.name}Map = new Map()
|
|
1861
|
+
this.${r.name}Map.set(item.${r.name}, ${r.name}Map)
|
|
1862
|
+
}
|
|
1863
|
+
${r.name}Map.set(item.id, item)
|
|
1864
|
+
${r.isRequired ? '' : `}`}`);
|
|
1865
|
+
result.removeCode.push(`
|
|
1866
|
+
${r.isRequired ? '' : `if (item.${r.name}) {`}
|
|
1867
|
+
const ${r.name}Map = this.${r.name}Map.get(item.${r.name})
|
|
1868
|
+
if (${r.name}Map) {
|
|
1869
|
+
${r.name}Map.delete(item.id)
|
|
1870
|
+
if (${r.name}Map.size === 0) {
|
|
1871
|
+
this.${r.name}Map.delete(item.${r.name})
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
${r.isRequired ? '' : '}'}
|
|
1875
|
+
`);
|
|
1876
|
+
}
|
|
1877
|
+
return result;
|
|
1878
|
+
}
|
|
1879
|
+
function generateRelationsBlocks_Database({ model, context, imports, }) {
|
|
1880
|
+
const { types, repository } = model;
|
|
1881
|
+
const relations = Array.from(model.fields.values()).filter((f) => f.kind === 'relation');
|
|
1882
|
+
const result = initRelationsBlockOptions();
|
|
1883
|
+
for (const r of relations) {
|
|
1884
|
+
const relationModel = context.models.get(r.referencedModelName);
|
|
1885
|
+
imports.addType(relationModel.types.id);
|
|
1886
|
+
result.getterFunctions.push(`
|
|
1887
|
+
/**
|
|
1888
|
+
* Function to retrieve all ${model.internalPluralName} that are related to a ${r.name}
|
|
1889
|
+
*/
|
|
1890
|
+
public async getItemsFor${(0, utils_1.toPascalCase)(r.name)}(
|
|
1891
|
+
id: ${relationModel.types.id.name}
|
|
1892
|
+
): Promise<Map<${types.id.name}, ${types.name}>> {
|
|
1893
|
+
const data = await this.db.${repository.prismaClientName}.findMany({ where: { ${r.databaseName}: id } })
|
|
1894
|
+
const result = new Map<${types.id.name}, ${types.name}>()
|
|
1895
|
+
for (const rawItem of data) {
|
|
1896
|
+
const item = ${model.decoder.flattened.decoder.parseFunction.name}(rawItem)
|
|
1897
|
+
result.set(item.id, item)
|
|
1898
|
+
}
|
|
1899
|
+
return result
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
/**
|
|
1903
|
+
* Function to retrieve all ${types.id.name}s that are related to a ${r.name}
|
|
1904
|
+
*/
|
|
1905
|
+
public async getIdsFor${(0, utils_1.toPascalCase)(r.name)}(
|
|
1906
|
+
id: ${types.id.name}
|
|
1907
|
+
): Promise<${types.id.name}[]> {
|
|
1908
|
+
const data = await this.db.${repository.prismaClientName}.findMany({ where: { ${r.databaseName}: id } })
|
|
1909
|
+
return data.map(({ id }) => ${types.id.toBranded.name}(id))
|
|
1910
|
+
}`);
|
|
1911
|
+
}
|
|
1912
|
+
return result;
|
|
1913
|
+
}
|
|
1914
|
+
function getFieldUpdateAssignment(field) {
|
|
1915
|
+
if (field.kind !== 'discriminatedUnion') {
|
|
1916
|
+
return `${field.databaseName}: item.${field.name} ${field.isRequired ? `?? existingItem.${field.name}` : ''}`;
|
|
1917
|
+
}
|
|
1918
|
+
const assignments = [];
|
|
1919
|
+
assignments.push(`${field.name}: item.${field.name} === undefined ? existingItem.${field.name}.type : item.${field.name}.type`);
|
|
1920
|
+
for (const f of field.commonFields.values()) {
|
|
1921
|
+
assignments.push(`${f.databaseName}: item.${field.name} === undefined ? existingItem.${field.name}.${f.name} : item.${field.name}.${f.name}${f.isRequired ? `?? existingItem.${field.name}.${f.name}` : ''}`);
|
|
1922
|
+
}
|
|
1923
|
+
for (const member of field.members.values()) {
|
|
1924
|
+
for (const f of member.fields.values()) {
|
|
1925
|
+
assignments.push(`${f.databaseName}:
|
|
1926
|
+
item.${field.name} === undefined
|
|
1927
|
+
? (existingItem.${field.name}.type === '${member.type}' ? existingItem.${field.name}.${f.name} : null)
|
|
1928
|
+
: (item.${field.name}.type === '${member.type}' ? item.${field.name}.${f.name} : null)`);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return assignments.join(',\n');
|
|
1932
|
+
}
|
|
1933
|
+
function skipIf(condition, text) {
|
|
1934
|
+
return condition ? '' : text; // NOSONAR
|
|
1935
|
+
}
|
|
1936
|
+
//# sourceMappingURL=model-repository.generator.js.map
|