@n8n/backend-module-insights 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +88 -0
- package/dist/build.tsbuildinfo +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/insights-by-period-query.helper.d.ts +15 -0
- package/dist/insights-by-period-query.helper.js +45 -0
- package/dist/insights-by-period-query.helper.js.map +1 -0
- package/dist/insights-by-period.entity.d.ts +17 -0
- package/dist/insights-by-period.entity.js +73 -0
- package/dist/insights-by-period.entity.js.map +1 -0
- package/dist/insights-by-period.repository.d.ts +100 -0
- package/dist/insights-by-period.repository.js +347 -0
- package/dist/insights-by-period.repository.js.map +1 -0
- package/dist/insights-collection.service.d.ts +30 -0
- package/dist/insights-collection.service.js +280 -0
- package/dist/insights-collection.service.js.map +1 -0
- package/dist/insights-compaction.service.d.ts +19 -0
- package/dist/insights-compaction.service.js +161 -0
- package/dist/insights-compaction.service.js.map +1 -0
- package/dist/insights-compaction.task.d.ts +14 -0
- package/dist/insights-compaction.task.js +35 -0
- package/dist/insights-compaction.task.js.map +1 -0
- package/dist/insights-metadata.entity.d.ts +8 -0
- package/dist/insights-metadata.entity.js +40 -0
- package/dist/insights-metadata.entity.js.map +1 -0
- package/dist/insights-metadata.repository.d.ts +7 -0
- package/dist/insights-metadata.repository.js +36 -0
- package/dist/insights-metadata.repository.js.map +1 -0
- package/dist/insights-pruning.service.d.ts +11 -0
- package/dist/insights-pruning.service.js +49 -0
- package/dist/insights-pruning.service.js.map +1 -0
- package/dist/insights-pruning.task.d.ts +15 -0
- package/dist/insights-pruning.task.js +36 -0
- package/dist/insights-pruning.task.js.map +1 -0
- package/dist/insights-raw.entity.d.ts +13 -0
- package/dist/insights-raw.entity.js +61 -0
- package/dist/insights-raw.entity.js.map +1 -0
- package/dist/insights-raw.repository.d.ts +12 -0
- package/dist/insights-raw.repository.js +36 -0
- package/dist/insights-raw.repository.js.map +1 -0
- package/dist/insights-shared.d.ts +21 -0
- package/dist/insights-shared.js +30 -0
- package/dist/insights-shared.js.map +1 -0
- package/dist/insights.config.d.ts +13 -0
- package/dist/insights.config.js +80 -0
- package/dist/insights.config.js.map +1 -0
- package/dist/insights.constants.d.ts +4 -0
- package/dist/insights.constants.js +24 -0
- package/dist/insights.constants.js.map +1 -0
- package/dist/insights.controller.d.ts +16 -0
- package/dist/insights.controller.js +159 -0
- package/dist/insights.controller.js.map +1 -0
- package/dist/insights.module.d.ts +17 -0
- package/dist/insights.module.js +51 -0
- package/dist/insights.module.js.map +1 -0
- package/dist/insights.service.d.ts +73 -0
- package/dist/insights.service.js +257 -0
- package/dist/insights.service.js.map +1 -0
- package/dist/insights.settings.d.ts +20 -0
- package/dist/insights.settings.js +48 -0
- package/dist/insights.settings.js.map +1 -0
- package/dist/testing/db-utils.d.ts +22 -0
- package/dist/testing/db-utils.js +76 -0
- package/dist/testing/db-utils.js.map +1 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +9 -0
- package/dist/testing.js.map +1 -0
- package/package.json +97 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { InsightsConfig } from './insights.config';
|
|
2
|
+
export { InsightsService } from './insights.service';
|
|
3
|
+
export { InsightsCollectionService } from './insights-collection.service';
|
|
4
|
+
export { InsightsCompactionService } from './insights-compaction.service';
|
|
5
|
+
export { InsightsPruningService } from './insights-pruning.service';
|
|
6
|
+
export { InsightsByPeriod } from './insights-by-period.entity';
|
|
7
|
+
export { InsightsMetadata } from './insights-metadata.entity';
|
|
8
|
+
export { InsightsRaw } from './insights-raw.entity';
|
|
9
|
+
export type { ByTimeInsightType, PeriodUnit, TypeUnit, } from './insights-shared';
|
|
10
|
+
export { TypeToNumber } from './insights-shared';
|
|
11
|
+
export type { InsightsAccessFilter } from './insights-by-period.repository';
|
|
12
|
+
export { InsightsByPeriodRepository } from './insights-by-period.repository';
|
|
13
|
+
export { InsightsMetadataRepository } from './insights-metadata.repository';
|
|
14
|
+
export { InsightsRawRepository } from './insights-raw.repository';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InsightsRawRepository = exports.InsightsMetadataRepository = exports.InsightsByPeriodRepository = exports.TypeToNumber = exports.InsightsRaw = exports.InsightsMetadata = exports.InsightsByPeriod = exports.InsightsPruningService = exports.InsightsCompactionService = exports.InsightsCollectionService = exports.InsightsService = exports.InsightsConfig = void 0;
|
|
4
|
+
var insights_config_1 = require("./insights.config");
|
|
5
|
+
Object.defineProperty(exports, "InsightsConfig", { enumerable: true, get: function () { return insights_config_1.InsightsConfig; } });
|
|
6
|
+
var insights_service_1 = require("./insights.service");
|
|
7
|
+
Object.defineProperty(exports, "InsightsService", { enumerable: true, get: function () { return insights_service_1.InsightsService; } });
|
|
8
|
+
var insights_collection_service_1 = require("./insights-collection.service");
|
|
9
|
+
Object.defineProperty(exports, "InsightsCollectionService", { enumerable: true, get: function () { return insights_collection_service_1.InsightsCollectionService; } });
|
|
10
|
+
var insights_compaction_service_1 = require("./insights-compaction.service");
|
|
11
|
+
Object.defineProperty(exports, "InsightsCompactionService", { enumerable: true, get: function () { return insights_compaction_service_1.InsightsCompactionService; } });
|
|
12
|
+
var insights_pruning_service_1 = require("./insights-pruning.service");
|
|
13
|
+
Object.defineProperty(exports, "InsightsPruningService", { enumerable: true, get: function () { return insights_pruning_service_1.InsightsPruningService; } });
|
|
14
|
+
var insights_by_period_entity_1 = require("./insights-by-period.entity");
|
|
15
|
+
Object.defineProperty(exports, "InsightsByPeriod", { enumerable: true, get: function () { return insights_by_period_entity_1.InsightsByPeriod; } });
|
|
16
|
+
var insights_metadata_entity_1 = require("./insights-metadata.entity");
|
|
17
|
+
Object.defineProperty(exports, "InsightsMetadata", { enumerable: true, get: function () { return insights_metadata_entity_1.InsightsMetadata; } });
|
|
18
|
+
var insights_raw_entity_1 = require("./insights-raw.entity");
|
|
19
|
+
Object.defineProperty(exports, "InsightsRaw", { enumerable: true, get: function () { return insights_raw_entity_1.InsightsRaw; } });
|
|
20
|
+
var insights_shared_1 = require("./insights-shared");
|
|
21
|
+
Object.defineProperty(exports, "TypeToNumber", { enumerable: true, get: function () { return insights_shared_1.TypeToNumber; } });
|
|
22
|
+
var insights_by_period_repository_1 = require("./insights-by-period.repository");
|
|
23
|
+
Object.defineProperty(exports, "InsightsByPeriodRepository", { enumerable: true, get: function () { return insights_by_period_repository_1.InsightsByPeriodRepository; } });
|
|
24
|
+
var insights_metadata_repository_1 = require("./insights-metadata.repository");
|
|
25
|
+
Object.defineProperty(exports, "InsightsMetadataRepository", { enumerable: true, get: function () { return insights_metadata_repository_1.InsightsMetadataRepository; } });
|
|
26
|
+
var insights_raw_repository_1 = require("./insights-raw.repository");
|
|
27
|
+
Object.defineProperty(exports, "InsightsRawRepository", { enumerable: true, get: function () { return insights_raw_repository_1.InsightsRawRepository; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,6EAA0E;AAAjE,wIAAA,yBAAyB,OAAA;AAClC,6EAA0E;AAAjE,wIAAA,yBAAyB,OAAA;AAClC,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,yEAA+D;AAAtD,6HAAA,gBAAgB,OAAA;AACzB,uEAA8D;AAArD,4HAAA,gBAAgB,OAAA;AACzB,6DAAoD;AAA3C,kHAAA,WAAW,OAAA;AAMpB,qDAAiD;AAAxC,+GAAA,YAAY,OAAA;AAErB,iFAA6E;AAApE,2IAAA,0BAA0B,OAAA;AACnC,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DatabaseConfig } from '@n8n/config';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
export declare const getDateRangesCommonTableExpressionQuery: ({ startDate, endDate, dbType, timeZone, now, }: {
|
|
4
|
+
startDate: Date;
|
|
5
|
+
endDate: Date;
|
|
6
|
+
dbType: DatabaseConfig['type'];
|
|
7
|
+
timeZone?: string;
|
|
8
|
+
now?: DateTime;
|
|
9
|
+
}) => string;
|
|
10
|
+
export declare function getDateRangesSelectQuery({ dbType, prevStartDateTime, startDateTime, endDateTime, }: {
|
|
11
|
+
dbType: DatabaseConfig['type'];
|
|
12
|
+
prevStartDateTime: DateTime;
|
|
13
|
+
startDateTime: DateTime;
|
|
14
|
+
endDateTime: DateTime;
|
|
15
|
+
}): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDateRangesCommonTableExpressionQuery = void 0;
|
|
4
|
+
exports.getDateRangesSelectQuery = getDateRangesSelectQuery;
|
|
5
|
+
const db_1 = require("@n8n/db");
|
|
6
|
+
const luxon_1 = require("luxon");
|
|
7
|
+
const getDateRangesCommonTableExpressionQuery = ({ startDate, endDate, dbType, timeZone = 'utc', now = luxon_1.DateTime.now(), }) => {
|
|
8
|
+
let startDateTime = luxon_1.DateTime.fromJSDate(startDate).setZone(timeZone);
|
|
9
|
+
let endDateTime = luxon_1.DateTime.fromJSDate(endDate).setZone(timeZone);
|
|
10
|
+
const nowInZone = now.setZone(timeZone);
|
|
11
|
+
const isEndDateToday = endDateTime.hasSame(nowInZone, 'day');
|
|
12
|
+
if (!isEndDateToday) {
|
|
13
|
+
startDateTime = startDateTime.startOf('day');
|
|
14
|
+
endDateTime = endDateTime.plus({ days: 1 }).startOf('day');
|
|
15
|
+
}
|
|
16
|
+
if (isEndDateToday && startDateTime.hasSame(endDateTime, 'day')) {
|
|
17
|
+
startDateTime = startDateTime.startOf('day');
|
|
18
|
+
}
|
|
19
|
+
const prevStartDateTime = startDateTime.minus(endDateTime.diff(startDateTime));
|
|
20
|
+
return getDateRangesSelectQuery({
|
|
21
|
+
dbType,
|
|
22
|
+
prevStartDateTime: prevStartDateTime.toUTC(),
|
|
23
|
+
startDateTime: startDateTime.toUTC(),
|
|
24
|
+
endDateTime: endDateTime.toUTC(),
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.getDateRangesCommonTableExpressionQuery = getDateRangesCommonTableExpressionQuery;
|
|
28
|
+
function getDateRangesSelectQuery({ dbType, prevStartDateTime, startDateTime, endDateTime, }) {
|
|
29
|
+
const prevStartStr = prevStartDateTime.toSQL({ includeZone: false, includeOffset: false });
|
|
30
|
+
const startStr = startDateTime.toSQL({ includeZone: false, includeOffset: false });
|
|
31
|
+
const endStr = endDateTime.toSQL({ includeZone: false, includeOffset: false });
|
|
32
|
+
if (dbType === 'postgresdb') {
|
|
33
|
+
return (0, db_1.sql) `SELECT
|
|
34
|
+
CAST('${prevStartStr}' AS TIMESTAMP) AS prev_start_date,
|
|
35
|
+
CAST('${startStr}' AS TIMESTAMP) AS start_date,
|
|
36
|
+
CAST('${endStr}' AS TIMESTAMP) AS end_date
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
return (0, db_1.sql) `SELECT
|
|
40
|
+
'${prevStartStr}' AS prev_start_date,
|
|
41
|
+
'${startStr}' AS start_date,
|
|
42
|
+
'${endStr}' AS end_date
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=insights-by-period-query.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insights-by-period-query.helper.js","sourceRoot":"","sources":["../src/insights-by-period-query.helper.ts"],"names":[],"mappings":";;;;AACA,gCAA8B;AAC9B,iCAAiC;AAqB1B,MAAM,uCAAuC,GAAG,CAAC,EACvD,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GAAG,KAAK,EAChB,GAAG,GAAG,gBAAQ,CAAC,GAAG,EAAE,GAOpB,EAAE,EAAE;IACJ,IAAI,aAAa,GAAG,gBAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrE,IAAI,WAAW,GAAG,gBAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjE,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAExC,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAG7D,IAAI,CAAC,cAAc,EAAE,CAAC;QACrB,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7C,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAGD,IAAI,cAAc,IAAI,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;QACjE,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,iBAAiB,GAAG,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAG/E,OAAO,wBAAwB,CAAC;QAC/B,MAAM;QACN,iBAAiB,EAAE,iBAAiB,CAAC,KAAK,EAAE;QAC5C,aAAa,EAAE,aAAa,CAAC,KAAK,EAAE;QACpC,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE;KAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AAvCW,QAAA,uCAAuC,GAAvC,uCAAuC,CAuClD;AAEF,kCAAyC,EACxC,MAAM,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,GAMX;IACA,MAAM,YAAY,GAAG,iBAAiB,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3F,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;IACnF,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;IAK/E,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;QAC7B,OAAO,IAAA,QAAG,EAAA;WACD,YAAY;WACZ,QAAQ;WACR,MAAM;GACd,CAAC;IACH,CAAC;IAED,OAAO,IAAA,QAAG,EAAA;MACL,YAAY;MACZ,QAAQ;MACR,MAAM;EACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseEntity } from '@n8n/typeorm';
|
|
2
|
+
import { InsightsMetadata } from './insights-metadata.entity';
|
|
3
|
+
import type { PeriodUnit } from './insights-shared';
|
|
4
|
+
import { TypeToNumber } from './insights-shared';
|
|
5
|
+
export declare class InsightsByPeriod extends BaseEntity {
|
|
6
|
+
id: number;
|
|
7
|
+
metaId: number;
|
|
8
|
+
metadata: InsightsMetadata;
|
|
9
|
+
private type_;
|
|
10
|
+
get type(): keyof typeof TypeToNumber;
|
|
11
|
+
set type(value: keyof typeof TypeToNumber);
|
|
12
|
+
value: number;
|
|
13
|
+
private periodUnit_;
|
|
14
|
+
get periodUnit(): PeriodUnit;
|
|
15
|
+
set periodUnit(value: PeriodUnit);
|
|
16
|
+
periodStart: Date;
|
|
17
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.InsightsByPeriod = void 0;
|
|
13
|
+
const db_1 = require("@n8n/db");
|
|
14
|
+
const typeorm_1 = require("@n8n/typeorm");
|
|
15
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
16
|
+
const insights_metadata_entity_1 = require("./insights-metadata.entity");
|
|
17
|
+
const insights_shared_1 = require("./insights-shared");
|
|
18
|
+
let InsightsByPeriod = class InsightsByPeriod extends typeorm_1.BaseEntity {
|
|
19
|
+
get type() {
|
|
20
|
+
const typeValue = this.type_;
|
|
21
|
+
if (!(0, insights_shared_1.isValidTypeNumber)(typeValue)) {
|
|
22
|
+
throw new n8n_workflow_1.UnexpectedError(`Type '${typeValue}' is not a valid type for 'InsightsByPeriod.type'`);
|
|
23
|
+
}
|
|
24
|
+
return insights_shared_1.NumberToType[typeValue];
|
|
25
|
+
}
|
|
26
|
+
set type(value) {
|
|
27
|
+
this.type_ = insights_shared_1.TypeToNumber[value];
|
|
28
|
+
}
|
|
29
|
+
get periodUnit() {
|
|
30
|
+
const periodUnitValue = this.periodUnit_;
|
|
31
|
+
if (!(0, insights_shared_1.isValidPeriodNumber)(periodUnitValue)) {
|
|
32
|
+
throw new n8n_workflow_1.UnexpectedError(`Period unit '${periodUnitValue}' is not a valid unit for 'InsightsByPeriod.periodUnit'`);
|
|
33
|
+
}
|
|
34
|
+
return insights_shared_1.NumberToPeriodUnit[periodUnitValue];
|
|
35
|
+
}
|
|
36
|
+
set periodUnit(value) {
|
|
37
|
+
this.periodUnit_ = insights_shared_1.PeriodUnitToNumber[value];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.InsightsByPeriod = InsightsByPeriod;
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
43
|
+
__metadata("design:type", Number)
|
|
44
|
+
], InsightsByPeriod.prototype, "id", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typeorm_1.Column)(),
|
|
47
|
+
__metadata("design:type", Number)
|
|
48
|
+
], InsightsByPeriod.prototype, "metaId", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typeorm_1.ManyToOne)(() => insights_metadata_entity_1.InsightsMetadata),
|
|
51
|
+
(0, typeorm_1.JoinColumn)({ name: 'metaId' }),
|
|
52
|
+
__metadata("design:type", insights_metadata_entity_1.InsightsMetadata)
|
|
53
|
+
], InsightsByPeriod.prototype, "metadata", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, typeorm_1.Column)({ name: 'type', type: 'int' }),
|
|
56
|
+
__metadata("design:type", Number)
|
|
57
|
+
], InsightsByPeriod.prototype, "type_", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, typeorm_1.Column)(),
|
|
60
|
+
__metadata("design:type", Number)
|
|
61
|
+
], InsightsByPeriod.prototype, "value", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, typeorm_1.Column)({ name: 'periodUnit' }),
|
|
64
|
+
__metadata("design:type", Number)
|
|
65
|
+
], InsightsByPeriod.prototype, "periodUnit_", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, db_1.DateTimeColumn)(),
|
|
68
|
+
__metadata("design:type", Date)
|
|
69
|
+
], InsightsByPeriod.prototype, "periodStart", void 0);
|
|
70
|
+
exports.InsightsByPeriod = InsightsByPeriod = __decorate([
|
|
71
|
+
(0, typeorm_1.Entity)()
|
|
72
|
+
], InsightsByPeriod);
|
|
73
|
+
//# sourceMappingURL=insights-by-period.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insights-by-period.entity.js","sourceRoot":"","sources":["../src/insights-by-period.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gCAAyC;AACzC,0CAOsB;AACtB,+CAA+C;AAE/C,yEAA8D;AAE9D,uDAO2B;AAGpB,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,oBAAU;IAc/C,IAAI,IAAI;QACP,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7B,IAAI,CAAC,IAAA,mCAAiB,EAAC,SAAS,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,8BAAe,CACxB,SAAS,SAAS,mDAAmD,CACrE,CAAC;QACH,CAAC;QAED,OAAO,8BAAY,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,IAAI,CAAC,KAAgC;QACxC,IAAI,CAAC,KAAK,GAAG,8BAAY,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAaD,IAAI,UAAU;QACb,MAAM,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC;QACzC,IAAI,CAAC,IAAA,qCAAmB,EAAC,eAAe,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,8BAAe,CACxB,gBAAgB,eAAe,yDAAyD,CACxF,CAAC;QACH,CAAC;QAED,OAAO,oCAAkB,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,UAAU,CAAC,KAAiB;QAC/B,IAAI,CAAC,WAAW,GAAG,oCAAkB,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;CAID,CAAA;;AAvDA;IADC,IAAA,gCAAsB,GAAE;;4CACd;AAGX;IADC,IAAA,gBAAM,GAAE;;gDACM;AAIf;IAFC,IAAA,mBAAS,EAAC,GAAG,EAAE,CAAC,2CAAgB,CAAC;IACjC,IAAA,oBAAU,EAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;8BACrB,2CAAgB;kDAAC;AAGnB;IADP,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;+CAChB;AAuBtB;IADC,IAAA,gBAAM,GAAE;;+CACK;AAGN;IADP,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;;qDACH;AAkB5B;IADC,IAAA,mBAAc,GAAE;8BACJ,IAAI;qDAAC;2BAxDN,gBAAgB;IAD5B,IAAA,gBAAM,GAAE;GACI,gBAAgB,CAyD5B"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { User } from '@n8n/db';
|
|
2
|
+
import { DbLockService, SharedWorkflowRepository } from '@n8n/db';
|
|
3
|
+
import type { SelectQueryBuilder } from '@n8n/typeorm';
|
|
4
|
+
import { DataSource, Repository } from '@n8n/typeorm';
|
|
5
|
+
import { InsightsByPeriod } from './insights-by-period.entity';
|
|
6
|
+
import type { PeriodUnit, TypeUnitNumber, ByTimeInsightType } from './insights-shared';
|
|
7
|
+
export type InsightsAccessFilter = {
|
|
8
|
+
user: User;
|
|
9
|
+
projectRoles: string[];
|
|
10
|
+
workflowRoles: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare class InsightsByPeriodRepository extends Repository<InsightsByPeriod> {
|
|
13
|
+
private readonly sharedWorkflowRepository;
|
|
14
|
+
private readonly dbLockService;
|
|
15
|
+
private isRunningCompaction;
|
|
16
|
+
constructor(dataSource: DataSource, sharedWorkflowRepository: SharedWorkflowRepository, dbLockService: DbLockService);
|
|
17
|
+
private escapeField;
|
|
18
|
+
private applyAccessFilter;
|
|
19
|
+
private getPeriodFilterExpr;
|
|
20
|
+
private getPeriodStartExpr;
|
|
21
|
+
getPeriodInsightsBatchQuery({ periodUnitToCompactFrom, compactionBatchSize, maxAgeInDays, }: {
|
|
22
|
+
periodUnitToCompactFrom: PeriodUnit;
|
|
23
|
+
compactionBatchSize: number;
|
|
24
|
+
maxAgeInDays: number;
|
|
25
|
+
}): SelectQueryBuilder<{
|
|
26
|
+
id: number;
|
|
27
|
+
metaId: number;
|
|
28
|
+
type: string;
|
|
29
|
+
value: number;
|
|
30
|
+
periodStart: Date;
|
|
31
|
+
}>;
|
|
32
|
+
private getAggregationQuery;
|
|
33
|
+
compactSourceDataIntoInsightPeriod({ sourceBatchQuery, sourceTableName, periodUnitToCompactInto, }: {
|
|
34
|
+
sourceBatchQuery: SelectQueryBuilder<{
|
|
35
|
+
id: number;
|
|
36
|
+
metaId: number;
|
|
37
|
+
type: string;
|
|
38
|
+
value: number;
|
|
39
|
+
periodStart: Date;
|
|
40
|
+
}>;
|
|
41
|
+
sourceTableName?: string;
|
|
42
|
+
periodUnitToCompactInto: PeriodUnit;
|
|
43
|
+
}): Promise<number>;
|
|
44
|
+
getPreviousAndCurrentPeriodTypeAggregates({ startDate, endDate, projectId, timeZone, accessFilter, }: {
|
|
45
|
+
projectId?: string;
|
|
46
|
+
startDate: Date;
|
|
47
|
+
endDate: Date;
|
|
48
|
+
accessFilter?: InsightsAccessFilter;
|
|
49
|
+
timeZone?: string;
|
|
50
|
+
}): Promise<Array<{
|
|
51
|
+
period: 'previous' | 'current';
|
|
52
|
+
type: TypeUnitNumber;
|
|
53
|
+
total_value: string | number;
|
|
54
|
+
}>>;
|
|
55
|
+
private countInsightsByWorkflowGroups;
|
|
56
|
+
getInsightsByWorkflow({ startDate, endDate, skip, take, sortBy, projectId, timeZone, accessFilter, }: {
|
|
57
|
+
skip?: number;
|
|
58
|
+
take?: number;
|
|
59
|
+
sortBy?: string;
|
|
60
|
+
projectId?: string;
|
|
61
|
+
startDate: Date;
|
|
62
|
+
endDate: Date;
|
|
63
|
+
timeZone?: string;
|
|
64
|
+
accessFilter?: InsightsAccessFilter;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
count: number;
|
|
67
|
+
rows: {
|
|
68
|
+
workflowId: string | null;
|
|
69
|
+
workflowName: string;
|
|
70
|
+
projectId: string | null;
|
|
71
|
+
projectName: string;
|
|
72
|
+
total: number;
|
|
73
|
+
succeeded: number;
|
|
74
|
+
failed: number;
|
|
75
|
+
failureRate: number;
|
|
76
|
+
runTime: number;
|
|
77
|
+
averageRunTime: number;
|
|
78
|
+
timeSaved: number;
|
|
79
|
+
}[];
|
|
80
|
+
}>;
|
|
81
|
+
getInsightsByTime({ periodUnit, insightTypes, projectId, startDate, endDate, timeZone, accessFilter, }: {
|
|
82
|
+
periodUnit: PeriodUnit;
|
|
83
|
+
insightTypes: ByTimeInsightType[];
|
|
84
|
+
projectId?: string;
|
|
85
|
+
startDate: Date;
|
|
86
|
+
endDate: Date;
|
|
87
|
+
timeZone?: string;
|
|
88
|
+
accessFilter?: InsightsAccessFilter;
|
|
89
|
+
}): Promise<{
|
|
90
|
+
periodStart: string;
|
|
91
|
+
runTime?: number | undefined;
|
|
92
|
+
succeeded?: number | undefined;
|
|
93
|
+
failed?: number | undefined;
|
|
94
|
+
timeSaved?: number | undefined;
|
|
95
|
+
}[]>;
|
|
96
|
+
pruneOldData(maxAgeInDays: number): Promise<{
|
|
97
|
+
affected: number | null | undefined;
|
|
98
|
+
}>;
|
|
99
|
+
getEarliestDataDate(): Promise<Date | null>;
|
|
100
|
+
}
|