@stryker-mutator/dashboard-data-access 0.15.1-pr-904.0 → 0.15.1-pr-897.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  import { encodeKey } from '../utils.js';
2
2
  import { odata } from '@azure/data-tables';
3
3
  export class DashboardQuery {
4
+ ModelClass;
5
+ whereConditions;
4
6
  constructor(ModelClass, whereConditions) {
5
7
  this.ModelClass = ModelClass;
6
8
  this.whereConditions = whereConditions;
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _MutationTestingResultMapper_containerClient;
13
1
  import { hasErrorCode, toBlobName } from '../utils.js';
14
2
  import { OptimisticConcurrencyError } from '../errors/index.js';
15
3
  import { createBlobServiceClient } from '../services/BlobServiceClient.js';
@@ -21,16 +9,17 @@ const errCodes = Object.freeze({
21
9
  * The report json part of a mutation testing report is stored in blob storage
22
10
  */
23
11
  export class MutationTestingResultMapper {
12
+ static CONTAINER_NAME = 'mutation-testing-report';
13
+ #containerClient;
24
14
  constructor(blobService = createBlobServiceClient()) {
25
- _MutationTestingResultMapper_containerClient.set(this, void 0);
26
- __classPrivateFieldSet(this, _MutationTestingResultMapper_containerClient, blobService.getContainerClient(MutationTestingResultMapper.CONTAINER_NAME), "f");
15
+ this.#containerClient = blobService.getContainerClient(MutationTestingResultMapper.CONTAINER_NAME);
27
16
  }
28
17
  createStorageIfNotExists() {
29
- return __classPrivateFieldGet(this, _MutationTestingResultMapper_containerClient, "f").createIfNotExists({});
18
+ return this.#containerClient.createIfNotExists({});
30
19
  }
31
20
  async insertOrReplace(id, result) {
32
21
  try {
33
- await __classPrivateFieldGet(this, _MutationTestingResultMapper_containerClient, "f")
22
+ await this.#containerClient
34
23
  .getBlockBlobClient(toBlobName(id))
35
24
  .uploadData(Buffer.from(JSON.stringify(result), 'utf-8'), {
36
25
  blobHTTPHeaders: {
@@ -51,7 +40,7 @@ export class MutationTestingResultMapper {
51
40
  async findOne(identifier) {
52
41
  const blobName = toBlobName(identifier);
53
42
  try {
54
- const result = JSON.parse((await __classPrivateFieldGet(this, _MutationTestingResultMapper_containerClient, "f").getBlockBlobClient(blobName).downloadToBuffer()).toString('utf-8'));
43
+ const result = JSON.parse((await this.#containerClient.getBlockBlobClient(blobName).downloadToBuffer()).toString('utf-8'));
55
44
  return result;
56
45
  }
57
46
  catch (error) {
@@ -66,9 +55,7 @@ export class MutationTestingResultMapper {
66
55
  }
67
56
  async delete(id) {
68
57
  const blobName = toBlobName(id);
69
- await __classPrivateFieldGet(this, _MutationTestingResultMapper_containerClient, "f").getBlockBlobClient(blobName).deleteIfExists();
58
+ await this.#containerClient.getBlockBlobClient(blobName).deleteIfExists();
70
59
  }
71
60
  }
72
- _MutationTestingResultMapper_containerClient = new WeakMap();
73
- MutationTestingResultMapper.CONTAINER_NAME = 'mutation-testing-report';
74
61
  //# sourceMappingURL=MutationTestingResultMapper.js.map
@@ -1,22 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var __asyncValues = (this && this.__asyncValues) || function (o) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var m = o[Symbol.asyncIterator], i;
15
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
16
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
17
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
18
- };
19
- var _TableStorageMapper_tableClient;
20
1
  import { encodeKey, decodeKey, hasErrorCode } from '../utils.js';
21
2
  import { OptimisticConcurrencyError } from '../errors/index.js';
22
3
  import { DashboardQuery } from './DashboardQuery.js';
@@ -26,22 +7,23 @@ const errCodes = Object.freeze({
26
7
  ENTITY_ALREADY_EXISTS: 'EntityAlreadyExists',
27
8
  RESOURCE_NOT_FOUND: 'ResourceNotFound',
28
9
  });
29
- class TableStorageMapper {
10
+ export default class TableStorageMapper {
11
+ ModelClass;
12
+ #tableClient;
30
13
  constructor(ModelClass, tableClient = createTableClient(ModelClass.name)) {
31
14
  this.ModelClass = ModelClass;
32
- _TableStorageMapper_tableClient.set(this, void 0);
33
- __classPrivateFieldSet(this, _TableStorageMapper_tableClient, tableClient, "f");
15
+ this.#tableClient = tableClient;
34
16
  }
35
17
  async createStorageIfNotExists() {
36
- await __classPrivateFieldGet(this, _TableStorageMapper_tableClient, "f").createTable();
18
+ await this.#tableClient.createTable();
37
19
  }
38
20
  async insertOrMerge(model) {
39
21
  const entity = this.toEntity(model);
40
- await __classPrivateFieldGet(this, _TableStorageMapper_tableClient, "f").upsertEntity(entity, 'Merge');
22
+ await this.#tableClient.upsertEntity(entity, 'Merge');
41
23
  }
42
24
  async findOne(identity) {
43
25
  try {
44
- const result = await __classPrivateFieldGet(this, _TableStorageMapper_tableClient, "f").getEntity(encodeKey(this.ModelClass.createPartitionKey(identity)), encodeKey(this.ModelClass.createRowKey(identity) || ''));
26
+ const result = await this.#tableClient.getEntity(encodeKey(this.ModelClass.createPartitionKey(identity)), encodeKey(this.ModelClass.createRowKey(identity) || ''));
45
27
  return this.toModel(result);
46
28
  }
47
29
  catch (err) {
@@ -55,24 +37,11 @@ class TableStorageMapper {
55
37
  }
56
38
  }
57
39
  async findAll(query = DashboardQuery.create(this.ModelClass)) {
58
- var _a, e_1, _b, _c;
59
40
  const tableQuery = query.build();
60
- const entities = __classPrivateFieldGet(this, _TableStorageMapper_tableClient, "f").listEntities({ queryOptions: tableQuery });
41
+ const entities = this.#tableClient.listEntities({ queryOptions: tableQuery });
61
42
  const results = [];
62
- try {
63
- for (var _d = true, entities_1 = __asyncValues(entities), entities_1_1; entities_1_1 = await entities_1.next(), _a = entities_1_1.done, !_a; _d = true) {
64
- _c = entities_1_1.value;
65
- _d = false;
66
- const entity = _c;
67
- results.push(this.toModel(entity));
68
- }
69
- }
70
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
- finally {
72
- try {
73
- if (!_d && !_a && (_b = entities_1.return)) await _b.call(entities_1);
74
- }
75
- finally { if (e_1) throw e_1.error; }
43
+ for await (const entity of entities) {
44
+ results.push(this.toModel(entity));
76
45
  }
77
46
  return results;
78
47
  }
@@ -85,7 +54,7 @@ class TableStorageMapper {
85
54
  async replace(model, etag) {
86
55
  const entity = this.toEntity(model);
87
56
  try {
88
- const result = await __classPrivateFieldGet(this, _TableStorageMapper_tableClient, "f").updateEntity(entity, 'Replace', { etag });
57
+ const result = await this.#tableClient.updateEntity(entity, 'Replace', { etag });
89
58
  return { model, etag: result.etag };
90
59
  }
91
60
  catch (err) {
@@ -100,7 +69,7 @@ class TableStorageMapper {
100
69
  async insert(model) {
101
70
  const entity = this.toEntity(model);
102
71
  try {
103
- const result = await __classPrivateFieldGet(this, _TableStorageMapper_tableClient, "f").createEntity(entity);
72
+ const result = await this.#tableClient.createEntity(entity);
104
73
  return { model, etag: result.etag };
105
74
  }
106
75
  catch (err) {
@@ -122,6 +91,7 @@ class TableStorageMapper {
122
91
  };
123
92
  }
124
93
  toEntity(entity) {
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
95
  const data = {
126
96
  partitionKey: encodeKey(this.ModelClass.createPartitionKey(entity)),
127
97
  rowKey: encodeKey(this.ModelClass.createRowKey(entity) || ''),
@@ -130,6 +100,4 @@ class TableStorageMapper {
130
100
  return data;
131
101
  }
132
102
  }
133
- _TableStorageMapper_tableClient = new WeakMap();
134
- export default TableStorageMapper;
135
103
  //# sourceMappingURL=TableStorageMapper.js.map
@@ -1,4 +1,24 @@
1
1
  export class MutationTestingReport {
2
+ /**
3
+ * The repo slug. /:provider/:owner/:name (could also have more components in the future, for example gitlab supports this)
4
+ * @example /github.com/stryker-mutator/mutation-testing-elements
5
+ */
6
+ projectName;
7
+ /**
8
+ * The branch, tag or git hash
9
+ * @example 'master', 'v1', '0d3af4840904c42dede7016f45b53718a617bbd8'
10
+ */
11
+ version;
12
+ /**
13
+ * Optional: the module
14
+ * For example 'schema'
15
+ */
16
+ moduleName;
17
+ /**
18
+ * Indicates whether this report is real-time.
19
+ */
20
+ realTime;
21
+ mutationScore;
2
22
  static createRowKey(identifier) {
3
23
  return identifier.moduleName;
4
24
  }
@@ -11,7 +31,7 @@ export class MutationTestingReport {
11
31
  entity.version = partitionKeyValue.substr(versionSplit + 1);
12
32
  entity.moduleName = rowKeyValue;
13
33
  }
34
+ static persistedFields = ['mutationScore'];
35
+ static tableName = 'MutationTestingReport';
14
36
  }
15
- MutationTestingReport.persistedFields = ['mutationScore'];
16
- MutationTestingReport.tableName = 'MutationTestingReport';
17
37
  //# sourceMappingURL=MutationTestingReport.js.map
@@ -1,4 +1,10 @@
1
1
  export class Project {
2
+ owner;
3
+ name;
4
+ enabled;
5
+ apiKeyHash;
6
+ static persistedFields = ['enabled', 'apiKeyHash'];
7
+ static tableName = 'Project';
2
8
  static createRowKey(identifier) {
3
9
  return identifier.name;
4
10
  }
@@ -10,6 +16,4 @@ export class Project {
10
16
  entity.owner = partitionKeyValue;
11
17
  }
12
18
  }
13
- Project.persistedFields = ['enabled', 'apiKeyHash'];
14
- Project.tableName = 'Project';
15
19
  //# sourceMappingURL=Project.js.map
@@ -1,6 +1,6 @@
1
1
  import { aggregateResultsByModule, calculateMetrics } from 'mutation-testing-metrics';
2
2
  import { MutationTestingResultMapper } from '../mappers/MutationTestingResultMapper.js';
3
- import { createMutationTestingReportMapper, DashboardQuery, } from '../mappers/index.js';
3
+ import { createMutationTestingReportMapper, DashboardQuery } from '../mappers/index.js';
4
4
  import { isMutationTestResult, } from '@stryker-mutator/dashboard-common';
5
5
  import { MutationTestingReport } from '../models/index.js';
6
6
  import { OptimisticConcurrencyError } from '../errors/index.js';
@@ -8,6 +8,8 @@ function moduleHasResult(tuple) {
8
8
  return !!tuple[1];
9
9
  }
10
10
  export class MutationTestingReportService {
11
+ resultMapper;
12
+ mutationScoreMapper;
11
13
  constructor(resultMapper = new MutationTestingResultMapper(), mutationScoreMapper = createMutationTestingReportMapper()) {
12
14
  this.resultMapper = resultMapper;
13
15
  this.mutationScoreMapper = mutationScoreMapper;
@@ -18,7 +20,10 @@ export class MutationTestingReportService {
18
20
  }
19
21
  async saveReport(id, result, logger) {
20
22
  const mutationScore = this.calculateMutationScore(result);
21
- await this.insertOrMergeReport(id, Object.assign(Object.assign({}, id), { mutationScore }), isMutationTestResult(result) ? result : null);
23
+ await this.insertOrMergeReport(id, {
24
+ ...id,
25
+ mutationScore,
26
+ }, isMutationTestResult(result) ? result : null);
22
27
  if (isMutationTestResult(result) && id.moduleName) {
23
28
  await this.aggregateProjectReport(id.projectName, id.version, logger);
24
29
  }
@@ -43,7 +48,10 @@ export class MutationTestingReportService {
43
48
  const resultsByModule = Object.fromEntries((await Promise.all(moduleScoreResults.map(async (score) => [score.model.moduleName, await this.resultMapper.findOne(score.model)]))).filter(moduleHasResult));
44
49
  if (Object.keys(resultsByModule).length) {
45
50
  const projectResult = aggregateResultsByModule(resultsByModule);
46
- const projectReport = Object.assign(Object.assign({}, id), { mutationScore: this.calculateMutationScore(projectResult) });
51
+ const projectReport = {
52
+ ...id,
53
+ mutationScore: this.calculateMutationScore(projectResult),
54
+ };
47
55
  try {
48
56
  await this.resultMapper.insertOrReplace(id, projectResult);
49
57
  if (projectMutationScoreModel) {
@@ -71,10 +79,14 @@ export class MutationTestingReportService {
71
79
  ]);
72
80
  if (reportEntity) {
73
81
  if (result) {
74
- return Object.assign(Object.assign(Object.assign({}, id), { mutationScore: reportEntity.model.mutationScore }), result);
82
+ return {
83
+ ...id,
84
+ mutationScore: reportEntity.model.mutationScore,
85
+ ...result,
86
+ };
75
87
  }
76
88
  else {
77
- return Object.assign(Object.assign({}, id), { mutationScore: reportEntity.model.mutationScore });
89
+ return { ...id, mutationScore: reportEntity.model.mutationScore };
78
90
  }
79
91
  }
80
92
  else {
@@ -85,10 +97,7 @@ export class MutationTestingReportService {
85
97
  await this.resultMapper.delete(id);
86
98
  }
87
99
  async insertOrMergeReport(id, report, result) {
88
- await Promise.all([
89
- this.resultMapper.insertOrReplace(id, result),
90
- this.mutationScoreMapper.insertOrMerge(report),
91
- ]);
100
+ await Promise.all([this.resultMapper.insertOrReplace(id, result), this.mutationScoreMapper.insertOrMerge(report)]);
92
101
  }
93
102
  calculateMutationScore(result) {
94
103
  if (isMutationTestResult(result)) {
@@ -1,37 +1,26 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _RealTimeMutantsBlobService_containerClient;
13
1
  import { toBlobName } from '../utils.js';
14
2
  import { createBlobServiceClient } from './BlobServiceClient.js';
15
3
  // To make resource delete themselves automatically, this should be managed from within Azure:
16
4
  // https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-overview?tabs=azure-portal
17
5
  export class RealTimeMutantsBlobService {
6
+ static CONTAINER_NAME = 'real-time-mutant-results';
7
+ #containerClient;
18
8
  constructor(blobService = createBlobServiceClient()) {
19
- _RealTimeMutantsBlobService_containerClient.set(this, void 0);
20
- __classPrivateFieldSet(this, _RealTimeMutantsBlobService_containerClient, blobService.getContainerClient(RealTimeMutantsBlobService.CONTAINER_NAME), "f");
9
+ this.#containerClient = blobService.getContainerClient(RealTimeMutantsBlobService.CONTAINER_NAME);
21
10
  }
22
11
  async createStorageIfNotExists() {
23
- await __classPrivateFieldGet(this, _RealTimeMutantsBlobService_containerClient, "f").createIfNotExists({});
12
+ await this.#containerClient.createIfNotExists({});
24
13
  }
25
14
  async createReport(id) {
26
- await __classPrivateFieldGet(this, _RealTimeMutantsBlobService_containerClient, "f").getAppendBlobClient(toBlobName(id)).create();
15
+ await this.#containerClient.getAppendBlobClient(toBlobName(id)).create();
27
16
  }
28
17
  async appendToReport(id, mutants) {
29
18
  const blobName = toBlobName(id);
30
19
  const data = mutants.map((mutant) => `${JSON.stringify(mutant)}\n`).join('');
31
- await __classPrivateFieldGet(this, _RealTimeMutantsBlobService_containerClient, "f").getAppendBlobClient(blobName).appendBlock(data, data.length);
20
+ await this.#containerClient.getAppendBlobClient(blobName).appendBlock(data, data.length);
32
21
  }
33
22
  async getReport(id) {
34
- const data = await __classPrivateFieldGet(this, _RealTimeMutantsBlobService_containerClient, "f").getAppendBlobClient(toBlobName(id)).downloadToBuffer();
23
+ const data = await this.#containerClient.getAppendBlobClient(toBlobName(id)).downloadToBuffer();
35
24
  return (data
36
25
  .toString('utf-8')
37
26
  .split('\n')
@@ -42,9 +31,7 @@ export class RealTimeMutantsBlobService {
42
31
  }
43
32
  async delete(id) {
44
33
  const blobName = toBlobName(id);
45
- await __classPrivateFieldGet(this, _RealTimeMutantsBlobService_containerClient, "f").getAppendBlobClient(blobName).deleteIfExists();
34
+ await this.#containerClient.getAppendBlobClient(blobName).deleteIfExists();
46
35
  }
47
36
  }
48
- _RealTimeMutantsBlobService_containerClient = new WeakMap();
49
- RealTimeMutantsBlobService.CONTAINER_NAME = 'real-time-mutant-results';
50
37
  //# sourceMappingURL=RealTimeMutantsBlobService.js.map
package/dist/src/utils.js CHANGED
@@ -9,18 +9,14 @@ export function isStorageError(maybeStorageError) {
9
9
  return maybeStorageError instanceof RestError;
10
10
  }
11
11
  export function hasErrorCode(err, code) {
12
- var _a;
13
12
  if (!isStorageError(err))
14
13
  return false;
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
15
  const details = err.details;
16
- return (typeof details === 'object' &&
17
- details !== null &&
18
- (details.errorCode === code || ((_a = details.odataError) === null || _a === void 0 ? void 0 : _a.code) === code));
16
+ return (typeof details === 'object' && details !== null && (details.errorCode === code || details.odataError?.code === code));
19
17
  }
20
18
  export function toBlobName({ projectName, version, moduleName, realTime }) {
21
- const slug = [projectName, version, moduleName, realTime ? 'real-time' : realTime]
22
- .filter(Boolean)
23
- .join('/');
19
+ const slug = [projectName, version, moduleName, realTime ? 'real-time' : realTime].filter(Boolean).join('/');
24
20
  return encodeKey(slug);
25
21
  }
26
22
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryker-mutator/dashboard-data-access",
3
- "version": "0.15.1-pr-904.0",
3
+ "version": "0.15.1-pr-897.2",
4
4
  "type": "module",
5
5
  "description": "This package contains the data access layer of the stryker dashboard application.",
6
6
  "scripts": {
@@ -24,9 +24,9 @@
24
24
  "dependencies": {
25
25
  "@azure/data-tables": "13.2.2",
26
26
  "@azure/storage-blob": "12.24.0",
27
- "@stryker-mutator/dashboard-common": "0.15.1-pr-904.0",
27
+ "@stryker-mutator/dashboard-common": "0.15.1-pr-897.2",
28
28
  "mutation-testing-metrics": "3.2.0",
29
29
  "mutation-testing-report-schema": "3.1.1"
30
30
  },
31
- "gitHead": "09ea1c81f1b117136f88a61074bee1ebc135c41c"
31
+ "gitHead": "246b54a147a103b4f9b1f313bfe3dd9123de8f05"
32
32
  }