@solidxai/core 0.1.9-beta.5 → 0.1.9-beta.7

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.
Files changed (159) hide show
  1. package/dist/helpers/bootstrap.helper.d.ts.map +1 -1
  2. package/dist/helpers/bootstrap.helper.js +4 -1
  3. package/dist/helpers/bootstrap.helper.js.map +1 -1
  4. package/dist/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.js +5 -5
  5. package/dist/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.js.map +1 -1
  6. package/dist/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.d.ts.map +1 -1
  7. package/dist/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.js +2 -2
  8. package/dist/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.js.map +1 -1
  9. package/dist/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.js +5 -5
  10. package/dist/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.js.map +1 -1
  11. package/dist/helpers/module-metadata-helper.service.js +3 -3
  12. package/dist/helpers/module-metadata-helper.service.js.map +1 -1
  13. package/dist/helpers/string.helper.d.ts +1 -0
  14. package/dist/helpers/string.helper.d.ts.map +1 -1
  15. package/dist/helpers/string.helper.js +4 -1
  16. package/dist/helpers/string.helper.js.map +1 -1
  17. package/dist/interfaces/mq.d.ts +1 -1
  18. package/dist/interfaces/mq.d.ts.map +1 -1
  19. package/dist/interfaces/mq.js.map +1 -1
  20. package/dist/jobs/database/api-email-subscriber-database.service.d.ts +1 -1
  21. package/dist/jobs/database/api-email-subscriber-database.service.js +1 -1
  22. package/dist/jobs/database/api-email-subscriber-database.service.js.map +1 -1
  23. package/dist/jobs/database/msg91-whatsapp-subscriber-database.service.d.ts +1 -1
  24. package/dist/jobs/database/msg91-whatsapp-subscriber-database.service.js +1 -1
  25. package/dist/jobs/database/msg91-whatsapp-subscriber-database.service.js.map +1 -1
  26. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.d.ts +1 -1
  27. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.js +1 -1
  28. package/dist/jobs/database/three60-whatsapp-subscriber-database.service.js.map +1 -1
  29. package/dist/jobs/rabbitmq/api-email-subscriber.service.d.ts +1 -1
  30. package/dist/jobs/rabbitmq/api-email-subscriber.service.js +1 -1
  31. package/dist/jobs/rabbitmq/api-email-subscriber.service.js.map +1 -1
  32. package/dist/jobs/rabbitmq/msg91-whatsapp-subscriber.service.d.ts +1 -1
  33. package/dist/jobs/rabbitmq/msg91-whatsapp-subscriber.service.js +1 -1
  34. package/dist/jobs/rabbitmq/msg91-whatsapp-subscriber.service.js.map +1 -1
  35. package/dist/jobs/rabbitmq/test-queue-subscriber.service.d.ts +1 -1
  36. package/dist/jobs/rabbitmq/test-queue-subscriber.service.d.ts.map +1 -1
  37. package/dist/jobs/rabbitmq/test-queue-subscriber.service.js +6 -3
  38. package/dist/jobs/rabbitmq/test-queue-subscriber.service.js.map +1 -1
  39. package/dist/jobs/rabbitmq/three60-whatsapp-subscriber.service.d.ts +1 -1
  40. package/dist/jobs/rabbitmq/three60-whatsapp-subscriber.service.js +1 -1
  41. package/dist/jobs/rabbitmq/three60-whatsapp-subscriber.service.js.map +1 -1
  42. package/dist/jobs/redis/api-email-subscriber-redis.service.d.ts +1 -1
  43. package/dist/jobs/redis/api-email-subscriber-redis.service.js +1 -1
  44. package/dist/jobs/redis/api-email-subscriber-redis.service.js.map +1 -1
  45. package/dist/jobs/redis/msg91-whatsapp-subscriber-redis.service.d.ts +1 -1
  46. package/dist/jobs/redis/msg91-whatsapp-subscriber-redis.service.js +1 -1
  47. package/dist/jobs/redis/msg91-whatsapp-subscriber-redis.service.js.map +1 -1
  48. package/dist/jobs/redis/three60-whatsapp-subscriber-redis.service.d.ts +1 -1
  49. package/dist/jobs/redis/three60-whatsapp-subscriber-redis.service.js +1 -1
  50. package/dist/jobs/redis/three60-whatsapp-subscriber-redis.service.js.map +1 -1
  51. package/dist/repository/chatter-message-details.repository.d.ts.map +1 -1
  52. package/dist/repository/chatter-message-details.repository.js +7 -6
  53. package/dist/repository/chatter-message-details.repository.js.map +1 -1
  54. package/dist/repository/chatter-message.repository.d.ts.map +1 -1
  55. package/dist/repository/chatter-message.repository.js +4 -4
  56. package/dist/repository/chatter-message.repository.js.map +1 -1
  57. package/dist/repository/solid-base.repository.js +2 -2
  58. package/dist/repository/solid-base.repository.js.map +1 -1
  59. package/dist/seeders/module-test-data.service.js +4 -4
  60. package/dist/seeders/module-test-data.service.js.map +1 -1
  61. package/dist/seeders/seed-data/solid-core-metadata.json +7 -3
  62. package/dist/services/chatter-message.service.d.ts.map +1 -1
  63. package/dist/services/chatter-message.service.js +7 -7
  64. package/dist/services/chatter-message.service.js.map +1 -1
  65. package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.d.ts.map +1 -1
  66. package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.js +2 -2
  67. package/dist/services/computed-fields/entity/sequence-num-computed-field-provider.js.map +1 -1
  68. package/dist/services/crud-helper.service.d.ts.map +1 -1
  69. package/dist/services/crud-helper.service.js +9 -9
  70. package/dist/services/crud-helper.service.js.map +1 -1
  71. package/dist/services/export-transaction.service.d.ts.map +1 -1
  72. package/dist/services/export-transaction.service.js +4 -3
  73. package/dist/services/export-transaction.service.js.map +1 -1
  74. package/dist/services/field-metadata.service.d.ts.map +1 -1
  75. package/dist/services/field-metadata.service.js +7 -7
  76. package/dist/services/field-metadata.service.js.map +1 -1
  77. package/dist/services/fixtures.service.js +2 -2
  78. package/dist/services/fixtures.service.js.map +1 -1
  79. package/dist/services/genai/mcp-handlers/mcp-handler-factory.service.d.ts.map +1 -1
  80. package/dist/services/genai/mcp-handlers/mcp-handler-factory.service.js +2 -2
  81. package/dist/services/genai/mcp-handlers/mcp-handler-factory.service.js.map +1 -1
  82. package/dist/services/import-transaction.service.d.ts.map +1 -1
  83. package/dist/services/import-transaction.service.js +2 -2
  84. package/dist/services/import-transaction.service.js.map +1 -1
  85. package/dist/services/menu-item-metadata.service.js +2 -2
  86. package/dist/services/menu-item-metadata.service.js.map +1 -1
  87. package/dist/services/model-metadata.service.d.ts.map +1 -1
  88. package/dist/services/model-metadata.service.js +11 -10
  89. package/dist/services/model-metadata.service.js.map +1 -1
  90. package/dist/services/module-metadata.service.d.ts.map +1 -1
  91. package/dist/services/module-metadata.service.js +2 -2
  92. package/dist/services/module-metadata.service.js.map +1 -1
  93. package/dist/services/queues/database-subscriber.service.d.ts +1 -1
  94. package/dist/services/queues/database-subscriber.service.d.ts.map +1 -1
  95. package/dist/services/queues/database-subscriber.service.js.map +1 -1
  96. package/dist/services/queues/publisher-factory.service.d.ts.map +1 -1
  97. package/dist/services/queues/publisher-factory.service.js +2 -2
  98. package/dist/services/queues/publisher-factory.service.js.map +1 -1
  99. package/dist/services/queues/rabbitmq-subscriber.service.d.ts +1 -1
  100. package/dist/services/queues/rabbitmq-subscriber.service.d.ts.map +1 -1
  101. package/dist/services/queues/rabbitmq-subscriber.service.js +3 -1
  102. package/dist/services/queues/rabbitmq-subscriber.service.js.map +1 -1
  103. package/dist/services/queues/redis-subscriber.service.d.ts +1 -1
  104. package/dist/services/queues/redis-subscriber.service.d.ts.map +1 -1
  105. package/dist/services/queues/redis-subscriber.service.js.map +1 -1
  106. package/dist/services/selection-providers/pseudo-foreign-key-selection-provider.service.js +3 -3
  107. package/dist/services/selection-providers/pseudo-foreign-key-selection-provider.service.js.map +1 -1
  108. package/dist/services/solid-introspect.service.js +2 -2
  109. package/dist/services/solid-introspect.service.js.map +1 -1
  110. package/dist/services/view-metadata.service.d.ts.map +1 -1
  111. package/dist/services/view-metadata.service.js +2 -2
  112. package/dist/services/view-metadata.service.js.map +1 -1
  113. package/dist/subscribers/computed-entity-field.subscriber.js +6 -6
  114. package/dist/subscribers/computed-entity-field.subscriber.js.map +1 -1
  115. package/dist/winston.logger.js +1 -1
  116. package/dist/winston.logger.js.map +1 -1
  117. package/package.json +1 -2
  118. package/src/helpers/bootstrap.helper.ts +5 -2
  119. package/src/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.ts +1 -1
  120. package/src/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.ts +1 -2
  121. package/src/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.ts +1 -1
  122. package/src/helpers/module-metadata-helper.service.ts +3 -3
  123. package/src/helpers/string.helper.ts +3 -0
  124. package/src/interfaces/mq.ts +2 -2
  125. package/src/jobs/database/api-email-subscriber-database.service.ts +1 -1
  126. package/src/jobs/database/msg91-whatsapp-subscriber-database.service.ts +1 -1
  127. package/src/jobs/database/three60-whatsapp-subscriber-database.service.ts +1 -1
  128. package/src/jobs/rabbitmq/api-email-subscriber.service.ts +1 -1
  129. package/src/jobs/rabbitmq/msg91-whatsapp-subscriber.service.ts +1 -1
  130. package/src/jobs/rabbitmq/test-queue-subscriber.service.ts +6 -7
  131. package/src/jobs/rabbitmq/three60-whatsapp-subscriber.service.ts +1 -1
  132. package/src/jobs/redis/api-email-subscriber-redis.service.ts +1 -1
  133. package/src/jobs/redis/msg91-whatsapp-subscriber-redis.service.ts +1 -1
  134. package/src/jobs/redis/three60-whatsapp-subscriber-redis.service.ts +1 -1
  135. package/src/repository/chatter-message-details.repository.ts +4 -3
  136. package/src/repository/chatter-message.repository.ts +4 -4
  137. package/src/repository/solid-base.repository.ts +2 -2
  138. package/src/seeders/module-test-data.service.ts +1 -1
  139. package/src/seeders/seed-data/solid-core-metadata.json +7 -3
  140. package/src/services/chatter-message.service.ts +1 -3
  141. package/src/services/computed-fields/entity/sequence-num-computed-field-provider.ts +1 -2
  142. package/src/services/crud-helper.service.ts +1 -4
  143. package/src/services/export-transaction.service.ts +3 -4
  144. package/src/services/field-metadata.service.ts +1 -4
  145. package/src/services/fixtures.service.ts +1 -1
  146. package/src/services/genai/mcp-handlers/mcp-handler-factory.service.ts +1 -2
  147. package/src/services/import-transaction.service.ts +1 -1
  148. package/src/services/menu-item-metadata.service.ts +2 -2
  149. package/src/services/model-metadata.service.ts +10 -12
  150. package/src/services/module-metadata.service.ts +1 -2
  151. package/src/services/queues/database-subscriber.service.ts +1 -1
  152. package/src/services/queues/publisher-factory.service.ts +1 -2
  153. package/src/services/queues/rabbitmq-subscriber.service.ts +13 -11
  154. package/src/services/queues/redis-subscriber.service.ts +2 -2
  155. package/src/services/selection-providers/pseudo-foreign-key-selection-provider.service.ts +1 -1
  156. package/src/services/solid-introspect.service.ts +1 -1
  157. package/src/services/view-metadata.service.ts +1 -5
  158. package/src/subscribers/computed-entity-field.subscriber.ts +6 -6
  159. package/src/winston.logger.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAYA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAC/D;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CA+Gf;AAgBD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
1
+ {"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAC/D;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAiHf;AAgBD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
@@ -14,6 +14,7 @@ const fs_1 = require("fs");
14
14
  const path_1 = require("path");
15
15
  const nest_winston_1 = require("nest-winston");
16
16
  const nest_commander_1 = require("nest-commander");
17
+ const winston_logger_1 = require("../winston.logger");
17
18
  const wrap_response_interceptor_1 = require("../interceptors/wrap-response.interceptor");
18
19
  const cors_helper_1 = require("./cors.helper");
19
20
  const security_helper_1 = require("./security.helper");
@@ -36,7 +37,9 @@ async function bootstrapSolidApp(appModuleFactory, options = {}) {
36
37
  registerGlobalProcessHandlers();
37
38
  const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;
38
39
  const appModule = await appModuleFactory();
39
- const app = await core_1.NestFactory.create(appModule);
40
+ const app = await core_1.NestFactory.create(appModule, {
41
+ logger: nest_winston_1.WinstonModule.createLogger(winston_logger_1.WinstonLoggerConfig),
42
+ });
40
43
  const apiEnabled = (0, environment_helper_1.parseBooleanEnv)('API_ENABLED', true);
41
44
  if (!apiEnabled) {
42
45
  await app.init();
@@ -1 +1 @@
1
-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,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import { ValidationPipe } from '@nestjs/common';\nimport { NestFactory } from '@nestjs/core';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;\n\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule);\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Nest's Swagger UI HTML injects inline styles; keep CSP strict elsewhere.\n const isSwaggerPath = (path: string) =>\n path === '/docs' ||\n path === '/docs/' ||\n path.startsWith('/docs/') ||\n path === '/docs-json' ||\n path === '/docs-yaml';\n\n app.use((req: Request, res: Response, next: NextFunction) => {\n if (isSwaggerPath(req.path)) {\n res.removeHeader('Content-Security-Policy');\n }\n next();\n });\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n // Winston logger\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 20,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = process.env.SOLID_APP_NAME, description = process.env.SOLID_APP_DESCRIPTION, version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n await app.listen(port);\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
1
+ {"version":3,"file":"bootstrap.helper.js","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":";;;;;AAiEA,8CAoHC;AAgBD,8CA0CC;AA/OD,2CAAgD;AAChD,uCAA2C;AAC3C,6CAAiE;AAEjE,oDAA4B;AAC5B,4CAAoB;AACpB,2BAAgC;AAChC,+BAA+B;AAC/B,+CAA2E;AAC3E,mDAAgD;AAChD,sDAAwD;AACxD,yFAAoF;AACpF,+CAAwD;AACxD,uDAA6H;AAC7H,6DAAuD;AAIvD,SAAS,6BAA6B;IACpC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;QACtC,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAGH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;QAChC,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,OAAO,CA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AE;QAC/D,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;KACjF,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,+BAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import { ValidationPipe } from '@nestjs/common';\nimport { NestFactory } from '@nestjs/core';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER, WinstonModule } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { WinstonLoggerConfig } from '../winston.logger';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;\n\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule, {\n logger: WinstonModule.createLogger(WinstonLoggerConfig),\n });\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Nest's Swagger UI HTML injects inline styles; keep CSP strict elsewhere.\n const isSwaggerPath = (path: string) =>\n path === '/docs' ||\n path === '/docs/' ||\n path.startsWith('/docs/') ||\n path === '/docs-json' ||\n path === '/docs-yaml';\n\n app.use((req: Request, res: Response, next: NextFunction) => {\n if (isSwaggerPath(req.path)) {\n res.removeHeader('Content-Security-Policy');\n }\n next();\n });\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n // Winston logger\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 20,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = process.env.SOLID_APP_NAME, description = process.env.SOLID_APP_DESCRIPTION, version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n await app.listen(port);\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ManyToManyRelationFieldCrudManager = void 0;
4
- const strings_1 = require("@angular-devkit/core/src/utils/strings");
4
+ const string_helper_1 = require("../string.helper");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const class_validator_1 = require("class-validator");
7
7
  const create_field_metadata_dto_1 = require("../../dtos/create-field-metadata.dto");
@@ -47,9 +47,9 @@ class ManyToManyRelationFieldCrudManager {
47
47
  return errors;
48
48
  }
49
49
  async transformForCreate(dto) {
50
- const currentEntityName = (0, strings_1.classify)(this.options.modelSingularName);
50
+ const currentEntityName = (0, string_helper_1.classify)(this.options.modelSingularName);
51
51
  const currentEntityRepository = this.options.entityManager.getRepository(currentEntityName);
52
- const relatedEntityName = (0, strings_1.classify)(this.options.relationCoModelSingularName);
52
+ const relatedEntityName = (0, string_helper_1.classify)(this.options.relationCoModelSingularName);
53
53
  const relatedEntityRepository = this.options.entityManager.getRepository(relatedEntityName);
54
54
  const result = await this.transformByCommand(dto, relatedEntityRepository, currentEntityRepository);
55
55
  if (result !== undefined) {
@@ -108,7 +108,7 @@ class ManyToManyRelationFieldCrudManager {
108
108
  }
109
109
  await this.options.entityManager
110
110
  .createQueryBuilder()
111
- .relation((0, strings_1.classify)(this.options.modelSingularName), this.valueFieldName)
111
+ .relation((0, string_helper_1.classify)(this.options.modelSingularName), this.valueFieldName)
112
112
  .of(this.options.entityId)
113
113
  .add(ids);
114
114
  return undefined;
@@ -119,7 +119,7 @@ class ManyToManyRelationFieldCrudManager {
119
119
  }
120
120
  await this.options.entityManager
121
121
  .createQueryBuilder()
122
- .relation((0, strings_1.classify)(this.options.modelSingularName), this.valueFieldName)
122
+ .relation((0, string_helper_1.classify)(this.options.modelSingularName), this.valueFieldName)
123
123
  .of(this.options.entityId)
124
124
  .remove(ids);
125
125
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToManyRelationFieldCrudManager.js","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.ts"],"names":[],"mappings":";;;AAAA,oEAAkE;AAClE,2CAAwC;AACxC,qDAA8D;AAC9D,oFAA2E;AAE3E,qCAA4C;AAe5C,MAAM,YAAY,GAAG,CAAC,iDAAqB,CAAC,IAAI,EAAE,iDAAqB,CAAC,MAAM,EAAE,iDAAqB,CAAC,GAAG,CAAC,CAAC;AAG3G,MAAa,kCAAkC;IAO3C,YAA6B,OAAuC;QAAvC,YAAO,GAAP,OAAO,CAAgC;QANnD,WAAM,GAAG,IAAI,eAAM,CAAC,kCAAkC,CAAC,IAAI,CA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M,CAAC,CAAC;gBAClE,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;iBACI,CAAC;gBACF,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3D,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;QAED,OAAO,wBAAwB,CAAC;IACpC,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,MAAa,EAAE,uBAA4B;QAE/E,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAG5C,MAAM,uBAAuB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAA;IACf,CAAC;IAEO,yBAAyB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,CAAC;CASJ;AA3LD,gFA2LC","sourcesContent":["import { classify } from \"@angular-devkit/core/src/utils/strings\";\nimport { Logger } from \"@nestjs/common\";\nimport { isEmpty, isEnum, isNotEmpty } from \"class-validator\";\nimport { RelationFieldsCommand } from \"src/dtos/create-field-metadata.dto\";\nimport { FieldCrudManager, ValidationError } from \"src/interfaces\";\nimport { EntityManager, In } from \"typeorm\";\n\nexport interface ManyToManyRelationFieldOptions {\n // Add options for relation field\n required: boolean | undefined | null;\n relationCoModelSingularName: string | undefined | null;\n modelSingularName: string | undefined | null;\n isInverseSide: boolean;\n entityManager: EntityManager;\n fieldName: string;\n relationCoModelFieldName?: string;\n isUpdate?: boolean;\n entityId?: number;\n}\n\nconst linkCommands = [RelationFieldsCommand.link, RelationFieldsCommand.unlink, RelationFieldsCommand.set];\n\n// This implementation is meant to be used for many-to-one relation field\nexport class ManyToManyRelationFieldCrudManager implements FieldCrudManager {\n private readonly logger = new Logger(ManyToManyRelationFieldCrudManager.name);\n\n private valueFieldName: string;\n private idFieldName: string;\n private commandFieldName: string;\n\n constructor(private readonly options: ManyToManyRelationFieldOptions) {\n if (!this.options.isInverseSide) {\n this.valueFieldName = `${this.options.fieldName}`;\n this.idFieldName = `${this.options.fieldName}Ids`;\n this.commandFieldName = `${this.options.fieldName}Command`;\n }\n else {\n this.valueFieldName = `${this.options.relationCoModelFieldName}`;\n this.idFieldName = `${this.options.relationCoModelFieldName}Ids`;\n this.commandFieldName = `${this.options.relationCoModelFieldName}Command`;\n }\n }\n\n validate(dto: any) {\n return this.applyValidations(dto);\n }\n\n private applyValidations(dto: any): ValidationError[] { \n const errors: ValidationError[] = [];\n\n const commandFieldName = this.commandFieldName;\n const commandValue = dto[commandFieldName];\n this.isApplyRequiredValidation() && isEmpty(commandValue) ? errors.push({ field: commandFieldName, error: 'Command field is required' }) : \"no errors\";\n if (isNotEmpty(commandValue)) {\n !isEnum(commandValue, RelationFieldsCommand)? errors.push({ field: this.options.fieldName, error: 'Command Field has invalid value' }) : \"no errors\";\n } \n \n var fieldValue = null\n if (commandValue === RelationFieldsCommand.clear) {\n return errors;\n } else if (linkCommands.includes(commandValue)) {\n fieldValue = dto[this.idFieldName];\n } \n else {\n fieldValue = dto[this.valueFieldName];\n }\n\n this.isApplyRequiredValidation() && isEmpty(fieldValue) ? errors.push({ field: this.options.fieldName, error: `Field: ${this.options.fieldName} is required` }) : \"no errors\";\n return errors;\n }\n\n async transformForCreate(dto: any): Promise<any> {\n const currentEntityName = classify(this.options.modelSingularName);\n const currentEntityRepository = this.options.entityManager.getRepository(currentEntityName);\n\n const relatedEntityName = classify(this.options.relationCoModelSingularName);\n const relatedEntityRepository = this.options.entityManager.getRepository(relatedEntityName)\n\n const result = await this.transformByCommand(dto, relatedEntityRepository, currentEntityRepository);\n if (result !== undefined) {\n dto[this.valueFieldName] = result;\n } else {\n delete dto[this.valueFieldName];\n }\n return dto;\n }\n\n private async transformByCommand(dto: any, relatedEntityRepository: any, currentEntityRepository: any): Promise<any[] | undefined> {\n // TODO : Need to add support for the multiple commands\n const command = dto[this.commandFieldName];\n const values = dto[this.valueFieldName];\n const ids = dto[this.idFieldName];\n\n switch (command) {\n case RelationFieldsCommand.create:\n return await this.transformForCommandCreate(values, relatedEntityRepository);\n case RelationFieldsCommand.update:\n return await this.transformForCommandUpdate(values, relatedEntityRepository, dto, currentEntityRepository);\n case RelationFieldsCommand.delete:\n return await this.transformForCommandDelete(values, relatedEntityRepository);\n case RelationFieldsCommand.clear:\n return this.transformForCommandClear();\n case RelationFieldsCommand.set:\n return await this.transformForCommandSet(ids, relatedEntityRepository);\n case RelationFieldsCommand.link:\n return await this.tranformForCommandLink(ids, relatedEntityRepository);\n case RelationFieldsCommand.unlink:\n return await this.transformForCommandUnLink(ids);\n default:\n this.logger.log(`Invalid command ${command}`);\n return null;\n\n }\n }\n\n private transformForCommandClear() {\n return []\n }\n\n private async transformForCommandSet(ids: any[], relatedEntityRepository: any): Promise<any[]> {\n const loadedEntities: any[] = await relatedEntityRepository.find({\n where : {id: In(ids) }\n })\n if (loadedEntities.length !== ids.length) {\n throw new Error('Invalid entity ids provided for set');\n }\n\n return loadedEntities;\n }\n\n private async tranformForCommandLink(ids: any[], relatedEntityRepository: any): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Link command is only supported for update operations');\n }\n\n const count: number = await relatedEntityRepository.count({\n where: { id: In(ids) }\n });\n if (count !== ids.length) {\n throw new Error('Invalid entity ids provided for linking');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .add(ids);\n\n return undefined;\n }\n\n private async transformForCommandUnLink(ids: any[]): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Unlink command is only supported for update operations');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .remove(ids);\n\n return undefined;\n }\n\n private async transformForCommandCreate(values: any[], relatedEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n return transformedRelatedFields;\n }\n\n private async transformForCommandUpdate(values: any[], relatedEntityRepository: any, dto: any, currentEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n if (entity.id) {\n const transformed = await relatedEntityRepository.preload(entity);\n transformedRelatedFields.push(transformed);\n }\n else {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n }\n\n return transformedRelatedFields;\n }\n\n private async transformForCommandDelete(values: any[], relatedEntityRepository: any): Promise<any[]> {\n // Map and get the ids from the values\n const ids = values.map((value) => value.id);\n\n // Delete the ids linked to the associated entity\n await relatedEntityRepository.delete(ids);\n return null\n }\n\n private isApplyRequiredValidation(): boolean {\n return this.options.required;\n }\n\n // TODO: We have moved this to SolidRegistry service, refactor to use that service.\n // Returns the entity target class from the entity name\n // private getEntityTarget(entityName: string): any { //TODO Can be refactored to use this function from crud helper service\n // const entityMetadatas = this.options.entityManager.connection.entityMetadatas;\n // const entityMetadata = entityMetadatas.find(em => em.name === entityName);\n // return entityMetadata.target;\n // }\n}\n"]}
1
+ {"version":3,"file":"ManyToManyRelationFieldCrudManager.js","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.ts"],"names":[],"mappings":";;;AAAA,oDAA4C;AAC5C,2CAAwC;AACxC,qDAA8D;AAC9D,oFAA2E;AAE3E,qCAA4C;AAe5C,MAAM,YAAY,GAAG,CAAC,iDAAqB,CAAC,IAAI,EAAE,iDAAqB,CAAC,MAAM,EAAE,iDAAqB,CAAC,GAAG,CAAC,CAAC;AAG3G,MAAa,kCAAkC;IAO3C,YAA6B,OAAuC;QAAvC,YAAO,GAAP,OAAO,CAAgC;QANnD,WAAM,GAAG,IAAI,eAAM,CAAC,kCAAkC,CAAC,IAAI,CAAC,CAAC;QAO1E,IAAI,CAAC,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,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;iBACI,CAAC;gBACF,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3D,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;QAED,OAAO,wBAAwB,CAAC;IACpC,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,MAAa,EAAE,uBAA4B;QAE/E,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAG5C,MAAM,uBAAuB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAA;IACf,CAAC;IAEO,yBAAyB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,CAAC;CASJ;AA3LD,gFA2LC","sourcesContent":["import { classify } from '../string.helper';\nimport { Logger } from \"@nestjs/common\";\nimport { isEmpty, isEnum, isNotEmpty } from \"class-validator\";\nimport { RelationFieldsCommand } from \"src/dtos/create-field-metadata.dto\";\nimport { FieldCrudManager, ValidationError } from \"src/interfaces\";\nimport { EntityManager, In } from \"typeorm\";\n\nexport interface ManyToManyRelationFieldOptions {\n // Add options for relation field\n required: boolean | undefined | null;\n relationCoModelSingularName: string | undefined | null;\n modelSingularName: string | undefined | null;\n isInverseSide: boolean;\n entityManager: EntityManager;\n fieldName: string;\n relationCoModelFieldName?: string;\n isUpdate?: boolean;\n entityId?: number;\n}\n\nconst linkCommands = [RelationFieldsCommand.link, RelationFieldsCommand.unlink, RelationFieldsCommand.set];\n\n// This implementation is meant to be used for many-to-one relation field\nexport class ManyToManyRelationFieldCrudManager implements FieldCrudManager {\n private readonly logger = new Logger(ManyToManyRelationFieldCrudManager.name);\n\n private valueFieldName: string;\n private idFieldName: string;\n private commandFieldName: string;\n\n constructor(private readonly options: ManyToManyRelationFieldOptions) {\n if (!this.options.isInverseSide) {\n this.valueFieldName = `${this.options.fieldName}`;\n this.idFieldName = `${this.options.fieldName}Ids`;\n this.commandFieldName = `${this.options.fieldName}Command`;\n }\n else {\n this.valueFieldName = `${this.options.relationCoModelFieldName}`;\n this.idFieldName = `${this.options.relationCoModelFieldName}Ids`;\n this.commandFieldName = `${this.options.relationCoModelFieldName}Command`;\n }\n }\n\n validate(dto: any) {\n return this.applyValidations(dto);\n }\n\n private applyValidations(dto: any): ValidationError[] { \n const errors: ValidationError[] = [];\n\n const commandFieldName = this.commandFieldName;\n const commandValue = dto[commandFieldName];\n this.isApplyRequiredValidation() && isEmpty(commandValue) ? errors.push({ field: commandFieldName, error: 'Command field is required' }) : \"no errors\";\n if (isNotEmpty(commandValue)) {\n !isEnum(commandValue, RelationFieldsCommand)? errors.push({ field: this.options.fieldName, error: 'Command Field has invalid value' }) : \"no errors\";\n } \n \n var fieldValue = null\n if (commandValue === RelationFieldsCommand.clear) {\n return errors;\n } else if (linkCommands.includes(commandValue)) {\n fieldValue = dto[this.idFieldName];\n } \n else {\n fieldValue = dto[this.valueFieldName];\n }\n\n this.isApplyRequiredValidation() && isEmpty(fieldValue) ? errors.push({ field: this.options.fieldName, error: `Field: ${this.options.fieldName} is required` }) : \"no errors\";\n return errors;\n }\n\n async transformForCreate(dto: any): Promise<any> {\n const currentEntityName = classify(this.options.modelSingularName);\n const currentEntityRepository = this.options.entityManager.getRepository(currentEntityName);\n\n const relatedEntityName = classify(this.options.relationCoModelSingularName);\n const relatedEntityRepository = this.options.entityManager.getRepository(relatedEntityName)\n\n const result = await this.transformByCommand(dto, relatedEntityRepository, currentEntityRepository);\n if (result !== undefined) {\n dto[this.valueFieldName] = result;\n } else {\n delete dto[this.valueFieldName];\n }\n return dto;\n }\n\n private async transformByCommand(dto: any, relatedEntityRepository: any, currentEntityRepository: any): Promise<any[] | undefined> {\n // TODO : Need to add support for the multiple commands\n const command = dto[this.commandFieldName];\n const values = dto[this.valueFieldName];\n const ids = dto[this.idFieldName];\n\n switch (command) {\n case RelationFieldsCommand.create:\n return await this.transformForCommandCreate(values, relatedEntityRepository);\n case RelationFieldsCommand.update:\n return await this.transformForCommandUpdate(values, relatedEntityRepository, dto, currentEntityRepository);\n case RelationFieldsCommand.delete:\n return await this.transformForCommandDelete(values, relatedEntityRepository);\n case RelationFieldsCommand.clear:\n return this.transformForCommandClear();\n case RelationFieldsCommand.set:\n return await this.transformForCommandSet(ids, relatedEntityRepository);\n case RelationFieldsCommand.link:\n return await this.tranformForCommandLink(ids, relatedEntityRepository);\n case RelationFieldsCommand.unlink:\n return await this.transformForCommandUnLink(ids);\n default:\n this.logger.log(`Invalid command ${command}`);\n return null;\n\n }\n }\n\n private transformForCommandClear() {\n return []\n }\n\n private async transformForCommandSet(ids: any[], relatedEntityRepository: any): Promise<any[]> {\n const loadedEntities: any[] = await relatedEntityRepository.find({\n where : {id: In(ids) }\n })\n if (loadedEntities.length !== ids.length) {\n throw new Error('Invalid entity ids provided for set');\n }\n\n return loadedEntities;\n }\n\n private async tranformForCommandLink(ids: any[], relatedEntityRepository: any): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Link command is only supported for update operations');\n }\n\n const count: number = await relatedEntityRepository.count({\n where: { id: In(ids) }\n });\n if (count !== ids.length) {\n throw new Error('Invalid entity ids provided for linking');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .add(ids);\n\n return undefined;\n }\n\n private async transformForCommandUnLink(ids: any[]): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Unlink command is only supported for update operations');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .remove(ids);\n\n return undefined;\n }\n\n private async transformForCommandCreate(values: any[], relatedEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n return transformedRelatedFields;\n }\n\n private async transformForCommandUpdate(values: any[], relatedEntityRepository: any, dto: any, currentEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n if (entity.id) {\n const transformed = await relatedEntityRepository.preload(entity);\n transformedRelatedFields.push(transformed);\n }\n else {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n }\n\n return transformedRelatedFields;\n }\n\n private async transformForCommandDelete(values: any[], relatedEntityRepository: any): Promise<any[]> {\n // Map and get the ids from the values\n const ids = values.map((value) => value.id);\n\n // Delete the ids linked to the associated entity\n await relatedEntityRepository.delete(ids);\n return null\n }\n\n private isApplyRequiredValidation(): boolean {\n return this.options.required;\n }\n\n // TODO: We have moved this to SolidRegistry service, refactor to use that service.\n // Returns the entity target class from the entity name\n // private getEntityTarget(entityName: string): any { //TODO Can be refactored to use this function from crud helper service\n // const entityMetadatas = this.options.entityManager.connection.entityMetadatas;\n // const entityMetadata = entityMetadatas.find(em => em.name === entityName);\n // return entityMetadata.target;\n // }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToOneRelationFieldCrudManager.d.ts","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,6BAA6B;IAE1C,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;IACrC,2BAA2B,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACvD,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAErC,iBAAiB,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAC7C,aAAa,EAAE,aAA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CAAC,GAAG,EAAE,GAAG;IAMjB,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,6BAA6B;IAS/B,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAgChD,OAAO,CAAC,yBAAyB;CAWpC"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ManyToOneRelationFieldCrudManager = void 0;
4
- const strings_1 = require("@angular-devkit/core/src/utils/strings");
4
+ const string_helper_1 = require("../string.helper");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const class_validator_1 = require("class-validator");
7
7
  const is_parsable_int_1 = require("../../validators/is-parsable-int");
@@ -48,7 +48,7 @@ class ManyToOneRelationFieldCrudManager {
48
48
  if (!this.options.relationCoModelSingularName) {
49
49
  throw new common_1.BadRequestException(`ManyToOneRelationFieldCrudManager: relationCoModelSingularName is not defined in the field: ${this.options.fieldName}`);
50
50
  }
51
- const coModelEntityName = (0, strings_1.classify)(this.options.relationCoModelSingularName);
51
+ const coModelEntityName = (0, string_helper_1.classify)(this.options.relationCoModelSingularName);
52
52
  if ((0, class_validator_1.isNotEmpty)(fieldId)) {
53
53
  dto[this.options.fieldName] = await this.options.entityManager.getRepository(coModelEntityName).findOneBy({ id: fieldId });
54
54
  if (this.options.required && (0, class_validator_1.isEmpty)(dto[this.options.fieldName])) {
@@ -1 +1 @@
1
- {"version":3,"file":"ManyToOneRelationFieldCrudManager.js","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.ts"],"names":[],"mappings":";;;AAAA,oEAAkE;AAClE,2CAAqD;AACrD,qDAAgE;AAEhE,sEAA+D;AAe/D,MAAa,iCAAiC;IAG1C,YAA6B,OAAsC;QAAtC,YAAO,GAAP,OAAO,CAA+B;QAE/D,IAAI,CAAC,WAAW,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,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B;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,CAAC;CASJ;AArFD,8EAqFC","sourcesContent":["import { classify } from \"@angular-devkit/core/src/utils/strings\";\nimport { BadRequestException } from \"@nestjs/common\";\nimport { isEmpty, isNotEmpty, isString } from \"class-validator\";\nimport { FieldCrudManager, ValidationError } from \"src/interfaces\";\nimport { IsParsableInt } from \"src/validators/is-parsable-int\";\nimport { EntityManager } from \"typeorm\";\n\nexport interface ManyToOneRelationFieldOptions {\n // Add options for relation field\n required: boolean | undefined | null;\n relationCoModelSingularName: string | undefined | null;\n fieldName: string | undefined | null;\n // modelUserKeyFieldName: string | undefined | null;\n modelSingularName: string | undefined | null;\n entityManager: EntityManager;\n relationCoModelUserKeyFieldName: string | undefined | null; \n}\n\n// This implementation is meant to be used for many-to-one relation field\nexport class ManyToOneRelationFieldCrudManager implements FieldCrudManager {\n private idFieldName: string;\n private userKeyFieldName: string;\n constructor(private readonly options: ManyToOneRelationFieldOptions) {\n // this.options = options;\n this.idFieldName = `${options.fieldName}Id`;\n this.userKeyFieldName = `${options.fieldName}UserKey`;\n }\n validate(dto: any) {\n const fieldId: number = dto[this.idFieldName];\n const fieldUserKey: string = dto[this.userKeyFieldName];\n return this.applyValidations(fieldId, fieldUserKey);\n }\n\n private applyValidations(fieldId: any, fieldUserKey: string): ValidationError[] {\n const errors: ValidationError[] = [];\n this.isApplyRequiredValidation() && isEmpty(fieldId) && isEmpty(fieldUserKey) ? errors.push({ field: this.options.fieldName, error: `Field: ${this.options.fieldName} is required. Either pass ${this.idFieldName} or ${this.userKeyFieldName}.` }) : \"no errors\";\n if (isNotEmpty(fieldId)) {\n errors.push(...this.applyIdFormatValidations(fieldId));\n }\n if (isNotEmpty(fieldUserKey)) {\n errors.push(...this.applyUserKeyFormatValidations(fieldUserKey));\n }\n return errors;\n }\n\n private applyIdFormatValidations(fieldId: any): ValidationError[] { //FIXME fieldId is any because it can be string or number. Keeping it any for compatibility with isParsableInt. \n const errors: ValidationError[] = [];\n !IsParsableInt(fieldId) ? errors.push({ field: this.options.fieldName, error: 'Field is not a integer' }) : \"no errors\";\n return errors;\n }\n\n private applyUserKeyFormatValidations(fieldUserKey: string): ValidationError[] {\n const errors: ValidationError[] = [];\n !isString(fieldUserKey) ? errors.push({ field: this.options.fieldName, error: 'Field is not a string' }) : \"no errors\";\n if (isEmpty(this.options.relationCoModelUserKeyFieldName)) {\n errors.push({ field: this.options.fieldName, error: `UserKey field name is not defined in the model ${this.options.relationCoModelSingularName}` });\n }\n return errors;\n }\n\n async transformForCreate(dto: any): Promise<any> {\n const fieldId: number = dto[this.idFieldName];\n const fieldUserKeyValue: string = dto[this.userKeyFieldName];\n\n // Avoid transforming if both fieldId and fieldUserKey is empty\n if ((isEmpty(fieldId)) && isEmpty(fieldUserKeyValue)) return dto;\n\n if (!this.options.relationCoModelSingularName) {\n throw new BadRequestException(`ManyToOneRelationFieldCrudManager: relationCoModelSingularName is not defined in the field: ${this.options.fieldName}`);\n }\n // // Load the related entity from the database, using the repository of the related entity\n //const entityTarget = this.getRelatedEntityTarget(classify(this.options.relationCoModelSingularName));\n const coModelEntityName = classify(this.options.relationCoModelSingularName);\n\n //Load the related entity from the database, using the repository of the related entity\n //const entityTarget = this.getRelatedEntityTarget(classify(this.options.relationCoModelSingularName));\n if (isNotEmpty(fieldId)) {\n dto[this.options.fieldName] = await this.options.entityManager.getRepository(coModelEntityName).findOneBy({ id: fieldId });\n if (this.options.required && isEmpty(dto[this.options.fieldName])) {\n throw new Error(`Field ${this.options.fieldName} resolution failed. Record with id: ${fieldId} not found in ${this.options.relationCoModelSingularName}`);\n }\n }\n else {\n dto[this.options.fieldName] = await this.options.entityManager.getRepository(coModelEntityName).findOneBy({ [this.options.relationCoModelUserKeyFieldName]: fieldUserKeyValue });\n if (this.options.required && isEmpty(dto[this.options.fieldName])) {\n throw new Error(`Field ${this.options.fieldName} resolution failed. Record with userKey: ${this.options.relationCoModelUserKeyFieldName}: ${fieldUserKeyValue} not found in ${this.options.relationCoModelSingularName}`);\n }\n }\n\n\n return dto;\n }\n\n private isApplyRequiredValidation(): boolean {\n return this.options.required;\n }\n\n // Returns the entity target class from the entity name\n // private getRelatedEntityTarget(relatedEntityName: string): any {\n // const entityMetadatas = this.options.entityManager.connection.entityMetadatas;\n // const relatedEntityMetadata = entityMetadatas.find(em => em.name === relatedEntityName);\n // return relatedEntityMetadata.target;\n // }\n\n}"]}
1
+ {"version":3,"file":"ManyToOneRelationFieldCrudManager.js","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/ManyToOneRelationFieldCrudManager.ts"],"names":[],"mappings":";;;AAAA,oDAA4C;AAC5C,2CAAqD;AACrD,qDAAgE;AAEhE,sEAA+D;AAe/D,MAAa,iCAAiC;IAG1C,YAA6B,OAAsC;QAAtC,YAAO,GAAP,OAAO,CAA+B;QAE/D,IAAI,CAAC,WAAW,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC;QAC5C,IAAI,CAAC,gBAAgB,GAAG,GAAG,OAAO,CAAC,SAAS,SAAS,CAAC;IAC1D,CAAC;IACD,QAAQ,CAAC,GAAQ;QACb,MAAM,OAAO,GAAW,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9C,MAAM,YAAY,GAAW,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACxD,CAAC;IAEO,gBAAgB,CAAC,OAAY,EAAE,YAAoB;QACvD,MAAM,MAAM,GAAsB,EAAE,CAAC;QACrC,IAAI,CAAC,yBAAyB,EAAE,IAAI,IAAA,yBAAO,EAAC,OAAO,CAAC,IAAI,IAAA,yBAAO,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,IAAI,CAAC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CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,+BAA+B,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC;YACjL,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAA,yBAAO,EAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;gBAChE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,SAAS,4CAA4C,IAAI,CAAC,OAAO,CAAC,+BAA+B,KAAK,iBAAiB,iBAAiB,IAAI,CAAC,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC;YAC9N,CAAC;QACL,CAAC;QAED,OAAO,GAAG,CAAC;IACf,CAAC;IAEO,yBAAyB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,CAAC;CASJ;AApFD,8EAoFC","sourcesContent":["import { classify } from '../string.helper';\nimport { BadRequestException } from \"@nestjs/common\";\nimport { isEmpty, isNotEmpty, isString } from \"class-validator\";\nimport { FieldCrudManager, ValidationError } from \"src/interfaces\";\nimport { IsParsableInt } from \"src/validators/is-parsable-int\";\nimport { EntityManager } from \"typeorm\";\n\nexport interface ManyToOneRelationFieldOptions {\n // Add options for relation field\n required: boolean | undefined | null;\n relationCoModelSingularName: string | undefined | null;\n fieldName: string | undefined | null;\n // modelUserKeyFieldName: string | undefined | null;\n modelSingularName: string | undefined | null;\n entityManager: EntityManager;\n relationCoModelUserKeyFieldName: string | undefined | null; \n}\n\n// This implementation is meant to be used for many-to-one relation field\nexport class ManyToOneRelationFieldCrudManager implements FieldCrudManager {\n private idFieldName: string;\n private userKeyFieldName: string;\n constructor(private readonly options: ManyToOneRelationFieldOptions) {\n // this.options = options;\n this.idFieldName = `${options.fieldName}Id`;\n this.userKeyFieldName = `${options.fieldName}UserKey`;\n }\n validate(dto: any) {\n const fieldId: number = dto[this.idFieldName];\n const fieldUserKey: string = dto[this.userKeyFieldName];\n return this.applyValidations(fieldId, fieldUserKey);\n }\n\n private applyValidations(fieldId: any, fieldUserKey: string): ValidationError[] {\n const errors: ValidationError[] = [];\n this.isApplyRequiredValidation() && isEmpty(fieldId) && isEmpty(fieldUserKey) ? errors.push({ field: this.options.fieldName, error: `Field: ${this.options.fieldName} is required. Either pass ${this.idFieldName} or ${this.userKeyFieldName}.` }) : \"no errors\";\n if (isNotEmpty(fieldId)) {\n errors.push(...this.applyIdFormatValidations(fieldId));\n }\n if (isNotEmpty(fieldUserKey)) {\n errors.push(...this.applyUserKeyFormatValidations(fieldUserKey));\n }\n return errors;\n }\n\n private applyIdFormatValidations(fieldId: any): ValidationError[] { //FIXME fieldId is any because it can be string or number. Keeping it any for compatibility with isParsableInt. \n const errors: ValidationError[] = [];\n !IsParsableInt(fieldId) ? errors.push({ field: this.options.fieldName, error: 'Field is not a integer' }) : \"no errors\";\n return errors;\n }\n\n private applyUserKeyFormatValidations(fieldUserKey: string): ValidationError[] {\n const errors: ValidationError[] = [];\n !isString(fieldUserKey) ? errors.push({ field: this.options.fieldName, error: 'Field is not a string' }) : \"no errors\";\n if (isEmpty(this.options.relationCoModelUserKeyFieldName)) {\n errors.push({ field: this.options.fieldName, error: `UserKey field name is not defined in the model ${this.options.relationCoModelSingularName}` });\n }\n return errors;\n }\n\n async transformForCreate(dto: any): Promise<any> {\n const fieldId: number = dto[this.idFieldName];\n const fieldUserKeyValue: string = dto[this.userKeyFieldName];\n\n // Avoid transforming if both fieldId and fieldUserKey is empty\n if ((isEmpty(fieldId)) && isEmpty(fieldUserKeyValue)) return dto;\n\n if (!this.options.relationCoModelSingularName) {\n throw new BadRequestException(`ManyToOneRelationFieldCrudManager: relationCoModelSingularName is not defined in the field: ${this.options.fieldName}`);\n }\n // // Load the related entity from the database, using the repository of the related entity\n //const entityTarget = this.getRelatedEntityTarget(classify(this.options.relationCoModelSingularName));\n const coModelEntityName = classify(this.options.relationCoModelSingularName);\n\n //Load the related entity from the database, using the repository of the related entity\n //const entityTarget = this.getRelatedEntityTarget(classify(this.options.relationCoModelSingularName));\n if (isNotEmpty(fieldId)) {\n dto[this.options.fieldName] = await this.options.entityManager.getRepository(coModelEntityName).findOneBy({ id: fieldId });\n if (this.options.required && isEmpty(dto[this.options.fieldName])) {\n throw new Error(`Field ${this.options.fieldName} resolution failed. Record with id: ${fieldId} not found in ${this.options.relationCoModelSingularName}`);\n }\n }\n else {\n dto[this.options.fieldName] = await this.options.entityManager.getRepository(coModelEntityName).findOneBy({ [this.options.relationCoModelUserKeyFieldName]: fieldUserKeyValue });\n if (this.options.required && isEmpty(dto[this.options.fieldName])) {\n throw new Error(`Field ${this.options.fieldName} resolution failed. Record with userKey: ${this.options.relationCoModelUserKeyFieldName}: ${fieldUserKeyValue} not found in ${this.options.relationCoModelSingularName}`);\n }\n }\n\n return dto;\n }\n\n private isApplyRequiredValidation(): boolean {\n return this.options.required;\n }\n\n // Returns the entity target class from the entity name\n // private getRelatedEntityTarget(relatedEntityName: string): any {\n // const entityMetadatas = this.options.entityManager.connection.entityMetadatas;\n // const relatedEntityMetadata = entityMetadatas.find(em => em.name === relatedEntityName);\n // return relatedEntityMetadata.target;\n // }\n\n}"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OneToManyRelationFieldCrudManager = void 0;
4
- const strings_1 = require("@angular-devkit/core/src/utils/strings");
4
+ const string_helper_1 = require("../string.helper");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const class_validator_1 = require("class-validator");
7
7
  const create_field_metadata_dto_1 = require("../../dtos/create-field-metadata.dto");
@@ -54,9 +54,9 @@ class OneToManyRelationFieldCrudManager {
54
54
  return errors;
55
55
  }
56
56
  async transformForCreate(dto) {
57
- const currentEntityName = (0, strings_1.classify)(this.options.modelSingularName);
57
+ const currentEntityName = (0, string_helper_1.classify)(this.options.modelSingularName);
58
58
  const currentEntityRepository = this.options.entityManager.getRepository(currentEntityName);
59
- const relatedEntityName = (0, strings_1.classify)(this.options.relationCoModelSingularName);
59
+ const relatedEntityName = (0, string_helper_1.classify)(this.options.relationCoModelSingularName);
60
60
  const relatedEntityRepository = this.options.entityManager.getRepository(relatedEntityName);
61
61
  const result = await this.transformByCommand(dto, relatedEntityRepository, currentEntityRepository);
62
62
  if (result !== undefined) {
@@ -115,7 +115,7 @@ class OneToManyRelationFieldCrudManager {
115
115
  }
116
116
  await this.options.entityManager
117
117
  .createQueryBuilder()
118
- .relation((0, strings_1.classify)(this.options.modelSingularName), this.valueFieldName)
118
+ .relation((0, string_helper_1.classify)(this.options.modelSingularName), this.valueFieldName)
119
119
  .of(this.options.entityId)
120
120
  .add(ids);
121
121
  return undefined;
@@ -126,7 +126,7 @@ class OneToManyRelationFieldCrudManager {
126
126
  }
127
127
  await this.options.entityManager
128
128
  .createQueryBuilder()
129
- .relation((0, strings_1.classify)(this.options.modelSingularName), this.valueFieldName)
129
+ .relation((0, string_helper_1.classify)(this.options.modelSingularName), this.valueFieldName)
130
130
  .of(this.options.entityId)
131
131
  .remove(ids);
132
132
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"OneToManyRelationFieldCrudManager.js","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.ts"],"names":[],"mappings":";;;AAAA,oEAAkE;AAClE,2CAAwC;AACxC,qDAAqE;AACrE,oFAA2E;AAE3E,qCAA4C;AAc5C,MAAM,YAAY,GAAG,CAAC,iDAAqB,CAAC,IAAI,EAAE,iDAAqB,CAAC,MAAM,EAAE,iDAAqB,CAAC,GAAG,CAAC,CAAC;AAG3G,MAAa,iCAAiC;IAO1C,YAA6B,OAAsC;QAAtC,YAAO,GAAP,OAAO,CAA+B;QANlD,WAAM,GAAG,IAAI,eAAM,CAAC,iCAAiC,CAAC,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AE,CAAC;YAC1B,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC3D,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC;QACA,OAAO,wBAAwB,CAAC;IACpC,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,MAAa,EAAE,uBAA4B,EAAE,GAAQ,EAAE,uBAA4B;QACvH,MAAM,wBAAwB,GAAG,EAAE,CAAC;QACpC,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;YAC1B,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,WAAW,GAAG,MAAM,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClE,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;iBACI,CAAC;gBACF,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3D,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;QAED,OAAO,wBAAwB,CAAC;IACpC,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,MAAa,EAAE,uBAA4B;QAE/E,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAG5C,MAAM,uBAAuB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAA;IACf,CAAC;IAEO,yBAAyB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,CAAC;CASJ;AAlMD,8EAkMC","sourcesContent":["import { classify } from \"@angular-devkit/core/src/utils/strings\";\nimport { Logger } from \"@nestjs/common\";\nimport { isEmpty, isEnum, isInt, isNotEmpty } from \"class-validator\";\nimport { RelationFieldsCommand } from \"src/dtos/create-field-metadata.dto\";\nimport { FieldCrudManager, ValidationError } from \"src/interfaces\";\nimport { EntityManager, In } from \"typeorm\";\n\nexport interface OneToManyRelationFieldOptions {\n // Add options for relation field\n required: boolean | undefined | null;\n relationCoModelSingularName: string | undefined | null;\n inverseRelationCoModelFieldName: string | undefined | null;\n modelSingularName: string | undefined | null;\n inverseFieldName: string | undefined | null;\n entityManager: EntityManager | undefined | null;\n isUpdate?: boolean;\n entityId?: number;\n}\n\nconst linkCommands = [RelationFieldsCommand.link, RelationFieldsCommand.unlink, RelationFieldsCommand.set];\n\n// This implementation is meant to be used for many-to-one relation field\nexport class OneToManyRelationFieldCrudManager implements FieldCrudManager {\n private readonly logger = new Logger(OneToManyRelationFieldCrudManager.name);\n\n private readonly valueFieldName: string;\n private readonly idFieldName: string;\n private readonly commandFieldName: string;\n\n constructor(private readonly options: OneToManyRelationFieldOptions) {\n this.valueFieldName = this.options.inverseRelationCoModelFieldName ?? `${this.options.relationCoModelSingularName}s`;\n this.idFieldName = `${this.options.inverseRelationCoModelFieldName ?? this.options.relationCoModelSingularName}Ids`;\n this.commandFieldName = `${this.options.inverseRelationCoModelFieldName ?? this.options.relationCoModelSingularName}Command`;\n }\n\n validate(dto: any) {\n return this.applyValidations(dto);\n }\n\n private applyValidations(dto: any): ValidationError[] { \n const errors: ValidationError[] = [];\n\n const commandFieldName = this.commandFieldName;\n const commandValue = dto[commandFieldName];\n this.isApplyRequiredValidation() && isEmpty(commandValue) ? errors.push({ field: commandFieldName, error: 'Command field is required' }) : \"no errors\";\n if (isNotEmpty(commandValue)) {\n !isEnum(commandValue, RelationFieldsCommand)? errors.push({ field: this.options.inverseFieldName, error: 'Command Field has invalid value' }) : \"no errors\";\n } \n \n var fieldValue = null\n if (commandValue === RelationFieldsCommand.clear) {\n return errors;\n } else if (linkCommands.includes(commandValue)) {\n fieldValue = dto[this.idFieldName];\n } \n else {\n fieldValue = dto[this.valueFieldName];\n }\n\n this.isApplyRequiredValidation() && isEmpty(fieldValue) ? errors.push({ field: this.options.inverseFieldName, error: `Field: ${this.options.inverseFieldName} is required` }) : \"no errors\";\n if (isNotEmpty(fieldValue)) {\n errors.push(...this.applyFormatValidations(fieldValue, commandValue, commandFieldName));\n }\n return errors;\n }\n\n private applyFormatValidations(fieldValue: any[], commandValue: RelationFieldsCommand, commandFieldName: string): ValidationError[] {\n const errors: ValidationError[] = [];\n if (linkCommands.includes(commandValue)) {\n for (const id of fieldValue) {\n if (!isInt(id)) {\n errors.push({ field: this.options.inverseFieldName, error: `Invalid ids in ${commandFieldName}` });\n }\n }\n }\n return errors;\n }\n\n async transformForCreate(dto: any): Promise<any> {\n const currentEntityName = classify(this.options.modelSingularName);\n const currentEntityRepository = this.options.entityManager.getRepository(currentEntityName);\n\n const relatedEntityName = classify(this.options.relationCoModelSingularName);\n const relatedEntityRepository = this.options.entityManager.getRepository(relatedEntityName);\n\n const result = await this.transformByCommand(dto, relatedEntityRepository, currentEntityRepository);\n if (result !== undefined) {\n dto[this.valueFieldName] = result;\n } else {\n delete dto[this.valueFieldName];\n }\n return dto;\n }\n\n private async transformByCommand(dto: any, relatedEntityRepository: any, currentEntityRepository: any): Promise<any[] | undefined> {\n // TODO : Need to add support for the multiple commands\n const command = dto[this.commandFieldName];\n const values = dto[this.valueFieldName];\n const ids = dto[this.idFieldName];\n \n switch (command) {\n case RelationFieldsCommand.create:\n return await this.transformForCommandCreate(values, relatedEntityRepository);\n case RelationFieldsCommand.update:\n return await this.transformForCommandUpdate(values, relatedEntityRepository, dto, currentEntityRepository);\n case RelationFieldsCommand.delete:\n return await this.transformForCommandDelete(values, relatedEntityRepository);\n case RelationFieldsCommand.clear:\n return this.transformForCommandClear();\n case RelationFieldsCommand.set:\n return await this.transformForCommandSet(ids, relatedEntityRepository);\n case RelationFieldsCommand.link:\n return await this.tranformForCommandLink(ids, relatedEntityRepository);\n case RelationFieldsCommand.unlink:\n return await this.transformForCommandUnLink(ids);\n default:\n this.logger.log(`Invalid command ${command}`);\n return null;\n }\n }\n\n private transformForCommandClear() {\n return []\n }\n\n private async transformForCommandSet(ids: any[], relatedEntityRepository: any): Promise<any[]> {\n const loadedEntities: any[] = await relatedEntityRepository.find({\n where : {id: In(ids) }\n })\n if (loadedEntities.length !== ids.length) {\n throw new Error('Invalid entity ids provided for set');\n }\n\n return loadedEntities;\n }\n\n private async tranformForCommandLink(ids: any[], relatedEntityRepository: any): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Link command is only supported for update operations');\n }\n\n const count: number = await relatedEntityRepository.count({\n where: { id: In(ids) }\n });\n if (count !== ids.length) {\n throw new Error('Invalid entity ids provided for linking');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .add(ids);\n\n return undefined;\n }\n\n private async transformForCommandUnLink(ids: any[]): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Unlink command is only supported for update operations');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .remove(ids);\n\n return undefined;\n }\n\n private async transformForCommandCreate(values: any[], relatedEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n return transformedRelatedFields;\n }\n\n private async transformForCommandUpdate(values: any[], relatedEntityRepository: any, dto: any, currentEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n if (entity.id) {\n const transformed = await relatedEntityRepository.preload(entity);\n transformedRelatedFields.push(transformed);\n }\n else {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n }\n\n return transformedRelatedFields;\n }\n\n private async transformForCommandDelete(values: any[], relatedEntityRepository: any): Promise<any[]> {\n // Map and get the ids from the values\n const ids = values.map((value) => value.id);\n\n // Delete the ids linked to the associated entity\n await relatedEntityRepository.delete(ids);\n return null\n }\n\n private isApplyRequiredValidation(): boolean {\n return this.options.required;\n }\n\n // TODO: We have moved this to SolidRegistry service, refactor to use that service.\n // Returns the entity target class from the entity name\n // private getEntityTarget(entityName: string): any { //TODO Can be refactored to use this function from crud helper service\n // const entityMetadatas = this.options.entityManager.connection.entityMetadatas;\n // const entityMetadata = entityMetadatas.find(em => em.name === entityName);\n // return entityMetadata.target;\n // }\n}"]}
1
+ {"version":3,"file":"OneToManyRelationFieldCrudManager.js","sourceRoot":"","sources":["../../../src/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.ts"],"names":[],"mappings":";;;AAAA,oDAA4C;AAC5C,2CAAwC;AACxC,qDAAqE;AACrE,oFAA2E;AAE3E,qCAA4C;AAc5C,MAAM,YAAY,GAAG,CAAC,iDAAqB,CAAC,IAAI,EAAE,iDAAqB,CAAC,MAAM,EAAE,iDAAqB,CAAC,GAAG,CAAC,CAAC;AAG3G,MAAa,iCAAiC;IAO1C,YAA6B,OAAsC;QAAtC,YAAO,GAAP,OAAO,CAA+B;QANlD,WAAM,GAAG,IAAI,eAAM,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC;QAOzE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,+BAA+B,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,GAAG,CAAC;QACrH,IAAI,CAAC,WAAW,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,+BAA+B,IAAI,IAAI,CAAC,OAAO,CAAC,2BAA2B,KAAK,CAAC;QACpH,IAAI,CAAC,gBAAgB,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,+BAA+B,IAAI,IAAI,CAAC,OAAO,CAAC,2BAA2B,SAAS,CAAC;IACjI,CAAC;IAED,QAAQ,CAAC,GAAQ;QACb,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IAEO,gBAAgB,CAAC,GAAQ;QAC7B,MAAM,MAAM,GAAsB,EAAE,CAAC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,MAAM,WAAW,GAAG,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3D,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;QAED,OAAO,wBAAwB,CAAC;IACpC,CAAC;IAEO,KAAK,CAAC,yBAAyB,CAAC,MAAa,EAAE,uBAA4B;QAE/E,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAG5C,MAAM,uBAAuB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAA;IACf,CAAC;IAEO,yBAAyB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACjC,CAAC;CASJ;AAlMD,8EAkMC","sourcesContent":["import { classify } from '../string.helper';\nimport { Logger } from \"@nestjs/common\";\nimport { isEmpty, isEnum, isInt, isNotEmpty } from \"class-validator\";\nimport { RelationFieldsCommand } from \"src/dtos/create-field-metadata.dto\";\nimport { FieldCrudManager, ValidationError } from \"src/interfaces\";\nimport { EntityManager, In } from \"typeorm\";\n\nexport interface OneToManyRelationFieldOptions {\n // Add options for relation field\n required: boolean | undefined | null;\n relationCoModelSingularName: string | undefined | null;\n inverseRelationCoModelFieldName: string | undefined | null;\n modelSingularName: string | undefined | null;\n inverseFieldName: string | undefined | null;\n entityManager: EntityManager | undefined | null;\n isUpdate?: boolean;\n entityId?: number;\n}\n\nconst linkCommands = [RelationFieldsCommand.link, RelationFieldsCommand.unlink, RelationFieldsCommand.set];\n\n// This implementation is meant to be used for many-to-one relation field\nexport class OneToManyRelationFieldCrudManager implements FieldCrudManager {\n private readonly logger = new Logger(OneToManyRelationFieldCrudManager.name);\n\n private readonly valueFieldName: string;\n private readonly idFieldName: string;\n private readonly commandFieldName: string;\n\n constructor(private readonly options: OneToManyRelationFieldOptions) {\n this.valueFieldName = this.options.inverseRelationCoModelFieldName ?? `${this.options.relationCoModelSingularName}s`;\n this.idFieldName = `${this.options.inverseRelationCoModelFieldName ?? this.options.relationCoModelSingularName}Ids`;\n this.commandFieldName = `${this.options.inverseRelationCoModelFieldName ?? this.options.relationCoModelSingularName}Command`;\n }\n\n validate(dto: any) {\n return this.applyValidations(dto);\n }\n\n private applyValidations(dto: any): ValidationError[] { \n const errors: ValidationError[] = [];\n\n const commandFieldName = this.commandFieldName;\n const commandValue = dto[commandFieldName];\n this.isApplyRequiredValidation() && isEmpty(commandValue) ? errors.push({ field: commandFieldName, error: 'Command field is required' }) : \"no errors\";\n if (isNotEmpty(commandValue)) {\n !isEnum(commandValue, RelationFieldsCommand)? errors.push({ field: this.options.inverseFieldName, error: 'Command Field has invalid value' }) : \"no errors\";\n } \n \n var fieldValue = null\n if (commandValue === RelationFieldsCommand.clear) {\n return errors;\n } else if (linkCommands.includes(commandValue)) {\n fieldValue = dto[this.idFieldName];\n } \n else {\n fieldValue = dto[this.valueFieldName];\n }\n\n this.isApplyRequiredValidation() && isEmpty(fieldValue) ? errors.push({ field: this.options.inverseFieldName, error: `Field: ${this.options.inverseFieldName} is required` }) : \"no errors\";\n if (isNotEmpty(fieldValue)) {\n errors.push(...this.applyFormatValidations(fieldValue, commandValue, commandFieldName));\n }\n return errors;\n }\n\n private applyFormatValidations(fieldValue: any[], commandValue: RelationFieldsCommand, commandFieldName: string): ValidationError[] {\n const errors: ValidationError[] = [];\n if (linkCommands.includes(commandValue)) {\n for (const id of fieldValue) {\n if (!isInt(id)) {\n errors.push({ field: this.options.inverseFieldName, error: `Invalid ids in ${commandFieldName}` });\n }\n }\n }\n return errors;\n }\n\n async transformForCreate(dto: any): Promise<any> {\n const currentEntityName = classify(this.options.modelSingularName);\n const currentEntityRepository = this.options.entityManager.getRepository(currentEntityName);\n\n const relatedEntityName = classify(this.options.relationCoModelSingularName);\n const relatedEntityRepository = this.options.entityManager.getRepository(relatedEntityName);\n\n const result = await this.transformByCommand(dto, relatedEntityRepository, currentEntityRepository);\n if (result !== undefined) {\n dto[this.valueFieldName] = result;\n } else {\n delete dto[this.valueFieldName];\n }\n return dto;\n }\n\n private async transformByCommand(dto: any, relatedEntityRepository: any, currentEntityRepository: any): Promise<any[] | undefined> {\n // TODO : Need to add support for the multiple commands\n const command = dto[this.commandFieldName];\n const values = dto[this.valueFieldName];\n const ids = dto[this.idFieldName];\n \n switch (command) {\n case RelationFieldsCommand.create:\n return await this.transformForCommandCreate(values, relatedEntityRepository);\n case RelationFieldsCommand.update:\n return await this.transformForCommandUpdate(values, relatedEntityRepository, dto, currentEntityRepository);\n case RelationFieldsCommand.delete:\n return await this.transformForCommandDelete(values, relatedEntityRepository);\n case RelationFieldsCommand.clear:\n return this.transformForCommandClear();\n case RelationFieldsCommand.set:\n return await this.transformForCommandSet(ids, relatedEntityRepository);\n case RelationFieldsCommand.link:\n return await this.tranformForCommandLink(ids, relatedEntityRepository);\n case RelationFieldsCommand.unlink:\n return await this.transformForCommandUnLink(ids);\n default:\n this.logger.log(`Invalid command ${command}`);\n return null;\n }\n }\n\n private transformForCommandClear() {\n return []\n }\n\n private async transformForCommandSet(ids: any[], relatedEntityRepository: any): Promise<any[]> {\n const loadedEntities: any[] = await relatedEntityRepository.find({\n where : {id: In(ids) }\n })\n if (loadedEntities.length !== ids.length) {\n throw new Error('Invalid entity ids provided for set');\n }\n\n return loadedEntities;\n }\n\n private async tranformForCommandLink(ids: any[], relatedEntityRepository: any): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Link command is only supported for update operations');\n }\n\n const count: number = await relatedEntityRepository.count({\n where: { id: In(ids) }\n });\n if (count !== ids.length) {\n throw new Error('Invalid entity ids provided for linking');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .add(ids);\n\n return undefined;\n }\n\n private async transformForCommandUnLink(ids: any[]): Promise<undefined> {\n if (!this.options.isUpdate) {\n throw new Error('Unlink command is only supported for update operations');\n }\n\n await this.options.entityManager\n .createQueryBuilder()\n .relation(classify(this.options.modelSingularName), this.valueFieldName)\n .of(this.options.entityId)\n .remove(ids);\n\n return undefined;\n }\n\n private async transformForCommandCreate(values: any[], relatedEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n return transformedRelatedFields;\n }\n\n private async transformForCommandUpdate(values: any[], relatedEntityRepository: any, dto: any, currentEntityRepository: any): Promise<any[]> {\n const transformedRelatedFields = [];\n for (const entity of values) {\n if (entity.id) {\n const transformed = await relatedEntityRepository.preload(entity);\n transformedRelatedFields.push(transformed);\n }\n else {\n const transformed = relatedEntityRepository.create(entity);\n transformedRelatedFields.push(transformed);\n }\n }\n\n return transformedRelatedFields;\n }\n\n private async transformForCommandDelete(values: any[], relatedEntityRepository: any): Promise<any[]> {\n // Map and get the ids from the values\n const ids = values.map((value) => value.id);\n\n // Delete the ids linked to the associated entity\n await relatedEntityRepository.delete(ids);\n return null\n }\n\n private isApplyRequiredValidation(): boolean {\n return this.options.required;\n }\n\n // TODO: We have moved this to SolidRegistry service, refactor to use that service.\n // Returns the entity target class from the entity name\n // private getEntityTarget(entityName: string): any { //TODO Can be refactored to use this function from crud helper service\n // const entityMetadatas = this.options.entityManager.connection.entityMetadatas;\n // const entityMetadata = entityMetadatas.find(em => em.name === entityName);\n // return entityMetadata.target;\n // }\n}"]}
@@ -44,7 +44,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
44
44
  var ModuleMetadataHelperService_1;
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.ModuleMetadataHelperService = void 0;
47
- const strings_1 = require("@angular-devkit/core/src/utils/strings");
47
+ const lodash_1 = require("lodash");
48
48
  const common_1 = require("@nestjs/common");
49
49
  const fs = __importStar(require("fs/promises"));
50
50
  const path = __importStar(require("path"));
@@ -78,7 +78,7 @@ let ModuleMetadataHelperService = ModuleMetadataHelperService_1 = class ModuleMe
78
78
  if (!moduleName) {
79
79
  return '';
80
80
  }
81
- const dashModuleName = (0, strings_1.dasherize)(moduleName);
81
+ const dashModuleName = (0, lodash_1.kebabCase)(moduleName);
82
82
  const folderPath = path.resolve(process.cwd(), 'module-metadata', dashModuleName);
83
83
  const filePath = path.join(folderPath, `${dashModuleName}-metadata.json`);
84
84
  const fileExists = await this.fileService.exists(filePath);
@@ -95,7 +95,7 @@ let ModuleMetadataHelperService = ModuleMetadataHelperService_1 = class ModuleMe
95
95
  if (!moduleName) {
96
96
  return '';
97
97
  }
98
- const dashModuleName = (0, strings_1.dasherize)(moduleName);
98
+ const dashModuleName = (0, lodash_1.kebabCase)(moduleName);
99
99
  const folderPath = path.resolve(process.cwd(), 'module-metadata', dashModuleName);
100
100
  const exists = await this.fileService.exists(folderPath);
101
101
  return exists ? folderPath : '';
@@ -1 +1 @@
1
- {"version":3,"file":"module-metadata-helper.service.js","sourceRoot":"","sources":["../../src/helpers/module-metadata-helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAmE;AACnE,2CAAoD;AACpD,gDAAkC;AAClC,2CAA6B;AAC7B,4CAAuD;AACvD,2CAAoD;AAG7C,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAEpC,YAA6B,WAA4B;QAA5B,gBAAW,GAAX,WAAW,CAAiB;QADxC,WAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;IACV,CAAC;IAO9D,KAAK,CAAC,8BAA8B,CAAC,cAAsB;QACvD,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,CAAC;YACD,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CA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,CAAC;IACD,KAAK,CAAC,2BAA2B,CAAC,UAAkB;QAChD,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;QACd,CAAC;QAED,MAAM,cAAc,GAAG,IAAA,mBAAS,EAAC,UAAU,CAAC,CAAC;QAE7C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAC3B,OAAO,CAAC,GAAG,EAAE,EACb,iBAAiB,EACjB,cAAc,CACjB,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzD,OAAO,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC;CAEJ,CAAA;AApEY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;qCAGiC,sBAAe;GAFhD,2BAA2B,CAoEvC","sourcesContent":["import { dasherize } from \"@angular-devkit/core/src/utils/strings\";\nimport { Injectable, Logger } from \"@nestjs/common\";\nimport * as fs from 'fs/promises'; // Use the Promise-based version of fs for async/await\nimport * as path from 'path'; // To handle file paths\nimport { SOLID_CORE_MODULE_NAME } from \"src/constants\";\nimport { DiskFileService } from \"src/services/file\";\n\n@Injectable()\nexport class ModuleMetadataHelperService {\n private readonly logger = new Logger(ModuleMetadataHelperService.name);\n constructor(private readonly fileService: DiskFileService) { }\n // async getModuleMetadataConfig(moduleName: string): Promise<ModuleMetadata> {\n // const filePath = this.getModuleMetadataFilePath(moduleName);\n // const metadata = await this.getModuleMetadata(filePath);\n // return metadata;\n // }\n\n async getModuleMetadataConfiguration(configFilePath: string): Promise<any> {\n if (!configFilePath) {\n return null;\n }\n try {\n const fileContent = await fs.readFile(configFilePath, 'utf8');\n return JSON.parse(fileContent);\n }\n catch (error) {\n this.logger.error(`module metadata configuration non existent at: ${configFilePath}`);\n }\n\n return null;\n }\n\n async getModulePath(moduleName: string): Promise<string> {\n if (!moduleName) {\n return '';\n }\n return path.resolve(process.cwd(), 'src', moduleName);\n }\n\n async getModuleMetadataFilePath(moduleName: string): Promise<string> {\n if (!moduleName) {\n return '';\n }\n const dashModuleName = dasherize(moduleName);\n const folderPath = path.resolve(process.cwd(), 'module-metadata', dashModuleName);\n const filePath = path.join(folderPath, `${dashModuleName}-metadata.json`);\n // Check if filePath exists\n const fileExists = await this.fileService.exists(filePath);\n // this.logger.debug(`File exists: ${fileExists} at ${filePath}`);\n if (!fileExists) {\n // If the module is solid-core, try the fallback path, in case the current root directory is the solid core project\n if (dashModuleName === SOLID_CORE_MODULE_NAME) {\n const fallbackPath = path.resolve(process.cwd(), 'src', 'seeders', 'seed-data', `${dashModuleName}-metadata.json`);\n this.logger.debug(`Fallback path: ${fallbackPath}`);\n return fallbackPath;\n }\n }\n return filePath;\n }\n async getModuleMetadataFolderPath(moduleName: string): Promise<string> {\n if (!moduleName) {\n return '';\n }\n\n const dashModuleName = dasherize(moduleName);\n\n const folderPath = path.resolve(\n process.cwd(),\n 'module-metadata',\n dashModuleName,\n );\n\n const exists = await this.fileService.exists(folderPath);\n return exists ? folderPath : '';\n }\n\n}\n"]}
1
+ {"version":3,"file":"module-metadata-helper.service.js","sourceRoot":"","sources":["../../src/helpers/module-metadata-helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,2CAAoD;AACpD,gDAAkC;AAClC,2CAA6B;AAC7B,4CAAuD;AACvD,2CAAoD;AAG7C,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAEpC,YAA6B,WAA4B;QAA5B,gBAAW,GAAX,WAAW,CAAiB;QADxC,WAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;IACV,CAAC;IAO9D,KAAK,CAAC,8BAA8B,CAAC,cAAsB;QACvD,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QAChB,CAAC;QAC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AAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,YAAY,EAAE,CAAC,CAAC;gBACpD,OAAO,YAAY,CAAC;YACxB,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IACD,KAAK,CAAC,2BAA2B,CAAC,UAAkB;QAChD,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;QACd,CAAC;QAED,MAAM,cAAc,GAAG,IAAA,kBAAS,EAAC,UAAU,CAAC,CAAC;QAE7C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAC3B,OAAO,CAAC,GAAG,EAAE,EACb,iBAAiB,EACjB,cAAc,CACjB,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzD,OAAO,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC;CAEJ,CAAA;AApEY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;qCAGiC,sBAAe;GAFhD,2BAA2B,CAoEvC","sourcesContent":["import { kebabCase } from 'lodash';\nimport { Injectable, Logger } from \"@nestjs/common\";\nimport * as fs from 'fs/promises'; // Use the Promise-based version of fs for async/await\nimport * as path from 'path'; // To handle file paths\nimport { SOLID_CORE_MODULE_NAME } from \"src/constants\";\nimport { DiskFileService } from \"src/services/file\";\n\n@Injectable()\nexport class ModuleMetadataHelperService {\n private readonly logger = new Logger(ModuleMetadataHelperService.name);\n constructor(private readonly fileService: DiskFileService) { }\n // async getModuleMetadataConfig(moduleName: string): Promise<ModuleMetadata> {\n // const filePath = this.getModuleMetadataFilePath(moduleName);\n // const metadata = await this.getModuleMetadata(filePath);\n // return metadata;\n // }\n\n async getModuleMetadataConfiguration(configFilePath: string): Promise<any> {\n if (!configFilePath) {\n return null;\n }\n try {\n const fileContent = await fs.readFile(configFilePath, 'utf8');\n return JSON.parse(fileContent);\n }\n catch (error) {\n this.logger.error(`module metadata configuration non existent at: ${configFilePath}`);\n }\n\n return null;\n }\n\n async getModulePath(moduleName: string): Promise<string> {\n if (!moduleName) {\n return '';\n }\n return path.resolve(process.cwd(), 'src', moduleName);\n }\n\n async getModuleMetadataFilePath(moduleName: string): Promise<string> {\n if (!moduleName) {\n return '';\n }\n const dashModuleName = kebabCase(moduleName);\n const folderPath = path.resolve(process.cwd(), 'module-metadata', dashModuleName);\n const filePath = path.join(folderPath, `${dashModuleName}-metadata.json`);\n // Check if filePath exists\n const fileExists = await this.fileService.exists(filePath);\n // this.logger.debug(`File exists: ${fileExists} at ${filePath}`);\n if (!fileExists) {\n // If the module is solid-core, try the fallback path, in case the current root directory is the solid core project\n if (dashModuleName === SOLID_CORE_MODULE_NAME) {\n const fallbackPath = path.resolve(process.cwd(), 'src', 'seeders', 'seed-data', `${dashModuleName}-metadata.json`);\n this.logger.debug(`Fallback path: ${fallbackPath}`);\n return fallbackPath;\n }\n }\n return filePath;\n }\n async getModuleMetadataFolderPath(moduleName: string): Promise<string> {\n if (!moduleName) {\n return '';\n }\n\n const dashModuleName = kebabCase(moduleName);\n\n const folderPath = path.resolve(\n process.cwd(),\n 'module-metadata',\n dashModuleName,\n );\n\n const exists = await this.fileService.exists(folderPath);\n return exists ? folderPath : '';\n }\n\n}\n"]}
@@ -1,2 +1,3 @@
1
1
  export declare const lowerFirst: (str: string) => string;
2
+ export declare const classify: (s: string) => string;
2
3
  //# sourceMappingURL=string.helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/string.helper.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MAGxC,CAAA"}
1
+ {"version":3,"file":"string.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/string.helper.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MAGxC,CAAA;AAGD,eAAO,MAAM,QAAQ,MAAO,MAAM,KAAG,MAAkC,CAAC"}
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lowerFirst = void 0;
3
+ exports.classify = exports.lowerFirst = void 0;
4
4
  const lowerFirst = (str) => {
5
5
  if (!str)
6
6
  return str;
7
7
  return str.charAt(0).toLowerCase() + str.slice(1);
8
8
  };
9
9
  exports.lowerFirst = lowerFirst;
10
+ const lodash_1 = require("lodash");
11
+ const classify = (s) => (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(s));
12
+ exports.classify = classify;
10
13
  //# sourceMappingURL=string.helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.helper.js","sourceRoot":"","sources":["../../src/helpers/string.helper.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IAC9C,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IACrB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC,CAAA;AAHY,QAAA,UAAU,cAGtB","sourcesContent":["export const lowerFirst = (str: string): string => {\n if (!str) return str;\n return str.charAt(0).toLowerCase() + str.slice(1);\n}\n"]}
1
+ {"version":3,"file":"string.helper.js","sourceRoot":"","sources":["../../src/helpers/string.helper.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IAC9C,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IACrB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC,CAAA;AAHY,QAAA,UAAU,cAGtB;AAED,mCAA+C;AACxC,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAA,mBAAU,EAAC,IAAA,kBAAS,EAAC,CAAC,CAAC,CAAC,CAAC;AAA3D,QAAA,QAAQ,YAAmD","sourcesContent":["export const lowerFirst = (str: string): string => {\n if (!str) return str;\n return str.charAt(0).toLowerCase() + str.slice(1);\n}\n\nimport { upperFirst, camelCase } from 'lodash';\nexport const classify = (s: string): string => upperFirst(camelCase(s));\n"]}
@@ -15,6 +15,6 @@ export interface QueuePublisher<T> {
15
15
  }
16
16
  export interface QueueSubscriber<T> {
17
17
  options(): QueuesModuleOptions;
18
- subscribe(message: QueueMessage<T>): void;
18
+ subscribe(message: QueueMessage<T>): Promise<any>;
19
19
  }
20
20
  //# sourceMappingURL=mq.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../src/interfaces/mq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,CAAC,CAAC;IACX,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC;AAEnE,MAAM,WAAW,cAAc,CAAC,CAAC;IAC7B,OAAO,IAAI,mBAAmB,CAAC;IAC/B,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAC9B,OAAO,IAAI,mBAAmB,CAAC;IAC/B,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC7C"}
1
+ {"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../src/interfaces/mq.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,CAAC,CAAC;IACX,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC;AAEnE,MAAM,WAAW,cAAc,CAAC,CAAC;IAC7B,OAAO,IAAI,mBAAmB,CAAC;IAC/B,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAC9B,OAAO,IAAI,mBAAmB,CAAC;IAC/B,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"mq.js","sourceRoot":"","sources":["../../src/interfaces/mq.ts"],"names":[],"mappings":"","sourcesContent":["import { QueuesModuleOptions } from \"../interfaces\";\n\nexport interface QueueMessage<T> {\n messageId?: string;\n payload: T;\n parentEntityId?: any;\n parentEntity?: string;\n retryCount?: number;\n retryInterval?: number;\n currentRetry?: number;\n}\n\nexport type QueueServiceRole = 'publisher' | 'subscriber' | 'both';\n\nexport interface QueuePublisher<T> {\n options(): QueuesModuleOptions;\n publish(message: QueueMessage<T>): Promise<string>;\n}\n\nexport interface QueueSubscriber<T> {\n options(): QueuesModuleOptions;\n subscribe(message: QueueMessage<T>): void;\n}"]}
1
+ {"version":3,"file":"mq.js","sourceRoot":"","sources":["../../src/interfaces/mq.ts"],"names":[],"mappings":"","sourcesContent":["import { QueuesModuleOptions } from \"../interfaces\";\n\nexport interface QueueMessage<T> {\n messageId?: string;\n payload: T;\n parentEntityId?: any;\n parentEntity?: string;\n retryCount?: number;\n retryInterval?: number;\n currentRetry?: number;\n}\n\nexport type QueueServiceRole = 'publisher' | 'subscriber' | 'both';\n\nexport interface QueuePublisher<T> {\n options(): QueuesModuleOptions;\n publish(message: QueueMessage<T>): Promise<string>;\n}\n\nexport interface QueueSubscriber<T> {\n options(): QueuesModuleOptions;\n subscribe(message: QueueMessage<T>): Promise<any>;\n}\n"]}
@@ -12,6 +12,6 @@ export declare class ApiEmailQueueSubscriberDatabase extends DatabaseSubscriber<
12
12
  readonly poller: PollerService;
13
13
  constructor(emailService: ElasticEmailService, mqMessageService: MqMessageService, mqMessageQueueService: MqMessageQueueService, poller: PollerService);
14
14
  options(): QueuesModuleOptions;
15
- subscribe(message: QueueMessage<any>): void;
15
+ subscribe(message: QueueMessage<any>): Promise<void>;
16
16
  }
17
17
  //# sourceMappingURL=api-email-subscriber-database.service.d.ts.map
@@ -34,7 +34,7 @@ let ApiEmailQueueSubscriberDatabase = class ApiEmailQueueSubscriberDatabase exte
34
34
  };
35
35
  }
36
36
  subscribe(message) {
37
- this.emailService.sendEmailSynchronously(message);
37
+ return this.emailService.sendEmailSynchronously(message);
38
38
  }
39
39
  };
40
40
  exports.ApiEmailQueueSubscriberDatabase = ApiEmailQueueSubscriberDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"api-email-subscriber-database.service.js","sourceRoot":"","sources":["../../../src/jobs/database/api-email-subscriber-database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAE5C,0GAAkE;AAElE,0EAAmE;AACnE,sFAA8E;AAC9E,qFAA8E;AAE9E,mGAAqF;AACrF,kEAA4D;AAGrD,IAAM,+BAA+B,GAArC,MAAM,+BAAgC,SAAQ,gDAAuB;IACxE,YACqB,YAAiC,EACzC,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAE9B,KAAK,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;QALtC,iBAAY,GAAZ,YAAY,CAAqB;QACzC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;IAGlC,CAAC;IAED,OAAO;QACH,OAAO;YACH,GAAG,0CAAgB;SACtB,CAAA;IACL,CAAC;IAED,SAAS,CAAC,OAA0B;QAChC,IAAI,CAAC,YAAY,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;CACJ,CAAA;AAnBY,0EAA+B;0CAA/B,+BAA+B;IAD3C,IAAA,mBAAU,GAAE;qCAG0B,2CAAmB;QACvB,qCAAgB;QACX,gDAAqB;QACpC,8BAAa;GALzB,+BAA+B,CAmB3C","sourcesContent":["import { Injectable } from '@nestjs/common';\n\nimport mailQueueOptions from './api-email-queue-options-database';\nimport { QueueMessage } from 'src/interfaces/mq';\nimport { MqMessageService } from 'src/services/mq-message.service';\nimport { MqMessageQueueService } from 'src/services/mq-message-queue.service';\nimport { ElasticEmailService } from 'src/services/mail/elastic-email.service';\nimport { QueuesModuleOptions } from 'src/interfaces';\nimport { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';\nimport { PollerService } from 'src/services/poller.service';\n\n@Injectable()\nexport class ApiEmailQueueSubscriberDatabase extends DatabaseSubscriber<any> {\n constructor(\n private readonly emailService: ElasticEmailService,\n readonly mqMessageService: MqMessageService,\n readonly mqMessageQueueService: MqMessageQueueService,\n readonly poller: PollerService,\n ) {\n super(mqMessageService, mqMessageQueueService, poller);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...mailQueueOptions\n }\n }\n\n subscribe(message: QueueMessage<any>) {\n this.emailService.sendEmailSynchronously(message);\n }\n}\n"]}
1
+ {"version":3,"file":"api-email-subscriber-database.service.js","sourceRoot":"","sources":["../../../src/jobs/database/api-email-subscriber-database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAE5C,0GAAkE;AAElE,0EAAmE;AACnE,sFAA8E;AAC9E,qFAA8E;AAE9E,mGAAqF;AACrF,kEAA4D;AAGrD,IAAM,+BAA+B,GAArC,MAAM,+BAAgC,SAAQ,gDAAuB;IACxE,YACqB,YAAiC,EACzC,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAE9B,KAAK,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;QALtC,iBAAY,GAAZ,YAAY,CAAqB;QACzC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;IAGlC,CAAC;IAED,OAAO;QACH,OAAO;YACH,GAAG,0CAAgB;SACtB,CAAA;IACL,CAAC;IAED,SAAS,CAAC,OAA0B;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACJ,CAAA;AAnBY,0EAA+B;0CAA/B,+BAA+B;IAD3C,IAAA,mBAAU,GAAE;qCAG0B,2CAAmB;QACvB,qCAAgB;QACX,gDAAqB;QACpC,8BAAa;GALzB,+BAA+B,CAmB3C","sourcesContent":["import { Injectable } from '@nestjs/common';\n\nimport mailQueueOptions from './api-email-queue-options-database';\nimport { QueueMessage } from 'src/interfaces/mq';\nimport { MqMessageService } from 'src/services/mq-message.service';\nimport { MqMessageQueueService } from 'src/services/mq-message-queue.service';\nimport { ElasticEmailService } from 'src/services/mail/elastic-email.service';\nimport { QueuesModuleOptions } from 'src/interfaces';\nimport { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';\nimport { PollerService } from 'src/services/poller.service';\n\n@Injectable()\nexport class ApiEmailQueueSubscriberDatabase extends DatabaseSubscriber<any> {\n constructor(\n private readonly emailService: ElasticEmailService,\n readonly mqMessageService: MqMessageService,\n readonly mqMessageQueueService: MqMessageQueueService,\n readonly poller: PollerService,\n ) {\n super(mqMessageService, mqMessageQueueService, poller);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...mailQueueOptions\n }\n }\n\n subscribe(message: QueueMessage<any>) {\n return this.emailService.sendEmailSynchronously(message);\n }\n}\n"]}
@@ -12,6 +12,6 @@ export declare class Msg91WhatsappQueueSubscriberDatabase extends DatabaseSubscr
12
12
  readonly poller: PollerService;
13
13
  constructor(whatsappService: Msg91WhatsappService, mqMessageService: MqMessageService, mqMessageQueueService: MqMessageQueueService, poller: PollerService);
14
14
  options(): QueuesModuleOptions;
15
- subscribe(message: QueueMessage<any>): void;
15
+ subscribe(message: QueueMessage<any>): Promise<void>;
16
16
  }
17
17
  //# sourceMappingURL=msg91-whatsapp-subscriber-database.service.d.ts.map
@@ -34,7 +34,7 @@ let Msg91WhatsappQueueSubscriberDatabase = class Msg91WhatsappQueueSubscriberDat
34
34
  };
35
35
  }
36
36
  subscribe(message) {
37
- this.whatsappService.sendWhatsAppMessageSynchronously(message);
37
+ return this.whatsappService.sendWhatsAppMessageSynchronously(message);
38
38
  }
39
39
  };
40
40
  exports.Msg91WhatsappQueueSubscriberDatabase = Msg91WhatsappQueueSubscriberDatabase;
@@ -1 +1 @@
1
- {"version":3,"file":"msg91-whatsapp-subscriber-database.service.js","sourceRoot":"","sources":["../../../src/jobs/database/msg91-whatsapp-subscriber-database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAG5C,oHAA2E;AAC3E,0EAAmE;AACnE,sFAA8E;AAC9E,uFAAkF;AAElF,mGAAqF;AACrF,kEAA4D;AAGrD,IAAM,oCAAoC,GAA1C,MAAM,oCAAqC,SAAQ,gDAAuB;IAC7E,YACqB,eAAqC,EAC7C,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAE9B,KAAK,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;QALtC,oBAAe,GAAf,eAAe,CAAsB;QAC7C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;IAGlC,CAAC;IAED,OAAO;QACH,OAAO;YACH,GAAG,+CAAoB;SAC1B,CAAA;IACL,CAAC;IAED,SAAS,CAAC,OAA0B;QAChC,IAAI,CAAC,eAAe,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAAC;IACnE,CAAC;CACJ,CAAA;AAnBY,oFAAoC;+CAApC,oCAAoC;IADhD,IAAA,mBAAU,GAAE;qCAG6B,2CAAoB;QAC3B,qCAAgB;QACX,gDAAqB;QACpC,8BAAa;GALzB,oCAAoC,CAmBhD","sourcesContent":["import { Injectable } from '@nestjs/common';\n\nimport { QueueMessage } from 'src/interfaces/mq';\nimport whatsappQueueOptions from './msg91-whatsapp-queue-options-database';\nimport { MqMessageService } from 'src/services/mq-message.service';\nimport { MqMessageQueueService } from 'src/services/mq-message-queue.service';\nimport { Msg91WhatsappService } from 'src/services/whatsapp/Msg91WhatsappService';\nimport { QueuesModuleOptions } from 'src/interfaces';\nimport { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';\nimport { PollerService } from 'src/services/poller.service';\n\n@Injectable()\nexport class Msg91WhatsappQueueSubscriberDatabase extends DatabaseSubscriber<any> {\n constructor(\n private readonly whatsappService: Msg91WhatsappService,\n readonly mqMessageService: MqMessageService,\n readonly mqMessageQueueService: MqMessageQueueService,\n readonly poller: PollerService,\n ) {\n super(mqMessageService, mqMessageQueueService, poller);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...whatsappQueueOptions\n }\n }\n\n subscribe(message: QueueMessage<any>) {\n this.whatsappService.sendWhatsAppMessageSynchronously(message);\n }\n}\n"]}
1
+ {"version":3,"file":"msg91-whatsapp-subscriber-database.service.js","sourceRoot":"","sources":["../../../src/jobs/database/msg91-whatsapp-subscriber-database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAG5C,oHAA2E;AAC3E,0EAAmE;AACnE,sFAA8E;AAC9E,uFAAkF;AAElF,mGAAqF;AACrF,kEAA4D;AAGrD,IAAM,oCAAoC,GAA1C,MAAM,oCAAqC,SAAQ,gDAAuB;IAC7E,YACqB,eAAqC,EAC7C,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAE9B,KAAK,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;QALtC,oBAAe,GAAf,eAAe,CAAsB;QAC7C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;IAGlC,CAAC;IAED,OAAO;QACH,OAAO;YACH,GAAG,+CAAoB;SAC1B,CAAA;IACL,CAAC;IAED,SAAS,CAAC,OAA0B;QAChC,OAAO,IAAI,CAAC,eAAe,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CACJ,CAAA;AAnBY,oFAAoC;+CAApC,oCAAoC;IADhD,IAAA,mBAAU,GAAE;qCAG6B,2CAAoB;QAC3B,qCAAgB;QACX,gDAAqB;QACpC,8BAAa;GALzB,oCAAoC,CAmBhD","sourcesContent":["import { Injectable } from '@nestjs/common';\n\nimport { QueueMessage } from 'src/interfaces/mq';\nimport whatsappQueueOptions from './msg91-whatsapp-queue-options-database';\nimport { MqMessageService } from 'src/services/mq-message.service';\nimport { MqMessageQueueService } from 'src/services/mq-message-queue.service';\nimport { Msg91WhatsappService } from 'src/services/whatsapp/Msg91WhatsappService';\nimport { QueuesModuleOptions } from 'src/interfaces';\nimport { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';\nimport { PollerService } from 'src/services/poller.service';\n\n@Injectable()\nexport class Msg91WhatsappQueueSubscriberDatabase extends DatabaseSubscriber<any> {\n constructor(\n private readonly whatsappService: Msg91WhatsappService,\n readonly mqMessageService: MqMessageService,\n readonly mqMessageQueueService: MqMessageQueueService,\n readonly poller: PollerService,\n ) {\n super(mqMessageService, mqMessageQueueService, poller);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...whatsappQueueOptions\n }\n }\n\n subscribe(message: QueueMessage<any>) {\n return this.whatsappService.sendWhatsAppMessageSynchronously(message);\n }\n}\n"]}