repometry 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +28 -2
- package/package.json +64 -4
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +33 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +252 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +120 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +560 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +92 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +106 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +108 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +53 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +71 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +74 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +153 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +31 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +47 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +36 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +35 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +57 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +227 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +14 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +17 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +46 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +102 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +86 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +111 -0
- package/target/main/ts/cli/config.d.ts +13 -0
- package/target/main/ts/cli/config.js +58 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +30 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +379 -0
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +104 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +16 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +39 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +164 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +50 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +45 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +10 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +17 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +39 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +30 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +50 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +105 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +107 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +86 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +2 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +15 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +32 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +36 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +33 -0
- package/target/main/ts/core/model/measurement.js +30 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +40 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +29 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +51 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +2 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +5 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +58 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +10 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +11 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +146 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +16 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +42 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +129 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +18 -0
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +6 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
- package/target/main/ts/plugins/coverage/coverage.js +199 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +94 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +36 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +61 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +80 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +38 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2104 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
- package/target/main/ts/report/html/app/viewer-trends.js +423 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +735 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +40 -0
- package/target/main/ts/report/html/site/export-site.d.ts +22 -0
- package/target/main/ts/report/html/site/export-site.js +150 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +71 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +65 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +80 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +65 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +23 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
- package/target/main/ts/report/json/projections/commit-summary.js +124 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +30 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +244 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +93 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +70 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +58 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +17 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +32 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +180 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +52 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +8 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +65 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +28 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +6 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Report } from '../validation/report.js';
|
|
2
|
+
import type { PublicHistory, QualityHistory } from '../wire/public-history-model.js';
|
|
3
|
+
export declare function publicHistory(reports: readonly Report[]): PublicHistory;
|
|
4
|
+
export declare function qualityHistory(reports: readonly Report[]): QualityHistory;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { qualitySummary } from '../../../core/model/quality-summary.js';
|
|
2
|
+
import { historyEntry } from './commit-summary.js';
|
|
3
|
+
import { historySchema } from '../wire/public-history-model.js';
|
|
4
|
+
export function publicHistory(reports) {
|
|
5
|
+
return {
|
|
6
|
+
schema: historySchema,
|
|
7
|
+
reports: reports.filter(report => report.subject.kind === 'commit').map(historyEntry),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function qualityHistory(reports) {
|
|
11
|
+
return {
|
|
12
|
+
schema: 'urn:repometry:schema:quality-history:1',
|
|
13
|
+
reports: Object.fromEntries(reports.filter(report => report.subject.kind === 'commit')
|
|
14
|
+
.map(report => [report.subject.id, qualitySummary(report)])),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=public-history.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
3
|
+
export async function readComponents(file, optional) {
|
|
4
|
+
try {
|
|
5
|
+
const config = JSON.parse(await readFile(file, 'utf8'));
|
|
6
|
+
if (!Array.isArray(config))
|
|
7
|
+
throw new Error('Expected an array of component definitions');
|
|
8
|
+
const names = new Set();
|
|
9
|
+
return config.map((entry) => {
|
|
10
|
+
if (!isRecord(entry) || typeof entry.name !== 'string' || !entry.name.trim() || entry.name.length > 100
|
|
11
|
+
|| !Array.isArray(entry.pathGlobs) || entry.pathGlobs.length === 0 || !entry.pathGlobs.every(validPattern)
|
|
12
|
+
|| (entry.description !== undefined && typeof entry.description !== 'string')) {
|
|
13
|
+
throw new Error('Each component requires a name and one or more root-relative pathGlobs');
|
|
14
|
+
}
|
|
15
|
+
const name = entry.name.trim();
|
|
16
|
+
if (names.has(name))
|
|
17
|
+
throw new Error(`Duplicate component name: ${name}`);
|
|
18
|
+
names.add(name);
|
|
19
|
+
return { name, pathGlobs: [...new Set(entry.pathGlobs)], description: entry.description };
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (optional && error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
24
|
+
return [];
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function validPattern(pattern) {
|
|
29
|
+
return typeof pattern === 'string' && !/^[A-Za-z]:|[\\\0]/.test(pattern)
|
|
30
|
+
&& pattern.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Subject } from '../../../core/model/snapshot.js';
|
|
2
|
+
import type { CommitSummary } from '../wire/summary-model.js';
|
|
3
|
+
import type { Report, ReportStore } from '../validation/report.js';
|
|
4
|
+
export declare class LocalReportStore implements ReportStore {
|
|
5
|
+
private readonly directory;
|
|
6
|
+
constructor(directory: string);
|
|
7
|
+
save(report: Report): Promise<void>;
|
|
8
|
+
read(subject: Subject): Promise<Report>;
|
|
9
|
+
list(): Promise<readonly Report[]>;
|
|
10
|
+
listSummaries(): Promise<readonly CommitSummary[]>;
|
|
11
|
+
private refreshSummary;
|
|
12
|
+
private folder;
|
|
13
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, open, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
6
|
+
import { commitSummary, orderSummaries, repositorySummary } from '../projections/commit-summary.js';
|
|
7
|
+
import { summarySchema } from '../wire/summary-model.js';
|
|
8
|
+
import { compactJsonSchema, packJson } from '../wire/compact-json.js';
|
|
9
|
+
import { compareReports, readReport, readReportText, validSubjectId } from '../validation/report.js';
|
|
10
|
+
import { validateSummaryRow } from '../validation/summary-validation.js';
|
|
11
|
+
const packedHeader = `{"schema":"${compactJsonSchema}","summary":`;
|
|
12
|
+
export class LocalReportStore {
|
|
13
|
+
directory;
|
|
14
|
+
constructor(directory) {
|
|
15
|
+
this.directory = directory;
|
|
16
|
+
}
|
|
17
|
+
async save(report) {
|
|
18
|
+
readReport(report);
|
|
19
|
+
const base = join(this.directory, subjectFolder(report.subject.kind));
|
|
20
|
+
const folder = this.folder(report.subject);
|
|
21
|
+
await mkdir(this.directory, { mode: 0o700, recursive: true });
|
|
22
|
+
await ensureDirectory(base);
|
|
23
|
+
await ensureDirectory(folder);
|
|
24
|
+
const packed = packJson(JSON.parse(JSON.stringify(report)));
|
|
25
|
+
const { strings, shapes, data } = packed;
|
|
26
|
+
const row = report.subject.kind === 'commit' ? commitSummary(report) : undefined;
|
|
27
|
+
if (row && !validateSummaryRow(row))
|
|
28
|
+
throw new Error(`Invalid report summary: ${report.subject.id}`);
|
|
29
|
+
// Keep the small index row on the first line of the same atomic file as the report.
|
|
30
|
+
const contents = row
|
|
31
|
+
? `${packedHeader}${JSON.stringify(row)},\n${JSON.stringify({ strings, shapes, data }).slice(1)}\n`
|
|
32
|
+
: `${JSON.stringify(packed)}\n`;
|
|
33
|
+
await replaceFile(folder, 'report.json', contents);
|
|
34
|
+
if (report.subject.kind === 'commit')
|
|
35
|
+
await this.refreshSummary();
|
|
36
|
+
}
|
|
37
|
+
async read(subject) {
|
|
38
|
+
const folder = this.folder(subject);
|
|
39
|
+
const path = join(folder, 'report.json');
|
|
40
|
+
await checkDirectory(join(this.directory, subjectFolder(subject.kind)));
|
|
41
|
+
await checkDirectory(folder);
|
|
42
|
+
if (!(await lstat(path)).isFile())
|
|
43
|
+
throw new Error(`Expected a report file: ${path}`);
|
|
44
|
+
return readReportText(await readFile(path, 'utf8'), subject);
|
|
45
|
+
}
|
|
46
|
+
async list() {
|
|
47
|
+
const reports = [];
|
|
48
|
+
for (const kind of ['commit', 'working-tree']) {
|
|
49
|
+
const base = join(this.directory, subjectFolder(kind));
|
|
50
|
+
try {
|
|
51
|
+
await checkDirectory(base);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (hasCode(error, 'ENOENT'))
|
|
55
|
+
continue;
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
for (const entry of await readdir(base, { withFileTypes: true })) {
|
|
59
|
+
if (!entry.isDirectory() || !validSubjectId(kind, entry.name))
|
|
60
|
+
continue;
|
|
61
|
+
try {
|
|
62
|
+
reports.push(await this.read({ kind, id: entry.name }));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
// A writer may have created the directory but not published its report yet.
|
|
66
|
+
if (!hasCode(error, 'ENOENT'))
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return reports.sort(compareReports);
|
|
72
|
+
}
|
|
73
|
+
async listSummaries() {
|
|
74
|
+
const base = join(this.directory, 'commits');
|
|
75
|
+
try {
|
|
76
|
+
await checkDirectory(base);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (hasCode(error, 'ENOENT'))
|
|
80
|
+
return [];
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const entries = await readdir(base, { withFileTypes: true });
|
|
84
|
+
const summaries = [];
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
if (!entry.isDirectory() || !validSubjectId('commit', entry.name))
|
|
87
|
+
continue;
|
|
88
|
+
const subject = { kind: 'commit', id: entry.name };
|
|
89
|
+
const path = join(base, entry.name, 'report.json');
|
|
90
|
+
try {
|
|
91
|
+
if (!(await lstat(path)).isFile())
|
|
92
|
+
throw new Error(`Expected a report file: ${path}`);
|
|
93
|
+
summaries.push((await readSummaryHeader(path, subject.id)) ?? commitSummary(await this.read(subject)));
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (!hasCode(error, 'ENOENT'))
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return orderSummaries(summaries);
|
|
101
|
+
}
|
|
102
|
+
async refreshSummary() {
|
|
103
|
+
const path = join(this.directory, 'summary.json');
|
|
104
|
+
try {
|
|
105
|
+
if (!(await lstat(path)).isFile())
|
|
106
|
+
throw new Error('Expected a regular summary.json file');
|
|
107
|
+
const current = JSON.parse(await readFile(path, 'utf8'));
|
|
108
|
+
if (!isRecord(current) || current.schema !== summarySchema)
|
|
109
|
+
throw new Error('Existing summary.json is not a Repometry summary');
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (!hasCode(error, 'ENOENT'))
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
for (let attempt = 0; attempt < 8; attempt++) {
|
|
116
|
+
const commits = await this.listSummaries();
|
|
117
|
+
await replaceFile(this.directory, 'summary.json', `${JSON.stringify(repositorySummary(commits))}\n`);
|
|
118
|
+
if (isDeepStrictEqual(commits, await this.listSummaries()))
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw new Error('Reports kept changing during summary publication. The inspection is saved and the summary can be refreshed by retrying.');
|
|
122
|
+
}
|
|
123
|
+
folder(subject) {
|
|
124
|
+
if (!validSubjectId(subject.kind, subject.id))
|
|
125
|
+
throw new Error(`Invalid ${subject.kind} ID: ${subject.id}`);
|
|
126
|
+
return join(this.directory, subjectFolder(subject.kind), subject.id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function readSummaryHeader(path, sha) {
|
|
130
|
+
const file = await open(path, 'r');
|
|
131
|
+
try {
|
|
132
|
+
const buffer = Buffer.alloc(4096);
|
|
133
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
134
|
+
const end = buffer.subarray(0, bytesRead).indexOf(10);
|
|
135
|
+
if (end < 0)
|
|
136
|
+
return undefined;
|
|
137
|
+
const first = buffer.toString('utf8', 0, end);
|
|
138
|
+
if (!first.startsWith(packedHeader) || !first.endsWith(','))
|
|
139
|
+
return undefined;
|
|
140
|
+
const envelope = JSON.parse(first.slice(0, -1) + '}');
|
|
141
|
+
if (!isRecord(envelope) || !validateSummaryRow(envelope.summary) || envelope.summary.sha !== sha
|
|
142
|
+
|| !envelope.summary.revision || envelope.summary.detail !== undefined)
|
|
143
|
+
throw new Error(`Invalid report summary: ${sha}`);
|
|
144
|
+
return envelope.summary;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
await file.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function replaceFile(directory, name, contents) {
|
|
151
|
+
const temporary = join(directory, `.repometry-${randomUUID()}.tmp`);
|
|
152
|
+
try {
|
|
153
|
+
await writeFile(temporary, contents, { flag: 'wx', mode: 0o600 });
|
|
154
|
+
await rename(temporary, join(directory, name));
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await rm(temporary, { force: true });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function subjectFolder(kind) {
|
|
161
|
+
return kind === 'commit' ? 'commits' : 'working-trees';
|
|
162
|
+
}
|
|
163
|
+
function hasCode(error, code) {
|
|
164
|
+
return error instanceof Error && 'code' in error && error.code === code;
|
|
165
|
+
}
|
|
166
|
+
async function ensureDirectory(path) {
|
|
167
|
+
try {
|
|
168
|
+
await mkdir(path, { mode: 0o700 });
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (!hasCode(error, 'EEXIST'))
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
await checkDirectory(path);
|
|
175
|
+
}
|
|
176
|
+
async function checkDirectory(path) {
|
|
177
|
+
if (!(await lstat(path)).isDirectory())
|
|
178
|
+
throw new Error(`Expected a directory: ${path}`);
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=local-store.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
+
import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
|
|
6
|
+
import comparison from '../../../../resources/report/json/comparison-v1.schema.json' with { type: 'json' };
|
|
7
|
+
import diffCoverage from '../../../../resources/report/json/diff-coverage-v1.schema.json' with { type: 'json' };
|
|
8
|
+
import inspection from '../../../../resources/report/json/report-v1.schema.json' with { type: 'json' };
|
|
9
|
+
import currentInspection from '../../../../resources/report/json/report-v2.schema.json' with { type: 'json' };
|
|
10
|
+
import schema from '../../../../resources/report/json/pull-review-v1.schema.json' with { type: 'json' };
|
|
11
|
+
const ajv = new Ajv2020({ schemas: [metricCatalog, inspection, currentInspection, comparison, diffCoverage] });
|
|
12
|
+
const validate = ajv.compile(schema);
|
|
13
|
+
export async function savePullReview(output, review) {
|
|
14
|
+
if (!validate(review))
|
|
15
|
+
throw new Error(`Invalid pull request review: ${ajv.errorsText(validate.errors)}`);
|
|
16
|
+
if (review.number === null)
|
|
17
|
+
throw new Error('Saving a pull request review requires its number');
|
|
18
|
+
const directory = join(output, 'reviews');
|
|
19
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
20
|
+
if (!(await lstat(directory)).isDirectory())
|
|
21
|
+
throw new Error('Expected a directory for PR reviews');
|
|
22
|
+
const temporary = join(directory, `.review-${randomUUID()}.tmp`);
|
|
23
|
+
try {
|
|
24
|
+
await writeFile(temporary, `${JSON.stringify(review, null, 2)}\n`, { flag: 'wx', mode: 0o600 });
|
|
25
|
+
await rename(temporary, join(directory, `${review.number}.json`));
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
await rm(temporary, { force: true });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function listPullReviews(output) {
|
|
32
|
+
const directory = join(output, 'reviews');
|
|
33
|
+
try {
|
|
34
|
+
if (!(await lstat(directory)).isDirectory())
|
|
35
|
+
throw new Error('Expected a directory for PR reviews');
|
|
36
|
+
const files = (await readdir(directory, { withFileTypes: true })).filter(entry => entry.isFile() && /^[1-9]\d*\.json$/.test(entry.name));
|
|
37
|
+
const reviews = await Promise.all(files.map(async ({ name }) => {
|
|
38
|
+
const value = JSON.parse(await readFile(join(directory, name), 'utf8'));
|
|
39
|
+
if (!validate(value) || `${value.number}.json` !== name || !Number.isFinite(Date.parse(value.generatedAt))) {
|
|
40
|
+
throw new Error(`Invalid pull request review: ${name}`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}));
|
|
44
|
+
return reviews.sort((left, right) => right.generatedAt.localeCompare(left.generatedAt) || (right.number ?? 0) - (left.number ?? 0));
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
48
|
+
return [];
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=pull-review-store.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
2
|
+
export const metaManifest = { schema: 'urn:repometry:schema:metabranch:1' };
|
|
3
|
+
export function checkMetaManifest(text) {
|
|
4
|
+
const value = JSON.parse(text);
|
|
5
|
+
if (!isRecord(value) || value.schema !== metaManifest.schema)
|
|
6
|
+
throw new Error('Unsupported metabranch manifest');
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=metabranch.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Subject } from '../../../core/model/source.js';
|
|
2
|
+
import type { CommitSummary } from '../wire/summary-model.js';
|
|
3
|
+
import type { Report } from '../../../core/model/report.js';
|
|
4
|
+
import type { ReportReader as DomainReportReader, ReportWriter } from '../../../core/ports/report.js';
|
|
5
|
+
export { legacyReportSchema, reportSchema, validSubjectId } from '../../../core/model/report.js';
|
|
6
|
+
export type { Diagnostic, Report } from '../../../core/model/report.js';
|
|
7
|
+
export interface ReportReader extends DomainReportReader {
|
|
8
|
+
listSummaries?(): Promise<readonly CommitSummary[]>;
|
|
9
|
+
}
|
|
10
|
+
export interface ReportStore extends ReportReader, ReportWriter {
|
|
11
|
+
}
|
|
12
|
+
export declare function readReportText(text: string, subject: Subject): Report;
|
|
13
|
+
export declare function reportRevision(report: Report): string;
|
|
14
|
+
export declare function compareReports(a: Report, b: Report): number;
|
|
15
|
+
export declare function readReport(value: unknown): Report;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
2
|
+
import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
|
|
3
|
+
import schemaV1 from '../../../../resources/report/json/report-v1.schema.json' with { type: 'json' };
|
|
4
|
+
import schemaV2 from '../../../../resources/report/json/report-v2.schema.json' with { type: 'json' };
|
|
5
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
6
|
+
import { isMetricDescriptor } from '../../../core/engine/manifest.js';
|
|
7
|
+
import { isFinding } from '../../../core/model/finding.js';
|
|
8
|
+
import { digest } from '../../../core/model/snapshot.js';
|
|
9
|
+
import { compactJsonSchema, unpackJson } from '../wire/compact-json.js';
|
|
10
|
+
import { legacyReportSchema, reportSchema } from '../../../core/model/report.js';
|
|
11
|
+
export { legacyReportSchema, reportSchema, validSubjectId } from '../../../core/model/report.js';
|
|
12
|
+
export function readReportText(text, subject) {
|
|
13
|
+
const envelope = JSON.parse(text);
|
|
14
|
+
const report = readReport(unpackJson(envelope));
|
|
15
|
+
if (report.subject.kind !== subject.kind || report.subject.id !== subject.id)
|
|
16
|
+
throw new Error(`Report subject mismatch: ${subject.id}`);
|
|
17
|
+
if (isRecord(envelope) && envelope.schema === compactJsonSchema && isRecord(envelope.summary)
|
|
18
|
+
&& envelope.summary.revision !== undefined && envelope.summary.revision !== reportRevision(report)) {
|
|
19
|
+
throw new Error(`Report revision mismatch: ${subject.id}`);
|
|
20
|
+
}
|
|
21
|
+
return report;
|
|
22
|
+
}
|
|
23
|
+
export function reportRevision(report) {
|
|
24
|
+
return digest(JSON.stringify(report));
|
|
25
|
+
}
|
|
26
|
+
export function compareReports(a, b) {
|
|
27
|
+
return b.generatedAt.localeCompare(a.generatedAt) || a.subject.id.localeCompare(b.subject.id);
|
|
28
|
+
}
|
|
29
|
+
const ajv = new Ajv2020({ schemas: [metricCatalog] });
|
|
30
|
+
const validateV1 = ajv.compile(schemaV1);
|
|
31
|
+
const validateV2 = ajv.compile(schemaV2);
|
|
32
|
+
export function readReport(value) {
|
|
33
|
+
if (!isRecord(value) || (value.schema !== reportSchema && value.schema !== legacyReportSchema)) {
|
|
34
|
+
throw new Error('Unsupported or missing report schema');
|
|
35
|
+
}
|
|
36
|
+
const validate = value.schema === reportSchema ? validateV2 : validateV1;
|
|
37
|
+
if (!validate(value))
|
|
38
|
+
throw new Error(`Invalid report: ${ajv.errorsText(validate.errors)}`);
|
|
39
|
+
if (value.pluginData) {
|
|
40
|
+
const { metrics, measured, privateMetrics } = value.pluginData;
|
|
41
|
+
const ids = new Set(metrics.map(metric => metric.id));
|
|
42
|
+
if (ids.size !== metrics.length || !metrics.every(isMetricDescriptor)
|
|
43
|
+
|| [...measured, ...privateMetrics ?? []].some(id => !ids.has(id)))
|
|
44
|
+
throw new Error('Invalid report: inconsistent metric catalog');
|
|
45
|
+
}
|
|
46
|
+
if (value.scope.parsed > value.scope.files)
|
|
47
|
+
throw new Error('Invalid report: parsed count exceeds source count');
|
|
48
|
+
if (value.findings?.some(finding => !isFinding(finding)))
|
|
49
|
+
throw new Error('Invalid report: inconsistent finding location');
|
|
50
|
+
const ignore = value.appliedConfig.findingIgnore;
|
|
51
|
+
if (value.ignoredFindings?.some(({ finding, matchedRule }) => !isFinding(finding)
|
|
52
|
+
|| !Array.isArray(ignore) || matchedRule >= ignore.length))
|
|
53
|
+
throw new Error('Invalid report: inconsistent ignored finding');
|
|
54
|
+
for (const item of value.measurements) {
|
|
55
|
+
if (!Object.hasOwn(value.definitions, item.definition))
|
|
56
|
+
throw new Error(`Unknown measurement definition: ${item.definition}`);
|
|
57
|
+
if (item.covered === undefined || item.total === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
if (item.covered > item.total || item.value !== (item.total === 0 ? null : item.covered / item.total)) {
|
|
60
|
+
throw new Error('Invalid report: inconsistent coverage counts');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CommitSummary, RepositorySummary } from '../wire/summary-model.js';
|
|
2
|
+
export declare const validateSummary: import("ajv/dist/2020.js").ValidateFunction<RepositorySummary>;
|
|
3
|
+
export declare function validateSummaryIndex(value: unknown): value is RepositorySummary;
|
|
4
|
+
export declare function validateSummaryRow(value: unknown): value is CommitSummary;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
2
|
+
import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
|
|
3
|
+
import historySchema from '../../../../resources/report/json/public-history-v1.schema.json' with { type: 'json' };
|
|
4
|
+
import qualitySchema from '../../../../resources/report/json/quality-history-v1.schema.json' with { type: 'json' };
|
|
5
|
+
import summaryContract from '../../../../resources/report/json/repository-summary-v1.schema.json' with { type: 'json' };
|
|
6
|
+
import { summarySchema } from '../wire/summary-model.js';
|
|
7
|
+
import { isMetricDescriptor } from '../../../core/engine/manifest.js';
|
|
8
|
+
const validator = new Ajv2020({ schemas: [metricCatalog, historySchema, qualitySchema, summaryContract] });
|
|
9
|
+
export const validateSummary = validator.compile(summaryContract);
|
|
10
|
+
const rowShape = validator.compile({ $ref: `${summarySchema}#/$defs/commit` });
|
|
11
|
+
export function validateSummaryIndex(value) {
|
|
12
|
+
return validateSummary(value) && validCatalog(value.metrics, value.privateMetrics)
|
|
13
|
+
&& value.commits.every(row => validCatalog(row.metrics, row.privateMetrics) && validPositions(row, value.metrics));
|
|
14
|
+
}
|
|
15
|
+
export function validateSummaryRow(value) {
|
|
16
|
+
return rowShape(value) && validCatalog(value.metrics, value.privateMetrics) && validPositions(value);
|
|
17
|
+
}
|
|
18
|
+
function validCatalog(catalog, privateMetrics = []) {
|
|
19
|
+
if (catalog && !catalog.every(isMetricDescriptor))
|
|
20
|
+
return false;
|
|
21
|
+
const ids = new Set(catalog?.map(metric => metric.id));
|
|
22
|
+
return ids.size === (catalog?.length ?? 0) && privateMetrics.every(id => ids.has(id));
|
|
23
|
+
}
|
|
24
|
+
function validPositions(row, fallback) {
|
|
25
|
+
const count = (row.metrics ?? fallback)?.length ?? 0;
|
|
26
|
+
return Object.keys(row.values ?? {}).every(key => Number(key) < count);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=summary-validation.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const compactJsonSchema = "urn:repometry:schema:compact-json:1";
|
|
2
|
+
type Node = null | boolean | number | readonly Node[];
|
|
3
|
+
export interface CompactJson {
|
|
4
|
+
readonly schema: typeof compactJsonSchema;
|
|
5
|
+
readonly strings: readonly string[];
|
|
6
|
+
readonly shapes: readonly (readonly string[])[];
|
|
7
|
+
readonly data: Node;
|
|
8
|
+
}
|
|
9
|
+
export declare function packJson(value: unknown): CompactJson;
|
|
10
|
+
export declare function unpackJson(value: unknown): unknown;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const compactJsonSchema = 'urn:repometry:schema:compact-json:1';
|
|
2
|
+
export function packJson(value) {
|
|
3
|
+
const strings = [];
|
|
4
|
+
const shapes = [];
|
|
5
|
+
const stringIds = new Map();
|
|
6
|
+
const shapeIds = new Map();
|
|
7
|
+
function pack(item, depth) {
|
|
8
|
+
if (depth > 512)
|
|
9
|
+
throw new Error('Compact JSON exceeds the nesting limit');
|
|
10
|
+
if (item === null || item === undefined)
|
|
11
|
+
return null;
|
|
12
|
+
if (typeof item === 'boolean')
|
|
13
|
+
return item;
|
|
14
|
+
if (typeof item === 'number')
|
|
15
|
+
return Number.isFinite(item) ? item : null;
|
|
16
|
+
if (typeof item === 'string') {
|
|
17
|
+
let index = stringIds.get(item);
|
|
18
|
+
if (index === undefined) {
|
|
19
|
+
index = strings.length;
|
|
20
|
+
strings.push(item);
|
|
21
|
+
stringIds.set(item, index);
|
|
22
|
+
}
|
|
23
|
+
return [0, index];
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(item))
|
|
26
|
+
return [1, ...item.map(value => pack(value, depth + 1))];
|
|
27
|
+
if (typeof item !== 'object')
|
|
28
|
+
throw new Error('Unsupported value in compact JSON');
|
|
29
|
+
const entries = Object.entries(item).filter(([, value]) => value !== undefined);
|
|
30
|
+
const keys = entries.map(([key]) => key);
|
|
31
|
+
const signature = JSON.stringify(keys);
|
|
32
|
+
let index = shapeIds.get(signature);
|
|
33
|
+
if (index === undefined) {
|
|
34
|
+
index = shapes.length;
|
|
35
|
+
shapes.push(keys);
|
|
36
|
+
shapeIds.set(signature, index);
|
|
37
|
+
}
|
|
38
|
+
return [index + 2, ...entries.map(([, value]) => pack(value, depth + 1))];
|
|
39
|
+
}
|
|
40
|
+
const data = pack(value, 0);
|
|
41
|
+
return { schema: compactJsonSchema, strings, shapes, data };
|
|
42
|
+
}
|
|
43
|
+
export function unpackJson(value) {
|
|
44
|
+
if (typeof value !== 'object' || value === null || !('schema' in value) || value.schema !== compactJsonSchema)
|
|
45
|
+
return value;
|
|
46
|
+
const candidate = value;
|
|
47
|
+
if (!Array.isArray(candidate.strings) || !candidate.strings.every(item => typeof item === 'string')
|
|
48
|
+
|| !Array.isArray(candidate.shapes) || !candidate.shapes.every(shape => Array.isArray(shape)
|
|
49
|
+
&& shape.every(key => typeof key === 'string') && new Set(shape).size === shape.length)) {
|
|
50
|
+
throw new Error('Invalid compact JSON dictionary');
|
|
51
|
+
}
|
|
52
|
+
const { strings, shapes } = candidate;
|
|
53
|
+
function unpack(item, depth) {
|
|
54
|
+
if (depth > 512)
|
|
55
|
+
throw new Error('Compact JSON exceeds the nesting limit');
|
|
56
|
+
if (item === null || typeof item === 'boolean' || typeof item === 'number')
|
|
57
|
+
return item;
|
|
58
|
+
if (!Array.isArray(item) || !Number.isSafeInteger(item[0]))
|
|
59
|
+
throw new Error('Invalid compact JSON node');
|
|
60
|
+
const [tag, ...values] = item;
|
|
61
|
+
if (tag === 0) {
|
|
62
|
+
const id = values[0];
|
|
63
|
+
if (values.length !== 1 || typeof id !== 'number' || !Number.isSafeInteger(id) || id < 0 || id >= strings.length) {
|
|
64
|
+
throw new Error('Invalid compact JSON string reference');
|
|
65
|
+
}
|
|
66
|
+
return strings[id];
|
|
67
|
+
}
|
|
68
|
+
if (tag === 1)
|
|
69
|
+
return values.map(child => unpack(child, depth + 1));
|
|
70
|
+
const keys = tag >= 2 ? shapes[tag - 2] : undefined;
|
|
71
|
+
if (!keys || keys.length !== values.length)
|
|
72
|
+
throw new Error('Invalid compact JSON object reference');
|
|
73
|
+
return Object.fromEntries(keys.map((key, index) => [key, unpack(values[index], depth + 1)]));
|
|
74
|
+
}
|
|
75
|
+
return unpack(candidate.data, 0);
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Report } from '../../../core/model/report.js';
|
|
2
|
+
import type { ChurnWindow } from '../../../core/model/churn.js';
|
|
3
|
+
import type { MetricDescriptor, MetricValues } from './summary-model.js';
|
|
4
|
+
export declare const fileMetricsSchema = "urn:repometry:schema:file-metrics:1";
|
|
5
|
+
export interface Complexity {
|
|
6
|
+
readonly sum: number;
|
|
7
|
+
readonly maximum: number | null;
|
|
8
|
+
readonly measuredFunctions: number;
|
|
9
|
+
}
|
|
10
|
+
interface LineCoverage {
|
|
11
|
+
readonly covered: number;
|
|
12
|
+
readonly total: number;
|
|
13
|
+
}
|
|
14
|
+
interface Duplication {
|
|
15
|
+
readonly duplicatedLines: number;
|
|
16
|
+
readonly codeLines: number;
|
|
17
|
+
}
|
|
18
|
+
export interface Maintainability {
|
|
19
|
+
readonly smells: number;
|
|
20
|
+
readonly effortMinutes: number | null;
|
|
21
|
+
}
|
|
22
|
+
export interface Quality {
|
|
23
|
+
codeLines?: number;
|
|
24
|
+
commentLines?: number;
|
|
25
|
+
classes?: number;
|
|
26
|
+
cognitiveComplexity?: number;
|
|
27
|
+
churn?: number;
|
|
28
|
+
duplication?: Duplication;
|
|
29
|
+
maintainability?: Maintainability;
|
|
30
|
+
}
|
|
31
|
+
export interface Metrics {
|
|
32
|
+
readonly path: string;
|
|
33
|
+
lines: number | null;
|
|
34
|
+
/** Size in bytes; absent in reports made before sizes were recorded. */
|
|
35
|
+
bytes?: number;
|
|
36
|
+
functions: number | null;
|
|
37
|
+
complexity: Complexity | null;
|
|
38
|
+
lineCoverage: LineCoverage | null;
|
|
39
|
+
diagnosticCount: number;
|
|
40
|
+
quality?: Quality;
|
|
41
|
+
values?: MetricValues;
|
|
42
|
+
language?: number;
|
|
43
|
+
analysed?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface DirectoryMetrics extends Metrics {
|
|
46
|
+
files: number;
|
|
47
|
+
sizeMeasuredFiles: number;
|
|
48
|
+
coverageMeasuredFiles: number;
|
|
49
|
+
}
|
|
50
|
+
export interface FileMetricsReport {
|
|
51
|
+
readonly schema: typeof fileMetricsSchema;
|
|
52
|
+
readonly subject: Report['subject'];
|
|
53
|
+
readonly generatedAt: string;
|
|
54
|
+
readonly status: Report['status'];
|
|
55
|
+
readonly scope: Report['scope'];
|
|
56
|
+
readonly files: readonly Metrics[];
|
|
57
|
+
readonly directories: readonly DirectoryMetrics[];
|
|
58
|
+
readonly unassignedDiagnostics: number;
|
|
59
|
+
readonly catalog?: readonly MetricDescriptor[];
|
|
60
|
+
readonly languages?: readonly {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly label?: string;
|
|
63
|
+
readonly analysed: boolean;
|
|
64
|
+
}[];
|
|
65
|
+
readonly churnWindow?: ChurnWindow & {
|
|
66
|
+
readonly lookbackDays: number;
|
|
67
|
+
readonly maxCommits: number;
|
|
68
|
+
};
|
|
69
|
+
readonly hotspots: {
|
|
70
|
+
readonly complexity: readonly string[];
|
|
71
|
+
readonly missedLines: readonly string[];
|
|
72
|
+
readonly cognitive?: readonly string[];
|
|
73
|
+
readonly duplication?: readonly string[];
|
|
74
|
+
readonly churn?: readonly string[];
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const fileMetricsSchema = 'urn:repometry:schema:file-metrics:1';
|