@solidxai/core 0.1.6-beta.2 → 0.1.6-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entities/chatter-message-details.entity.d.ts +1 -0
- package/dist/entities/chatter-message-details.entity.d.ts.map +1 -1
- package/dist/entities/chatter-message-details.entity.js +5 -1
- package/dist/entities/chatter-message-details.entity.js.map +1 -1
- package/dist/entities/common.entity.js +1 -1
- package/dist/entities/common.entity.js.map +1 -1
- package/dist/entities/legacy-common.entity.d.ts.map +1 -1
- package/dist/entities/legacy-common.entity.js +1 -1
- package/dist/entities/legacy-common.entity.js.map +1 -1
- package/dist/interfaces.d.ts +4 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +73 -3
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +16 -12
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/chatter-message.service.d.ts +0 -1
- package/dist/services/chatter-message.service.d.ts.map +1 -1
- package/dist/services/chatter-message.service.js +22 -19
- package/dist/services/chatter-message.service.js.map +1 -1
- package/dist/services/dashboard-question.service.d.ts +4 -0
- package/dist/services/dashboard-question.service.d.ts.map +1 -1
- package/dist/services/dashboard-question.service.js +22 -8
- package/dist/services/dashboard-question.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +101 -6
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.d.ts +2 -4
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.d.ts.map +1 -1
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.js +2 -1
- package/dist/services/question-data-providers/chartjs-sql-data-provider.service.js.map +1 -1
- package/dist/services/question-data-providers/interfaces.d.ts +1 -0
- package/dist/services/question-data-providers/interfaces.d.ts.map +1 -0
- package/dist/services/question-data-providers/interfaces.js +1 -0
- package/dist/services/question-data-providers/interfaces.js.map +1 -0
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.d.ts +2 -5
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.d.ts.map +1 -1
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.js +2 -1
- package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.js.map +1 -1
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.d.ts +2 -5
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.d.ts.map +1 -1
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.js +2 -1
- package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.js.map +1 -1
- package/dist/services/queues/database-subscriber.service.d.ts +4 -2
- package/dist/services/queues/database-subscriber.service.d.ts.map +1 -1
- package/dist/services/queues/database-subscriber.service.js +9 -1
- package/dist/services/queues/database-subscriber.service.js.map +1 -1
- package/dist/services/queues/publisher-factory.service.d.ts.map +1 -1
- package/dist/services/queues/publisher-factory.service.js +4 -6
- package/dist/services/queues/publisher-factory.service.js.map +1 -1
- package/dist/services/queues/rabbitmq-subscriber.service.d.ts +4 -2
- package/dist/services/queues/rabbitmq-subscriber.service.d.ts.map +1 -1
- package/dist/services/queues/rabbitmq-subscriber.service.js +9 -1
- package/dist/services/queues/rabbitmq-subscriber.service.js.map +1 -1
- package/dist/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.d.ts.map +1 -1
- package/dist/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.js +4 -1
- package/dist/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.js.map +1 -1
- package/dist/transformers/typeorm/local-date-time-transformer.d.ts +4 -4
- package/dist/transformers/typeorm/local-date-time-transformer.d.ts.map +1 -1
- package/dist/transformers/typeorm/local-date-time-transformer.js +25 -28
- package/dist/transformers/typeorm/local-date-time-transformer.js.map +1 -1
- package/package.json +1 -1
- package/src/entities/chatter-message-details.entity.ts +3 -0
- package/src/entities/common.entity.ts +2 -2
- package/src/entities/legacy-common.entity.ts +3 -4
- package/src/interfaces.ts +7 -1
- package/src/seeders/seed-data/solid-core-metadata.json +73 -3
- package/src/services/authentication.service.ts +18 -14
- package/src/services/chatter-message.service.ts +21 -21
- package/src/services/dashboard-question.service.ts +23 -4
- package/src/services/model-metadata.service.ts +109 -7
- package/src/services/question-data-providers/chartjs-sql-data-provider.service.ts +3 -7
- package/src/services/question-data-providers/interfaces.ts +0 -0
- package/src/services/question-data-providers/prime-react-datatable-sql-data-provider.service.ts +4 -8
- package/src/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.ts +4 -8
- package/src/services/queues/database-subscriber.service.ts +12 -1
- package/src/services/queues/publisher-factory.service.ts +8 -6
- package/src/services/queues/rabbitmq-subscriber.service.ts +12 -1
- package/src/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.ts +4 -1
- package/src/transformers/typeorm/local-date-time-transformer.ts +41 -33
package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.js
CHANGED
|
@@ -29,7 +29,8 @@ let PrimeReactDatatableSqlDataProvider = PrimeReactDatatableSqlDataProvider_1 =
|
|
|
29
29
|
name() {
|
|
30
30
|
return "PrimeReactDatatableSqlDataProvider";
|
|
31
31
|
}
|
|
32
|
-
async getData(question,
|
|
32
|
+
async getData(question, context) {
|
|
33
|
+
const expressions = context?.expressions || [];
|
|
33
34
|
const kpi = await (0, helpers_1.getKpi)(question, expressions, this.entityManager, this.sqlExpressionResolver);
|
|
34
35
|
const labelSql = question.labelSql;
|
|
35
36
|
const labelResults = await this.entityManager.query(labelSql);
|
package/dist/services/question-data-providers/prime-react-datatable-sql-data-provider.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prime-react-datatable-sql-data-provider.service.js","sourceRoot":"","sources":["../../../src/services/question-data-providers/prime-react-datatable-sql-data-provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,4HAA0G;AAG1G,qCAAwC;AACxC,wFAAkF;AAClF,2CAAwC;AAExC,uCAAmC;
|
|
1
|
+
{"version":3,"file":"prime-react-datatable-sql-data-provider.service.js","sourceRoot":"","sources":["../../../src/services/question-data-providers/prime-react-datatable-sql-data-provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,4HAA0G;AAG1G,qCAAwC;AACxC,wFAAkF;AAClF,2CAAwC;AAExC,uCAAmC;AAI5B,IAAM,kCAAkC,0CAAxC,MAAM,kCAAkC;IAG3C,YAA6B,aAA4B,EAAmB,qBAAmD;QAAlG,kBAAa,GAAb,aAAa,CAAe;QAAmB,0BAAqB,GAArB,qBAAqB,CAA8B;QAF9G,WAAM,GAAG,IAAI,eAAM,CAAC,oCAAkC,CAAC,IAAI,CAAC,CAAC;IAEqD,CAAC;IAEpI,IAAI;QACA,OAAO,qLAAqL,CAAC;IACjM,CAAC;IAED,IAAI;QACA,OAAO,oCAAoC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAA2B,EAAE,OAAwC;QAC/E,MAAM,WAAW,GAAoB,OAAO,EAAE,WAAW,IAAI,EAAE,CAAC;QAMhE,MAAM,GAAG,GAAW,MAAM,IAAA,gBAAM,EAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAExG,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QACnC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CA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,CA6D9C","sourcesContent":["import { Injectable } from \"@nestjs/common\";\nimport { DashboardQuestionDataProvider } from \"src/decorators/dashboard-question-data-provider.decorator\";\nimport { DashboardQuestion } from \"src/entities/dashboard-question.entity\";\nimport { IDashboardQuestionDataProvider, QuestionSqlDataProviderContext } from \"src/interfaces\";\nimport { EntityManager } from \"typeorm\";\nimport { SqlExpressionResolverService } from \"../sql-expression-resolver.service\";\nimport { Logger } from '@nestjs/common';\nimport { SqlExpression } from \"./chartjs-sql-data-provider.service\";\nimport { getKpi } from \"./helpers\";\n\n@DashboardQuestionDataProvider()\n@Injectable()\nexport class PrimeReactDatatableSqlDataProvider implements IDashboardQuestionDataProvider<QuestionSqlDataProviderContext, any> {\n private readonly logger = new Logger(PrimeReactDatatableSqlDataProvider.name);\n\n constructor(private readonly entityManager: EntityManager, private readonly sqlExpressionResolver: SqlExpressionResolverService) { }\n\n help(): string {\n return \"Provides data for dashboard questions using a SQL dataset configuration. Configure your SQL dataset in the admin panel, then reference it in your dashboard question to fetch data.\";\n }\n\n name(): string {\n return \"PrimeReactDatatableSqlDataProvider\";\n }\n\n async getData(question: DashboardQuestion, context?: QuestionSqlDataProviderContext): Promise<any> {\n const expressions: SqlExpression[] = context?.expressions || [];\n\n // TODO: put some validation to check if the results of each SQL in each dataset returns the same number of rows \n\n // Check the expected response for prime react data tables to understand what is going on here...\n\n const kpi: string = await getKpi(question, expressions, this.entityManager, this.sqlExpressionResolver);\n // TODO: Load the set of labels by using a separate field on the question entity.\n const labelSql = question.labelSql;\n const labelResults = await this.entityManager.query(labelSql);\n const columns = [];\n for (let i = 0; i < labelResults.length; i++) {\n const labelResult = labelResults[i];\n columns.push({\n field: labelResult['field'],\n header: labelResult['header'],\n });\n }\n\n // Load the chart options as a JSON \n // const chartOptions = JSON.parse(question.barChartLabelOptions || '{}');\n\n const values = []\n\n // For meter group we can assume that we only have one sql dataset config.\n const questionSqlDatasetConfig = question.questionSqlDatasetConfigs[0];\n\n const sql = questionSqlDatasetConfig.sql;\n if (!sql) {\n throw new Error(`SQL dataset ${questionSqlDatasetConfig.datasetName} configuration does not contain a valid SQL query.`);\n }\n\n const sqlReplacementResult = this.sqlExpressionResolver.resolveSqlWithExpressions(sql, expressions || []);\n this.logger.debug(`Final Sql query for dataset [${questionSqlDatasetConfig.datasetName}] is query=[${sqlReplacementResult.rawSql}]`);\n this.logger.debug(`Final Sql query for dataset [${questionSqlDatasetConfig.datasetName}] is parameters=[${JSON.stringify(sqlReplacementResult.parameters)}]`);\n const results = await this.entityManager.query(sqlReplacementResult.rawSql, sqlReplacementResult.parameters);\n\n return {\n kpi,\n visualisedAs: question.visualisedAs,\n visualizationData: {\n columns,\n rows: results,\n }\n };\n\n }\n}"]}
|
package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { DashboardQuestion } from "src/entities/dashboard-question.entity";
|
|
2
|
-
import { IDashboardQuestionDataProvider } from "src/interfaces";
|
|
2
|
+
import { IDashboardQuestionDataProvider, QuestionSqlDataProviderContext } from "src/interfaces";
|
|
3
3
|
import { EntityManager } from "typeorm";
|
|
4
4
|
import { SqlExpressionResolverService } from "../sql-expression-resolver.service";
|
|
5
|
-
import { SqlExpression } from "./chartjs-sql-data-provider.service";
|
|
6
|
-
export interface QuestionSqlDataProviderContext {
|
|
7
|
-
}
|
|
8
5
|
export declare class PrimeReactMeterGroupSqlDataProvider implements IDashboardQuestionDataProvider<QuestionSqlDataProviderContext, any> {
|
|
9
6
|
private readonly entityManager;
|
|
10
7
|
private readonly sqlExpressionResolver;
|
|
@@ -14,6 +11,6 @@ export declare class PrimeReactMeterGroupSqlDataProvider implements IDashboardQu
|
|
|
14
11
|
name(): string;
|
|
15
12
|
hslToHex(h: number, s: number, l: number): string;
|
|
16
13
|
generateDistinctColors(count: number): string[];
|
|
17
|
-
getData(question: DashboardQuestion,
|
|
14
|
+
getData(question: DashboardQuestion, context?: QuestionSqlDataProviderContext): Promise<any>;
|
|
18
15
|
}
|
|
19
16
|
//# sourceMappingURL=prime-react-meter-group-sql-data-provider.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prime-react-meter-group-sql-data-provider.service.d.ts","sourceRoot":"","sources":["../../../src/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"prime-react-meter-group-sql-data-provider.service.d.ts","sourceRoot":"","sources":["../../../src/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAKlF,qBAEa,mCAAoC,YAAW,8BAA8B,CAAC,8BAA8B,EAAE,GAAG,CAAC;IAG/G,OAAO,CAAC,QAAQ,CAAC,aAAa;IAAiB,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAFjG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwD;gBAElD,aAAa,EAAE,aAAa,EAAmB,qBAAqB,EAAE,4BAA4B;IAE/H,IAAI,IAAI,MAAM;IAId,IAAI,IAAI,MAAM;IAId,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAcjD,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAezC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,8BAA8B,GAAG,OAAO,CAAC,GAAG,CAAC;CA4DrG"}
|
package/dist/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.js
CHANGED
|
@@ -50,7 +50,8 @@ let PrimeReactMeterGroupSqlDataProvider = PrimeReactMeterGroupSqlDataProvider_1
|
|
|
50
50
|
}
|
|
51
51
|
return colors;
|
|
52
52
|
}
|
|
53
|
-
async getData(question,
|
|
53
|
+
async getData(question, context) {
|
|
54
|
+
const expressions = context?.expressions || [];
|
|
54
55
|
const kpi = await (0, helpers_1.getKpi)(question, expressions, this.entityManager, this.sqlExpressionResolver);
|
|
55
56
|
const chartOptions = JSON.parse(question.chartOptions || '{}');
|
|
56
57
|
const values = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prime-react-meter-group-sql-data-provider.service.js","sourceRoot":"","sources":["../../../src/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,4HAA0G;AAG1G,qCAAwC;AACxC,wFAAkF;AAClF,2CAAwC;AAExC,uCAAmC;
|
|
1
|
+
{"version":3,"file":"prime-react-meter-group-sql-data-provider.service.js","sourceRoot":"","sources":["../../../src/services/question-data-providers/prime-react-meter-group-sql-data-provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,4HAA0G;AAG1G,qCAAwC;AACxC,wFAAkF;AAClF,2CAAwC;AAExC,uCAAmC;AAI5B,IAAM,mCAAmC,2CAAzC,MAAM,mCAAmC;IAG5C,YAA6B,aAA4B,EAAmB,qBAAmD;QAAlG,kBAAa,GAAb,aAAa,CAAe;QAAmB,0BAAqB,GAArB,qBAAqB,CAA8B;QAF9G,WAAM,GAAG,IAAI,eAAM,CAAC,qCAAmC,CAAC,IAAI,CAAC,CAAC;IAEoD,CAAC;IAEpI,IAAI;QACA,OAAO,qLAAqL,CAAC;IACjM,CAAC;IAED,IAAI;QACA,OAAO,qCAAqC,CAAC;IACjD,CAAC;IAED,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oBAAoB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9J,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAE7G,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAG3D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAE1B,MAAM,qBAAqB,GAAG,YAAY,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAC,CAAC;YACvG,MAAM,KAAK,GAAG,OAAO,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAE5F,MAAM,CAAC,IAAI,CAAC;gBACR,KAAK,EAAE,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC;gBACvD,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC;aAC1D,CAAC,CAAA;QACN,CAAC;QAED,OAAO;YACH,GAAG;YACH,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,iBAAiB,EAAE;gBACf,OAAO,EAAE,MAAM;aAClB;SACJ,CAAC;IAEN,CAAC;CACJ,CAAA;AAtGY,kFAAmC;8CAAnC,mCAAmC;IAF/C,IAAA,0EAA6B,GAAE;IAC/B,IAAA,mBAAU,GAAE;qCAImC,uBAAa,EAA0C,8DAA4B;GAHtH,mCAAmC,CAsG/C","sourcesContent":["import { Injectable } from \"@nestjs/common\";\nimport { DashboardQuestionDataProvider } from \"src/decorators/dashboard-question-data-provider.decorator\";\nimport { DashboardQuestion } from \"src/entities/dashboard-question.entity\";\nimport { IDashboardQuestionDataProvider, QuestionSqlDataProviderContext } from \"src/interfaces\";\nimport { EntityManager } from \"typeorm\";\nimport { SqlExpressionResolverService } from \"../sql-expression-resolver.service\";\nimport { Logger } from '@nestjs/common';\nimport { SqlExpression } from \"./chartjs-sql-data-provider.service\";\nimport { getKpi } from \"./helpers\";\n\n@DashboardQuestionDataProvider()\n@Injectable()\nexport class PrimeReactMeterGroupSqlDataProvider implements IDashboardQuestionDataProvider<QuestionSqlDataProviderContext, any> {\n private readonly logger = new Logger(PrimeReactMeterGroupSqlDataProvider.name);\n\n constructor(private readonly entityManager: EntityManager, private readonly sqlExpressionResolver: SqlExpressionResolverService) { }\n\n help(): string {\n return \"Provides data for dashboard questions using a SQL dataset configuration. Configure your SQL dataset in the admin panel, then reference it in your dashboard question to fetch data.\";\n }\n\n name(): string {\n return \"PrimeReactMeterGroupSqlDataProvider\";\n }\n\n hslToHex(h: number, s: number, l: number): string {\n l /= 100;\n s /= 100;\n\n const k = (n: number) => (n + h / 30) % 12;\n const a = s * Math.min(l, 1 - l);\n const f = (n: number) =>\n Math.round(255 * (l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)))));\n\n return `#${f(0).toString(16).padStart(2, '0')}${f(8).toString(16).padStart(2, '0')}${f(4)\n .toString(16)\n .padStart(2, '0')}`;\n }\n\n generateDistinctColors(count: number): string[] {\n const colors: string[] = [];\n\n const hueStep = 360 / count;\n const saturation = 65; // keep it vibrant\n const lightness = 55; // balanced for both light/dark themes\n\n for (let i = 0; i < count; i++) {\n const hue = Math.round(i * hueStep);\n colors.push(this.hslToHex(hue, saturation, lightness));\n }\n\n return colors;\n }\n\n async getData(question: DashboardQuestion, context?: QuestionSqlDataProviderContext): Promise<any> {\n const expressions: SqlExpression[] = context?.expressions || [];\n\n // TODO: put some validation to check if the results of each SQL in each dataset returns the same number of rows \n\n // This is what we have to return.\n // const values = [\n // { label: 'Apps', color: '#34d399', value: 16 },\n // { label: 'Messages', color: '#fbbf24', value: 8 },\n // { label: 'Media', color: '#60a5fa', value: 24 },\n // { label: 'System', color: '#c084fc', value: 10 }\n // ];\n\n // TODO: Load the set of labels by using a separate field on the question entity.\n\n const kpi: string = await getKpi(question, expressions, this.entityManager, this.sqlExpressionResolver);\n \n // Load the chart options as a JSON \n const chartOptions = JSON.parse(question.chartOptions || '{}');\n\n const values = []\n\n // For meter group we can assume that we only have one sql dataset config.\n const questionSqlDatasetConfig = question.questionSqlDatasetConfigs[0];\n\n const sql = questionSqlDatasetConfig.sql;\n if (!sql) {\n throw new Error(`SQL dataset ${questionSqlDatasetConfig.datasetName} configuration does not contain a valid SQL query.`);\n }\n\n const sqlReplacementResult = this.sqlExpressionResolver.resolveSqlWithExpressions(sql, expressions || []);\n this.logger.debug(`Final Sql query for dataset [${questionSqlDatasetConfig.datasetName}] is query=[${sqlReplacementResult.rawSql}]`);\n this.logger.debug(`Final Sql query for dataset [${questionSqlDatasetConfig.datasetName}] is parameters=[${JSON.stringify(sqlReplacementResult.parameters)}]`);\n const results = await this.entityManager.query(sqlReplacementResult.rawSql, sqlReplacementResult.parameters);\n\n const colors = this.generateDistinctColors(results.length);\n\n // Also for each data set we create the dataset object as is expected by ChartJs.\n for (let i = 0; i < results.length; i++) {\n const result = results[i];\n\n const colorFromChartOptions = chartOptions?.colors?.[result[questionSqlDatasetConfig.labelColumnName]];\n const color = typeof colorFromChartOptions === 'string' ? colorFromChartOptions : colors[i];\n\n values.push({\n label: result[questionSqlDatasetConfig.labelColumnName],\n color: color,\n value: result[questionSqlDatasetConfig.valueColumnName]\n })\n }\n\n return {\n kpi,\n visualizedAs: question.visualisedAs,\n visualizationData: {\n dataset: values\n },\n };\n\n }\n}"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
1
|
+
import { Logger, OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { QueuesModuleOptions } from "../../interfaces";
|
|
3
3
|
import { QueueMessage, QueueSubscriber } from '../../interfaces/mq';
|
|
4
4
|
import { MqMessageQueueService } from '../mq-message-queue.service';
|
|
@@ -8,10 +8,12 @@ export declare abstract class DatabaseSubscriber<T> implements OnModuleInit, Que
|
|
|
8
8
|
protected readonly mqMessageService: MqMessageService;
|
|
9
9
|
protected readonly mqMessageQueueService: MqMessageQueueService;
|
|
10
10
|
protected readonly poller: PollerService;
|
|
11
|
-
private
|
|
11
|
+
private _loggerInstance?;
|
|
12
12
|
private readonly url;
|
|
13
13
|
private readonly serviceRole;
|
|
14
14
|
constructor(mqMessageService: MqMessageService, mqMessageQueueService: MqMessageQueueService, poller: PollerService);
|
|
15
|
+
protected get loggerContext(): string;
|
|
16
|
+
protected get logger(): Logger;
|
|
15
17
|
abstract subscribe(message: QueueMessage<T>): any;
|
|
16
18
|
abstract options(): QueuesModuleOptions;
|
|
17
19
|
private processNext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-subscriber.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"database-subscriber.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,8BAAsB,kBAAkB,CAAC,CAAC,CAAE,YAAW,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAM/E,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IACrD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IAC/D,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa;IAP5C,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAGd,gBAAgB,EAAE,gBAAgB,EAClC,qBAAqB,EAAE,qBAAqB,EAC5C,MAAM,EAAE,aAAa;IAS5C,SAAS,KAAK,aAAa,IAAI,MAAM,CAEpC;IAED,SAAS,KAAK,MAAM,IAAI,MAAM,CAK7B;IAED,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3C,QAAQ,CAAC,OAAO,IAAI,mBAAmB;YAEzB,WAAW;IA6CnB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAqCnC,eAAe;cAUC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAazD,YAAY;YAsBZ,sBAAsB;CAoCvC"}
|
|
@@ -8,12 +8,20 @@ class DatabaseSubscriber {
|
|
|
8
8
|
this.mqMessageService = mqMessageService;
|
|
9
9
|
this.mqMessageQueueService = mqMessageQueueService;
|
|
10
10
|
this.poller = poller;
|
|
11
|
-
this.logger = new common_1.Logger(DatabaseSubscriber.name);
|
|
12
11
|
this.serviceRole = process.env.QUEUES_SERVICE_ROLE;
|
|
13
12
|
if (!this.serviceRole) {
|
|
14
13
|
this.logger.debug('Queue service Role is not defined in the environment variables');
|
|
15
14
|
}
|
|
16
15
|
}
|
|
16
|
+
get loggerContext() {
|
|
17
|
+
return this.constructor.name;
|
|
18
|
+
}
|
|
19
|
+
get logger() {
|
|
20
|
+
if (!this._loggerInstance) {
|
|
21
|
+
this._loggerInstance = new common_1.Logger(this.loggerContext);
|
|
22
|
+
}
|
|
23
|
+
return this._loggerInstance;
|
|
24
|
+
}
|
|
17
25
|
async processNext(queueName) {
|
|
18
26
|
const job = await this.mqMessageService.lockNextPendingMessage(queueName);
|
|
19
27
|
if (!job) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAMtD,qCAAoD;AAEpD,MAAsB,kBAAkB;IAKpC,YACuB,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAFrB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;QAP3B,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAS1D,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACxF,CAAC;IAEL,CAAC;IAMO,KAAK,CAAC,WAAW,CAAC,SAAiB;QAEvC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAC1E,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,OAAO;QACX,CAAC;QAED,MAAM,oBAAoB,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAGlD,IAAI,OAAO,GAAoB,IAAI,CAAC;QAEpC,IAAI,CAAC;YACD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAoB,CAAC;YAG9D,IAAI,CAAC,OAAO,CAAC,UAAU;gBAAE,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC;YAChD,IAAI,CAAC,OAAO,CAAC,aAAa;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aAAa,CAAC,eAAe,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;gBAC3G,CAAC;gBACD,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBACxB,aAAa,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;gBACrC,CAAC;gBACD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACrB,aAAa,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;gBACnC,CAAC;gBACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;gBACrE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,mBAAmB,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3F,CAAC;QACL,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;CACJ;AAxLD,gDAwLC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { PollerService } from '../poller.service';\nimport { buildNamespacedQueueName } from './common';\n\nexport abstract class DatabaseSubscriber<T> implements OnModuleInit, QueueSubscriber<T> {\n private readonly logger = new Logger(DatabaseSubscriber.name);\n private readonly url: string;\n private readonly serviceRole: string;\n\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n protected readonly poller: PollerService,\n ) {\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`DatabaseSubscriber instance created with options: ${JSON.stringify(this.options())}`);\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n private async processNext(queueName: string) {\n // this.logger.debug(`#### DatabaseSubscriber processing next message from queue: ${queueName}`);\n const job = await this.mqMessageService.lockNextPendingMessage(queueName);\n if (!job) {\n return;\n }\n\n const messageContentString = job.input.toString();\n // this.logger.debug(`DatabaseSubscriber Received raw message: ${messageContentString}`);\n\n let message: QueueMessage<T> = null;\n\n try {\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n\n // this is the first time we are receiving the message so we set the currentRetry to 0\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n await this.processMessage(message);\n }\n catch (error) {\n this.logger.error(`Error processing message: ${error.message}`);\n\n // if an error occurs then if retryCount is set we start retrying. \n if (message) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n // Discard the message after max retries\n await this.updateStatusInDatabase('failed', message, error.message, '');\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n }\n }\n }\n // this.logger.debug(`#### DatabaseSubscriber finished processing message from queue: ${queueName}`);\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of DatabaseSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'database';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n\n // we will start subscriber only if the current service role is subscriber. \n if (['both', 'subscriber'].includes(this.serviceRole) && defaultBroker === 'database' && solidCliRunning === \"false\") {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`DatabaseSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n this.poller.start(namespacedQueueName, (q) => this.processNext(q), {\n baseDelayMs: 1000,\n maxDelayMs: 30_000,\n timeoutPerIterationMs: 5 * 60_000,\n jitter: true,\n });\n\n this.logger.log(`DatabaseSubscriber ready to consume messages: ${JSON.stringify(this.options())}`);\n }\n }\n\n onModuleDestroy() {\n const options = this.options();\n const queueName = options.queueName;\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n this.poller.stop(namespacedQueueName);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // TODO: Update the database to indicate that the task is finished.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n }\n\n /**\n * Retry the message by invoking the processing logic again.\n */\n private async retryMessage(message: QueueMessage<T>) {\n try {\n await this.processMessage(message);\n } catch (error) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms: ${error.message}`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n\n // TODO: Store the error in the database and update the status accordingly.\n await this.updateStatusInDatabase('failed', message, error.message, '');\n\n }\n }\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n try {\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${message.messageId}`);\n\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n this.logger.debug(`Found message in database: ${JSON.stringify(mqMessage.messageId)}`);\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${mqMessage.id}`);\n\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n this.logger.debug(`Message status updated to ${stage} for messageId: ${mqMessage.id}`);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"database-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/database-subscriber.service.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAMtD,qCAAoD;AAEpD,MAAsB,kBAAkB;IAKpC,YACuB,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB;QAFrB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;QAExC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACxF,CAAC;IAE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gBACrE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,mBAAmB,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3F,CAAC;QACL,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;CACJ;AAnMD,gDAmMC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { PollerService } from '../poller.service';\nimport { buildNamespacedQueueName } from './common';\n\nexport abstract class DatabaseSubscriber<T> implements OnModuleInit, QueueSubscriber<T> {\n private _loggerInstance?: Logger;\n private readonly url: string;\n private readonly serviceRole: string;\n\n constructor(\n protected readonly mqMessageService: MqMessageService,\n protected readonly mqMessageQueueService: MqMessageQueueService,\n protected readonly poller: PollerService,\n ) {\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`DatabaseSubscriber instance created with options: ${JSON.stringify(this.options())}`);\n }\n\n protected get loggerContext(): string {\n return this.constructor.name;\n }\n\n protected get logger(): Logger {\n if (!this._loggerInstance) {\n this._loggerInstance = new Logger(this.loggerContext);\n }\n return this._loggerInstance;\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n private async processNext(queueName: string) {\n // this.logger.debug(`#### DatabaseSubscriber processing next message from queue: ${queueName}`);\n const job = await this.mqMessageService.lockNextPendingMessage(queueName);\n if (!job) {\n return;\n }\n\n const messageContentString = job.input.toString();\n // this.logger.debug(`DatabaseSubscriber Received raw message: ${messageContentString}`);\n\n let message: QueueMessage<T> = null;\n\n try {\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n\n // this is the first time we are receiving the message so we set the currentRetry to 0\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n await this.processMessage(message);\n }\n catch (error) {\n this.logger.error(`Error processing message: ${error.message}`);\n\n // if an error occurs then if retryCount is set we start retrying. \n if (message) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n // Discard the message after max retries\n await this.updateStatusInDatabase('failed', message, error.message, '');\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n }\n }\n }\n // this.logger.debug(`#### DatabaseSubscriber finished processing message from queue: ${queueName}`);\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of DatabaseSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'database';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n\n // we will start subscriber only if the current service role is subscriber. \n if (['both', 'subscriber'].includes(this.serviceRole) && defaultBroker === 'database' && solidCliRunning === \"false\") {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`DatabaseSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n this.poller.start(namespacedQueueName, (q) => this.processNext(q), {\n baseDelayMs: 1000,\n maxDelayMs: 30_000,\n timeoutPerIterationMs: 5 * 60_000,\n jitter: true,\n });\n\n this.logger.log(`DatabaseSubscriber ready to consume messages: ${JSON.stringify(this.options())}`);\n }\n }\n\n onModuleDestroy() {\n const options = this.options();\n const queueName = options.queueName;\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n this.poller.stop(namespacedQueueName);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // TODO: Update the database to indicate that the task is finished.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n }\n\n /**\n * Retry the message by invoking the processing logic again.\n */\n private async retryMessage(message: QueueMessage<T>) {\n try {\n await this.processMessage(message);\n } catch (error) {\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms: ${error.message}`);\n setTimeout(() => {\n this.retryMessage(message);\n }, message.retryInterval);\n } else {\n this.logger.error(`Message failed after ${message.retryCount} attempts: ${error.message}`);\n\n // TODO: Store the error in the database and update the status accordingly.\n await this.updateStatusInDatabase('failed', message, error.message, '');\n\n }\n }\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n try {\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${message.messageId}`);\n\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n this.logger.debug(`Found message in database: ${JSON.stringify(mqMessage.messageId)}`);\n this.logger.debug(`Updating message status in database: ${stage} for messageId: ${mqMessage.id}`);\n\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n this.logger.debug(`Message status updated to ${stage} for messageId: ${mqMessage.id}`);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publisher-factory.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/publisher-factory.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,qBACa,gBAAgB,CAAC,CAAC;IAKvB,OAAO,CAAC,QAAQ,CAAC,yBAAyB;IAJ9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;gBAIvC,yBAAyB,EAAE,sBAAsB;IAIhE,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"publisher-factory.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/publisher-factory.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,qBACa,gBAAgB,CAAC,CAAC;IAKvB,OAAO,CAAC,QAAQ,CAAC,yBAAyB;IAJ9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;gBAIvC,yBAAyB,EAAE,sBAAsB;IAIhE,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAyBxG"}
|
|
@@ -28,12 +28,10 @@ let PublisherFactory = PublisherFactory_1 = class PublisherFactory {
|
|
|
28
28
|
let resolvedPublisherName = `${publisherName}${(0, strings_1.classify)(defaultBrokerToUse)}`;
|
|
29
29
|
let actualPublisherToUse = this.solidIntrospectionService.getProvider(resolvedPublisherName);
|
|
30
30
|
if (!actualPublisherToUse) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
31
|
+
actualPublisherToUse = this.solidIntrospectionService.getProvider(publisherName);
|
|
32
|
+
}
|
|
33
|
+
if (!actualPublisherToUse) {
|
|
34
|
+
throw new Error(`Unable to locate publisher with name ${resolvedPublisherName}`);
|
|
37
35
|
}
|
|
38
36
|
const typedActualPublisher = actualPublisherToUse.instance;
|
|
39
37
|
this.logger.debug(`Resolved publisher with name ${actualPublisherToUse.name}, and with options: ${JSON.stringify(typedActualPublisher.options())}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publisher-factory.service.js","sourceRoot":"","sources":["../../../src/services/queues/publisher-factory.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,2CAA4C;AAG5C,oEAAkE;AAClE,0EAAqE;AAI9D,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAGzB,YAEI,yBAAkE;QAAjD,8BAAyB,GAAzB,yBAAyB,CAAwB;QAJrD,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IAM5D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB,EAAE,aAAqB,EAAE,WAAoB;QAC/E,IAAI,kBAAk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AAM,oBAAoB,GAAsB,oBAAoB,CAAC,QAAQ,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,oBAAoB,CAAC,IAAI,uBAAuB,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;QAEpJ,OAAO,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;CACJ,CAAA;AAlCY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAKJ,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,iDAAsB,CAAC,CAAC,CAAA;qCACL,iDAAsB;GAL7D,gBAAgB,CAkC5B","sourcesContent":["import { forwardRef, Inject, Logger } from '@nestjs/common';\nimport { Injectable } from '@nestjs/common';\n\nimport { QueueMessage, QueuePublisher } from 'src/interfaces/mq';\nimport { classify } from '@angular-devkit/core/src/utils/strings';\nimport { SolidIntrospectService } from '../solid-introspect.service';\n\n\n@Injectable()\nexport class PublisherFactory<T> {\n private readonly logger = new Logger(PublisherFactory.name);\n\n constructor(\n @Inject(forwardRef(() => SolidIntrospectService))\n private readonly solidIntrospectionService: SolidIntrospectService\n ) {\n }\n\n async publish(message: QueueMessage<T>, publisherName: string, brokerToUse?: string): Promise<string> {\n let defaultBrokerToUse = brokerToUse || process.env.QUEUES_DEFAULT_BROKER || \"database\";\n let resolvedPublisherName = `${publisherName}${classify(defaultBrokerToUse)}`;\n\n // Register all ISolidDatabaseModules implementations\n let actualPublisherToUse = this.solidIntrospectionService.getProvider(resolvedPublisherName);\n if (!actualPublisherToUse) {\n // Relaxed extra check in place to make sure we do not have to refactor old publishers or publishers named without the ____RabbitMq or ____Database convention\n actualPublisherToUse = this.solidIntrospectionService.getProvider(publisherName);\n\n // Extra check in place to make sure we do not have to refactor old publishers which have been created earlier. \n // if (defaultBrokerToUse === 'rabbitmq') {\n // actualPublisherToUse = this.solidIntrospectionService.getProvider(publisherName);\n // }\n }\n if (!actualPublisherToUse) {\n throw new Error(`Unable to locate publisher with name ${resolvedPublisherName}`);\n }\n\n // type safe\n const typedActualPublisher: QueuePublisher<T> = actualPublisherToUse.instance;\n this.logger.debug(`Resolved publisher with name ${actualPublisherToUse.name}, and with options: ${JSON.stringify(typedActualPublisher.options())}`);\n\n return typedActualPublisher.publish(message);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
1
|
+
import { Logger, OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import * as amqp from 'amqplib';
|
|
3
3
|
import { QueuesModuleOptions } from "../../interfaces";
|
|
4
4
|
import { QueueMessage, QueueSubscriber } from '../../interfaces/mq';
|
|
@@ -7,7 +7,7 @@ import { MqMessageService } from '../mq-message.service';
|
|
|
7
7
|
export declare abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> {
|
|
8
8
|
protected readonly mqMessageService: MqMessageService;
|
|
9
9
|
protected readonly mqMessageQueueService: MqMessageQueueService;
|
|
10
|
-
private
|
|
10
|
+
private _loggerInstance?;
|
|
11
11
|
private readonly url;
|
|
12
12
|
private readonly serviceRole;
|
|
13
13
|
private connection;
|
|
@@ -17,6 +17,8 @@ export declare abstract class RabbitMqSubscriber<T> implements OnModuleInit, Que
|
|
|
17
17
|
private reconnectAttempt;
|
|
18
18
|
private stopping;
|
|
19
19
|
constructor(mqMessageService: MqMessageService, mqMessageQueueService: MqMessageQueueService);
|
|
20
|
+
protected get loggerContext(): string;
|
|
21
|
+
protected get logger(): Logger;
|
|
20
22
|
abstract subscribe(message: QueueMessage<T>): any;
|
|
21
23
|
abstract options(): QueuesModuleOptions;
|
|
22
24
|
establishConnection(): Promise<amqp.Connection>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq-subscriber.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"rabbitmq-subscriber.service.d.ts","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,8BAAsB,kBAAkB,CAAC,CAAC,CAAE,YAAW,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAWvE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IAAE,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IAVlI,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAS;gBAEM,gBAAgB,EAAE,gBAAgB,EAAqB,qBAAqB,EAAE,qBAAqB;IAYlI,SAAS,KAAK,aAAa,IAAI,MAAM,CAEpC;IAED,SAAS,KAAK,MAAM,IAAI,MAAM,CAK7B;IAED,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3C,QAAQ,CAAC,OAAO,IAAI,mBAAmB;IAEjC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;IAsB/C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;YAqCrB,iBAAiB;YA0GjB,qBAAqB;YA8BrB,oBAAoB;IAclC,OAAO,CAAC,gBAAgB;YAWV,aAAa;YAkBb,OAAO;IAkCrB,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,OAAO;cAWC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;YAc9E,sBAAsB;CAkCvC"}
|
|
@@ -41,7 +41,6 @@ class RabbitMqSubscriber {
|
|
|
41
41
|
constructor(mqMessageService, mqMessageQueueService) {
|
|
42
42
|
this.mqMessageService = mqMessageService;
|
|
43
43
|
this.mqMessageQueueService = mqMessageQueueService;
|
|
44
|
-
this.logger = new common_1.Logger(RabbitMqSubscriber.name);
|
|
45
44
|
this.connection = null;
|
|
46
45
|
this.channel = null;
|
|
47
46
|
this.consumerTag = null;
|
|
@@ -57,6 +56,15 @@ class RabbitMqSubscriber {
|
|
|
57
56
|
this.logger.debug('Queue service Role is not defined in the environment variables');
|
|
58
57
|
}
|
|
59
58
|
}
|
|
59
|
+
get loggerContext() {
|
|
60
|
+
return this.constructor.name;
|
|
61
|
+
}
|
|
62
|
+
get logger() {
|
|
63
|
+
if (!this._loggerInstance) {
|
|
64
|
+
this._loggerInstance = new common_1.Logger(this.loggerContext);
|
|
65
|
+
}
|
|
66
|
+
return this._loggerInstance;
|
|
67
|
+
}
|
|
60
68
|
async establishConnection() {
|
|
61
69
|
const url = new URL(this.url);
|
|
62
70
|
const connection = await amqp.connect({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;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AI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBAC9C,aAAa,CAAC,YAAY,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;oBACzC,aAAa,CAAC,eAAe,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;gBAC3G,CAAC;gBACD,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;oBACxB,aAAa,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;gBACrC,CAAC;gBACD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACrB,aAAa,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;gBACnC,CAAC;gBACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;YACzE,CAAC;QACL,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IAEL,CAAC;CAEJ;AA3WD,gDA2WC","sourcesContent":["import { Logger, OnModuleInit } from '@nestjs/common';\nimport * as amqp from 'amqplib';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\n\nexport abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> { // TODO This can be made a generic type for better type visibility\n private readonly logger = new Logger(RabbitMqSubscriber.name);\n private readonly url: string;\n private readonly serviceRole: string;\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private consumerTag: string | null = null;\n private reconnectPromise: Promise<void> | null = null;\n private reconnectAttempt = 0;\n private stopping = false;\n\n constructor(protected readonly mqMessageService: MqMessageService, protected readonly mqMessageQueueService: MqMessageQueueService) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqSubscriber instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n async establishConnection(): Promise<amqp.Connection> {\n\n const url = new URL(this.url);\n\n // this.logger.debug(`user: ${url.username}`);\n // // just for local debug, don’t log in prod\n // this.logger.debug(`pass: ${url.password}`);\n // this.logger.debug(`path (vhost): ${url.pathname}`);\n\n const connection = await amqp.connect({\n protocol: url.protocol.replace(':', ''),\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n heartbeat: 30,\n });\n\n return connection\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of RabbitMqSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n\n // we will start subscriber only if the current service role is subscriber. \n if (this.url && ['both', 'subscriber'].includes(this.serviceRole) && solidCliRunning === \"false\" && defaultBroker === 'rabbitmq') {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`RabbitMqSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n try {\n await this.connectAndConsume(namespacedQueueName);\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${namespacedQueueName}: ${(err as Error).message}`, (err as Error).stack);\n this.triggerReconnect(namespacedQueueName, 'initial connection failure');\n }\n\n this.logger.log(`RabbitMqSubscriber ready to consume messages: ${JSON.stringify(options)} and url: ${this.url}`);\n }\n }\n\n private async connectAndConsume(queueName: string): Promise<void> {\n await this.cleanup();\n this.logger.log(`RabbitMqSubscriber in connectAndConsume for queue: ${queueName} and url: ${this.url}`);\n\n const options = this.options();\n const prefetch = options.prefetch ?? 1;\n if (prefetch < 1) {\n throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);\n }\n\n let connection: amqp.Connection;\n try {\n connection = await this.establishConnection();\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${queueName}: ${(err as Error).message}`, (err as Error).stack);\n throw err;\n }\n\n this.connection = connection;\n\n connection.on('error', (err) => {\n if (connection !== this.connection) return;\n this.logger.error(`RabbitMqSubscriber connection error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n connection.on('close', () => {\n if (connection !== this.connection) return;\n this.logger.warn(`RabbitMqSubscriber connection closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'connection closed');\n });\n\n const channel = await connection.createChannel();\n this.channel = channel;\n\n channel.on('error', (err) => {\n if (channel !== this.channel) return;\n this.logger.error(`RabbitMqSubscriber channel error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n channel.on('close', () => {\n if (channel !== this.channel) return;\n this.logger.warn(`RabbitMqSubscriber channel closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'channel closed');\n });\n\n // Process one message at a time per consumer to avoid parallel work on the same subscriber instance.\n await channel.prefetch(prefetch);\n\n // Use a direct exchange with a stable routing key so retry DLX can route back to the main queue.\n const exchangeName = `${queueName}.exchange`;\n const routingKey = `${queueName}.routing-key`;\n const retryQueue = `${queueName}.retry`;\n const failedQueue = `${queueName}.failed`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n await channel.assertQueue(queueName, {});\n await channel.bindQueue(queueName, exchangeName, routingKey);\n\n // Retry queue uses DLX to route expired messages back to the main exchange/routing key.\n await channel.assertQueue(retryQueue, {\n arguments: {\n 'x-dead-letter-exchange': exchangeName,\n 'x-dead-letter-routing-key': routingKey,\n }\n });\n\n await channel.assertQueue(failedQueue, {});\n\n const consumeResult = await channel.consume(\n queueName,\n async (rawMessage) => {\n if (!rawMessage) {\n return;\n }\n\n let message: QueueMessage<T> = null;\n\n try {\n const messageContentString = rawMessage.content.toString();\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n this.logger.debug(`rabbitmq subscriber received message with id: ${message.messageId} for queue ${queueName}`);\n } catch (error) {\n this.logger.error(`Invalid JSON message on queue ${queueName}: ${(error as Error).message}`);\n await this.publishToFailedQueue(queueName, rawMessage.content, channel, error);\n channel.ack(rawMessage);\n return;\n }\n\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n try {\n await this.processMessage(message, rawMessage, channel);\n } catch (error) {\n await this.handleProcessingError(message, rawMessage, channel, error, queueName);\n }\n },\n // Explicit ack enables reliable processing and retry routing.\n { noAck: false },\n );\n\n this.consumerTag = consumeResult.consumerTag;\n }\n\n // Retry flow: update DB -> increment retry -> send to retry queue with per-message expiration -> ack original.\n private async handleProcessingError(message: QueueMessage<T>, rawMessage: amqp.ConsumeMessage, channel: amqp.Channel, error: any, queueName: string): Promise<void> {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`);\n\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n const retryQueue = `${queueName}.retry`;\n const payload = Buffer.from(JSON.stringify(message));\n\n // Per-message expiration keeps the message in the retry queue until TTL, then DLX routes it back.\n channel.sendToQueue(retryQueue, payload, {\n expiration: String(message.retryInterval || 1000),\n headers: {\n 'x-error': errorMessage,\n }\n });\n\n channel.ack(rawMessage);\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);\n return;\n }\n\n await this.updateStatusInDatabase('failed', message, errorMessage, '');\n channel.ack(rawMessage);\n await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);\n this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);\n }\n\n private async publishToFailedQueue(queueName: string, payload: Buffer | string, channel: amqp.Channel, error?: any): Promise<void> {\n const failedQueue = `${queueName}.failed`;\n const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);\n const errorMessage = (error as Error)?.message || String(error || '');\n\n try {\n channel.sendToQueue(failedQueue, body, errorMessage ? {\n headers: { 'x-error': errorMessage }\n } : undefined);\n } catch (err) {\n this.logger.error(`Failed to publish to failed queue ${failedQueue}: ${(err as Error).message}`);\n }\n }\n\n private triggerReconnect(queueName: string, reason: string) {\n if (this.stopping) return;\n if (this.reconnectPromise) return;\n\n this.reconnectPromise = this.reconnectLoop(queueName, reason)\n .finally(() => {\n this.reconnectPromise = null;\n });\n }\n\n // Reconnect with backoff to avoid hammering the broker during outages.\n private async reconnectLoop(queueName: string, reason: string): Promise<void> {\n this.logger.warn(`RabbitMqSubscriber reconnecting for queue ${queueName}: ${reason}`);\n\n while (!this.stopping) {\n try {\n await this.connectAndConsume(queueName);\n this.reconnectAttempt = 0;\n this.logger.log(`RabbitMqSubscriber reconnected for queue ${queueName}`);\n return;\n } catch (err) {\n this.reconnectAttempt += 1;\n const delay = this.backoff();\n this.logger.warn(`RabbitMqSubscriber reconnect failed for queue ${queueName}; retrying in ${delay}ms`);\n await this.sleep(delay);\n }\n }\n }\n\n private async cleanup(): Promise<void> {\n const channel = this.channel;\n const connection = this.connection;\n const consumerTag = this.consumerTag;\n\n this.channel = null;\n this.connection = null;\n this.consumerTag = null;\n\n if (channel) {\n try {\n if (consumerTag) {\n await channel.cancel(consumerTag);\n }\n } catch (_) {\n // ignore\n }\n\n try {\n await channel.close();\n } catch (_) {\n // ignore\n }\n }\n\n if (connection) {\n try {\n await connection.close();\n } catch (_) {\n // ignore\n }\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n // Exponential backoff with jitter, capped to 30s.\n private backoff(): number {\n const baseMs = 1000;\n const maxMs = 30_000;\n const exp = Math.min(maxMs, baseMs * Math.pow(2, this.reconnectAttempt));\n const jitter = Math.floor(Math.random() * (exp * 0.2));\n return Math.min(maxMs, exp + jitter);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>, rawMessage, channel): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // Ack the message. \n channel.ack(rawMessage);\n\n // Persist success output and timing.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n\n // Update the existing message record by messageId; creation happens upstream.\n try {\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rabbitmq-subscriber.service.js","sourceRoot":"","sources":["../../../src/services/queues/rabbitmq-subscriber.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,8CAAgC;AAKhC,qCAAoD;AAGpD,MAAsB,kBAAkB;IAWpC,YAA+B,gBAAkC,EAAqB,qBAA4C;QAAnG,qBAAgB,GAAhB,gBAAgB,CAAkB;QAAqB,0BAAqB,GAArB,qBAAqB,CAAuB;QAP1H,eAAU,GAA2B,IAAI,CAAC;QAC1C,YAAO,GAAwB,IAAI,CAAC;QACpC,gBAAW,GAAkB,IAAI,CAAC;QAClC,qBAAgB,GAAyB,IAAI,CAAC;QAC9C,qBAAgB,GAAG,CAAC,CAAC;QACrB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACxF,CAAC;IAEL,CAAC;IAED,IAAc,aAAa;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACjC,CAAC;IAED,IAAc,MAAM;QAChB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QA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/common';\nimport * as amqp from 'amqplib';\nimport { QueuesModuleOptions } from \"../../interfaces\";\nimport { QueueMessage, QueueSubscriber } from '../../interfaces/mq';\nimport { MqMessageQueueService } from '../mq-message-queue.service';\nimport { MqMessageService } from '../mq-message.service';\nimport { buildNamespacedQueueName } from './common';\n\n\nexport abstract class RabbitMqSubscriber<T> implements OnModuleInit, QueueSubscriber<T> { // TODO This can be made a generic type for better type visibility\n private _loggerInstance?: Logger;\n private readonly url: string;\n private readonly serviceRole: string;\n private connection: amqp.Connection | null = null;\n private channel: amqp.Channel | null = null;\n private consumerTag: string | null = null;\n private reconnectPromise: Promise<void> | null = null;\n private reconnectAttempt = 0;\n private stopping = false;\n\n constructor(protected readonly mqMessageService: MqMessageService, protected readonly mqMessageQueueService: MqMessageQueueService) {\n this.url = process.env.QUEUES_RABBIT_MQ_URL;\n this.serviceRole = process.env.QUEUES_SERVICE_ROLE;\n if (!this.url) {\n this.logger.debug('RabbitMqPublisher url is not defined in the environment variables');\n }\n if (!this.serviceRole) {\n this.logger.debug('Queue service Role is not defined in the environment variables');\n }\n // this.logger.debug(`RabbitMqSubscriber instance created with options: ${JSON.stringify(this.options())} and url: ${this.url}`);\n }\n\n protected get loggerContext(): string {\n return this.constructor.name;\n }\n\n protected get logger(): Logger {\n if (!this._loggerInstance) {\n this._loggerInstance = new Logger(this.loggerContext);\n }\n return this._loggerInstance;\n }\n\n abstract subscribe(message: QueueMessage<T>);\n\n abstract options(): QueuesModuleOptions;\n\n async establishConnection(): Promise<amqp.Connection> {\n\n const url = new URL(this.url);\n\n // this.logger.debug(`user: ${url.username}`);\n // // just for local debug, don’t log in prod\n // this.logger.debug(`pass: ${url.password}`);\n // this.logger.debug(`path (vhost): ${url.pathname}`);\n\n const connection = await amqp.connect({\n protocol: url.protocol.replace(':', ''),\n hostname: url.hostname,\n port: parseInt(url.port),\n username: url.username,\n password: decodeURIComponent(url.password),\n frameMax: 131072,\n heartbeat: 30,\n });\n\n return connection\n }\n\n async onModuleInit(): Promise<void> {\n // Not using SettingService here as that will necessitate all implementors of RabbitMqSubscriber to also inject SettingService which is not ideal. \n // Instead we directly read the environment variables here.\n const defaultBroker = process.env.QUEUES_DEFAULT_BROKER || 'rabbitmq';\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n const queueNameRegex = (process.env.QUEUES_QUEUE_NAME_REGEX_TO_ENABLE || '').trim();\n\n // we will start subscriber only if the current service role is subscriber. \n if (this.url && ['both', 'subscriber'].includes(this.serviceRole) && solidCliRunning === \"false\" && defaultBroker === 'rabbitmq') {\n const options = this.options();\n const queueName = options.queueName;\n\n if (queueNameRegex && queueNameRegex !== \"all\") {\n try {\n const regex = new RegExp(queueNameRegex);\n if (!regex.test(queueName)) {\n this.logger.log(`RabbitMqSubscriber for queue ${queueName} is disabled because it does not match QUEUES_QUEUE_NAME_REGEX_TO_ENABLE=${queueNameRegex}`);\n return;\n }\n } catch (error) {\n this.logger.error(`Invalid QUEUES_QUEUE_NAME_REGEX_TO_ENABLE regex \"${queueNameRegex}\". Subscriber for queue ${queueName} will not start.`);\n return;\n }\n }\n\n const namespacedQueueName = buildNamespacedQueueName(queueName);\n try {\n await this.connectAndConsume(namespacedQueueName);\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${namespacedQueueName}: ${(err as Error).message}`, (err as Error).stack);\n this.triggerReconnect(namespacedQueueName, 'initial connection failure');\n }\n\n this.logger.log(`RabbitMqSubscriber ready to consume messages: ${JSON.stringify(options)} and url: ${this.url}`);\n }\n }\n\n private async connectAndConsume(queueName: string): Promise<void> {\n await this.cleanup();\n this.logger.log(`RabbitMqSubscriber in connectAndConsume for queue: ${queueName} and url: ${this.url}`);\n\n const options = this.options();\n const prefetch = options.prefetch ?? 1;\n if (prefetch < 1) {\n throw new Error(`RabbitMqSubscriber prefetch must be >= 1 for queue ${queueName}`);\n }\n\n let connection: amqp.Connection;\n try {\n connection = await this.establishConnection();\n } catch (err) {\n this.logger.error(`Failed to connect to RabbitMQ for queue ${queueName}: ${(err as Error).message}`, (err as Error).stack);\n throw err;\n }\n\n this.connection = connection;\n\n connection.on('error', (err) => {\n if (connection !== this.connection) return;\n this.logger.error(`RabbitMqSubscriber connection error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n connection.on('close', () => {\n if (connection !== this.connection) return;\n this.logger.warn(`RabbitMqSubscriber connection closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'connection closed');\n });\n\n const channel = await connection.createChannel();\n this.channel = channel;\n\n channel.on('error', (err) => {\n if (channel !== this.channel) return;\n this.logger.error(`RabbitMqSubscriber channel error for queue ${queueName}: ${(err as Error).message}`);\n });\n\n channel.on('close', () => {\n if (channel !== this.channel) return;\n this.logger.warn(`RabbitMqSubscriber channel closed for queue ${queueName}`);\n this.triggerReconnect(queueName, 'channel closed');\n });\n\n // Process one message at a time per consumer to avoid parallel work on the same subscriber instance.\n await channel.prefetch(prefetch);\n\n // Use a direct exchange with a stable routing key so retry DLX can route back to the main queue.\n const exchangeName = `${queueName}.exchange`;\n const routingKey = `${queueName}.routing-key`;\n const retryQueue = `${queueName}.retry`;\n const failedQueue = `${queueName}.failed`;\n\n await channel.assertExchange(exchangeName, 'direct', {});\n await channel.assertQueue(queueName, {});\n await channel.bindQueue(queueName, exchangeName, routingKey);\n\n // Retry queue uses DLX to route expired messages back to the main exchange/routing key.\n await channel.assertQueue(retryQueue, {\n arguments: {\n 'x-dead-letter-exchange': exchangeName,\n 'x-dead-letter-routing-key': routingKey,\n }\n });\n\n await channel.assertQueue(failedQueue, {});\n\n const consumeResult = await channel.consume(\n queueName,\n async (rawMessage) => {\n if (!rawMessage) {\n return;\n }\n\n let message: QueueMessage<T> = null;\n\n try {\n const messageContentString = rawMessage.content.toString();\n message = JSON.parse(messageContentString) as QueueMessage<T>;\n this.logger.debug(`rabbitmq subscriber received message with id: ${message.messageId} for queue ${queueName}`);\n } catch (error) {\n this.logger.error(`Invalid JSON message on queue ${queueName}: ${(error as Error).message}`);\n await this.publishToFailedQueue(queueName, rawMessage.content, channel, error);\n channel.ack(rawMessage);\n return;\n }\n\n if (!message.retryCount) message.retryCount = 0;\n if (!message.retryInterval) message.retryInterval = 1000;\n if (!message.currentRetry) message.currentRetry = 0;\n\n try {\n await this.processMessage(message, rawMessage, channel);\n } catch (error) {\n await this.handleProcessingError(message, rawMessage, channel, error, queueName);\n }\n },\n // Explicit ack enables reliable processing and retry routing.\n { noAck: false },\n );\n\n this.consumerTag = consumeResult.consumerTag;\n }\n\n // Retry flow: update DB -> increment retry -> send to retry queue with per-message expiration -> ack original.\n private async handleProcessingError(message: QueueMessage<T>, rawMessage: amqp.ConsumeMessage, channel: amqp.Channel, error: any, queueName: string): Promise<void> {\n const errorMessage = (error as Error)?.message || String(error);\n this.logger.error(`Error processing message on queue ${queueName}: ${errorMessage}`);\n\n if (message.currentRetry < message.retryCount) {\n await this.updateStatusInDatabase('retrying', message);\n\n message.currentRetry++;\n const retryQueue = `${queueName}.retry`;\n const payload = Buffer.from(JSON.stringify(message));\n\n // Per-message expiration keeps the message in the retry queue until TTL, then DLX routes it back.\n channel.sendToQueue(retryQueue, payload, {\n expiration: String(message.retryInterval || 1000),\n headers: {\n 'x-error': errorMessage,\n }\n });\n\n channel.ack(rawMessage);\n this.logger.warn(`Retrying message (${message.currentRetry}/${message.retryCount}) after ${message.retryInterval}ms on queue ${queueName}`);\n return;\n }\n\n await this.updateStatusInDatabase('failed', message, errorMessage, '');\n channel.ack(rawMessage);\n await this.publishToFailedQueue(queueName, Buffer.from(JSON.stringify(message)), channel, error);\n this.logger.error(`Message failed after ${message.retryCount} attempts on queue ${queueName}: ${errorMessage}`);\n }\n\n private async publishToFailedQueue(queueName: string, payload: Buffer | string, channel: amqp.Channel, error?: any): Promise<void> {\n const failedQueue = `${queueName}.failed`;\n const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);\n const errorMessage = (error as Error)?.message || String(error || '');\n\n try {\n channel.sendToQueue(failedQueue, body, errorMessage ? {\n headers: { 'x-error': errorMessage }\n } : undefined);\n } catch (err) {\n this.logger.error(`Failed to publish to failed queue ${failedQueue}: ${(err as Error).message}`);\n }\n }\n\n private triggerReconnect(queueName: string, reason: string) {\n if (this.stopping) return;\n if (this.reconnectPromise) return;\n\n this.reconnectPromise = this.reconnectLoop(queueName, reason)\n .finally(() => {\n this.reconnectPromise = null;\n });\n }\n\n // Reconnect with backoff to avoid hammering the broker during outages.\n private async reconnectLoop(queueName: string, reason: string): Promise<void> {\n this.logger.warn(`RabbitMqSubscriber reconnecting for queue ${queueName}: ${reason}`);\n\n while (!this.stopping) {\n try {\n await this.connectAndConsume(queueName);\n this.reconnectAttempt = 0;\n this.logger.log(`RabbitMqSubscriber reconnected for queue ${queueName}`);\n return;\n } catch (err) {\n this.reconnectAttempt += 1;\n const delay = this.backoff();\n this.logger.warn(`RabbitMqSubscriber reconnect failed for queue ${queueName}; retrying in ${delay}ms`);\n await this.sleep(delay);\n }\n }\n }\n\n private async cleanup(): Promise<void> {\n const channel = this.channel;\n const connection = this.connection;\n const consumerTag = this.consumerTag;\n\n this.channel = null;\n this.connection = null;\n this.consumerTag = null;\n\n if (channel) {\n try {\n if (consumerTag) {\n await channel.cancel(consumerTag);\n }\n } catch (_) {\n // ignore\n }\n\n try {\n await channel.close();\n } catch (_) {\n // ignore\n }\n }\n\n if (connection) {\n try {\n await connection.close();\n } catch (_) {\n // ignore\n }\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n\n // Exponential backoff with jitter, capped to 30s.\n private backoff(): number {\n const baseMs = 1000;\n const maxMs = 30_000;\n const exp = Math.min(maxMs, baseMs * Math.pow(2, this.reconnectAttempt));\n const jitter = Math.floor(Math.random() * (exp * 0.2));\n return Math.min(maxMs, exp + jitter);\n }\n\n /**\n * Abstract method for message processing logic.\n */\n protected async processMessage(message: QueueMessage<T>, rawMessage, channel): Promise<void> {\n await this.updateStatusInDatabase('started', message);\n\n // Capture the results of handling the task.\n const result = await this.subscribe(message);\n\n // Ack the message. \n channel.ack(rawMessage);\n\n // Persist success output and timing.\n await this.updateStatusInDatabase('succeeded', message, '', result ? JSON.stringify(result, null, 2) : '');\n\n }\n\n private async updateStatusInDatabase(stage: string, message: QueueMessage<T>, error: string = '', result: string = '') {\n\n // Update the existing message record by messageId; creation happens upstream.\n try {\n // 1. resolve the queue first\n const mqMessage = await this.mqMessageService.repo.findOne({\n where: {\n messageId: message.messageId,\n }\n });\n\n if (mqMessage) {\n const updatedFields = {\n stage: stage\n };\n if (stage === 'failed' || stage === 'succeeded') {\n updatedFields['finishedAt'] = new Date();\n updatedFields['elapsedMillis'] = updatedFields['finishedAt'].getTime() - mqMessage.startedAt.getTime();\n }\n if (stage === 'succeeded') {\n updatedFields['output'] = result;\n }\n if (stage === 'failed') {\n updatedFields['error'] = error;\n }\n await this.mqMessageService.repo.update(mqMessage.id, updatedFields);\n }\n }\n catch (error) {\n this.logger.error(error.message, error.stack);\n }\n\n }\n\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-of-dashboard-question-providers-selection-provider.service.d.ts","sourceRoot":"","sources":["../../../src/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAuE,kBAAkB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"list-of-dashboard-question-providers-selection-provider.service.d.ts","sourceRoot":"","sources":["../../../src/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAuE,kBAAkB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAKhL,qBAEa,iDAAkD,YAAW,kBAAkB,CAAC,yBAAyB,CAAC;IAG/G,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAIjD,IAAI,IAAI,MAAM;IAId,IAAI,IAAI,MAAM;IAIR,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,GAAG,GAAG,CAAC;IASpG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,SAAS,wBAAwB,EAAE,CAAC;CAS7G"}
|
|
@@ -13,6 +13,7 @@ exports.ListOfDashboardQuestionProvidersSelectionProvider = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const selection_provider_decorator_1 = require("../../decorators/selection-provider.decorator");
|
|
15
15
|
const solid_registry_1 = require("../../helpers/solid-registry");
|
|
16
|
+
const dashboard_question_service_1 = require("../dashboard-question.service");
|
|
16
17
|
let ListOfDashboardQuestionProvidersSelectionProvider = class ListOfDashboardQuestionProvidersSelectionProvider {
|
|
17
18
|
constructor(solidRegistry) {
|
|
18
19
|
this.solidRegistry = solidRegistry;
|
|
@@ -32,7 +33,9 @@ let ListOfDashboardQuestionProvidersSelectionProvider = class ListOfDashboardQue
|
|
|
32
33
|
}
|
|
33
34
|
async values(query, ctxt) {
|
|
34
35
|
const dashboardSelectionProviders = this.solidRegistry.getDashboardQuestionDataProviders();
|
|
35
|
-
return dashboardSelectionProviders
|
|
36
|
+
return dashboardSelectionProviders
|
|
37
|
+
.filter(provider => !dashboard_question_service_1.INBUILT_SQL_DATA_PROVIDERS.includes(provider.name()))
|
|
38
|
+
.map(i => {
|
|
36
39
|
return { label: i.name, value: i.name };
|
|
37
40
|
});
|
|
38
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-of-dashboard-question-providers-selection-provider.service.js","sourceRoot":"","sources":["../../../src/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,gGAAgF;AAChF,iEAA2D;
|
|
1
|
+
{"version":3,"file":"list-of-dashboard-question-providers-selection-provider.service.js","sourceRoot":"","sources":["../../../src/services/selection-providers/list-of-dashboard-question-providers-selection-provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,gGAAgF;AAChF,iEAA2D;AAG3D,8EAAyM;AAKlM,IAAM,iDAAiD,GAAvD,MAAM,iDAAiD;IAE1D,YACqB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAEjD,CAAC;IAED,IAAI;QACA,OAAO,mGAAmG,CAAC;IAC/G,CAAC;IAED,IAAI;QACA,OAAO,mDAAmD,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,WAAmB,EAAE,IAA+B;QAC5D,MAAM,0BAA0B,GAAyD,IAAI,CAAC,aAAa,CAAC,wCAAwC,CAAC,WAAW,CAAC,CAAC;QAClK,IAAI,CAAC,0BAA0B,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,0BAA0B,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,0BAA0B,CAAC,IAAI,EAAE,EAAE,CAAC;IAClG,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,IAA+B;QACvD,MAAM,2BAA2B,GAAG,IAAI,CAAC,aAAa,CAAC,iCAAiC,EAAE,CAAA;QAE1F,OAAO,2BAA2B;aACjC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,uDAA0B,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;aACzE,GAAG,CAAC,CAAC,CAAC,EAAE;YACL,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AAjCY,8GAAiD;4DAAjD,iDAAiD;IAF7D,IAAA,gDAAiB,GAAE;IACnB,IAAA,mBAAU,GAAE;qCAI2B,8BAAa;GAHxC,iDAAiD,CAiC7D","sourcesContent":["import { Injectable } from \"@nestjs/common\";\nimport { SelectionProvider } from \"src/decorators/selection-provider.decorator\";\nimport { SolidRegistry } from \"src/helpers/solid-registry\";\nimport { IDashboardQuestionDataProvider, IDashboardVariableSelectionProvider, ISelectionProvider, ISelectionProviderContext, ISelectionProviderValues } from \"../../interfaces\";\nimport { SQL_DYNAMIC_PROVIDER_NAME } from \"../dashboard.service\";\nimport { CHARTJS_SQL_DATA_PROVIDER_NAME, INBUILT_SQL_DATA_PROVIDERS, PRIME_REACT_DATATABLE_SQL_DATA_PROVIDER_NAME, PRIME_REACT_METER_GROUP_SQL_DATA_PROVIDER_NAME } from \"../dashboard-question.service\";\n\n\n@SelectionProvider()\n@Injectable()\nexport class ListOfDashboardQuestionProvidersSelectionProvider implements ISelectionProvider<ISelectionProviderContext> {\n\n constructor(\n private readonly solidRegistry: SolidRegistry,\n ) {\n }\n\n help(): string {\n return \"# Allows one to dynamically fetch all the dashboard providers that are registered in the system. \";\n }\n\n name(): string {\n return 'ListOfDashboardQuestionProvidersSelectionProvider';\n }\n\n async value(optionValue: string, ctxt: ISelectionProviderContext): Promise<ISelectionProviderValues | any> {\n const dashboardSelectionProvider: IDashboardQuestionDataProvider<any, any> | undefined = this.solidRegistry.getDashboardQuestionDataProviderInstance(optionValue);\n if (!dashboardSelectionProvider) {\n return null;\n }\n\n return { label: dashboardSelectionProvider.name(), value: dashboardSelectionProvider.name() };\n }\n\n async values(query: string, ctxt: ISelectionProviderContext): Promise<readonly ISelectionProviderValues[]> {\n const dashboardSelectionProviders = this.solidRegistry.getDashboardQuestionDataProviders()\n //Exclude the SQL dynamic provider from the list, (since although it is a dashboard selection provider, it is not a valid option for the user to select)\n return dashboardSelectionProviders\n .filter(provider => !INBUILT_SQL_DATA_PROVIDERS.includes(provider.name())) \n .map(i => {\n return { label: i.name, value: i.name };\n });\n }\n}"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
1
2
|
import { ValueTransformer } from "typeorm";
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare const UtcDateTimeTransformer: ValueTransformer;
|
|
3
|
+
export declare function parseDate(date: Date): dayjs.Dayjs;
|
|
4
|
+
export declare function serializeDate(date: Date): string;
|
|
5
|
+
export declare const LocalDateTimeTransformer: ValueTransformer;
|
|
6
6
|
//# sourceMappingURL=local-date-time-transformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-date-time-transformer.d.ts","sourceRoot":"","sources":["../../../src/transformers/typeorm/local-date-time-transformer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"local-date-time-transformer.d.ts","sourceRoot":"","sources":["../../../src/transformers/typeorm/local-date-time-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmC3C,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC,KAAK,CAIjD;AAQD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAIhD;AAED,eAAO,MAAM,wBAAwB,EAAE,gBA2BtC,CAAC"}
|