@dataparade/cli 0.0.32 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +56 -1
  2. package/dist/package.json +4 -3
  3. package/dist/src/cli.js +47 -4
  4. package/dist/src/diff/register-diff-command.d.ts +4 -0
  5. package/dist/src/diff/register-diff-command.js +79 -0
  6. package/dist/src/diff/run-diff.d.ts +80 -0
  7. package/dist/src/diff/run-diff.js +206 -0
  8. package/dist/src/diff/upload-diff.d.ts +26 -0
  9. package/dist/src/diff/upload-diff.js +69 -0
  10. package/dist/src/facts/apply-answers.js +1 -1
  11. package/dist/src/facts/build-facts.d.ts +3 -1
  12. package/dist/src/facts/build-facts.js +10 -1
  13. package/dist/src/facts/identity.d.ts +27 -0
  14. package/dist/src/facts/identity.js +203 -0
  15. package/dist/src/facts/io.d.ts +2 -0
  16. package/dist/src/facts/io.js +7 -0
  17. package/dist/src/facts/scan-stamps.d.ts +55 -0
  18. package/dist/src/facts/scan-stamps.js +165 -0
  19. package/dist/src/facts/schema.d.ts +243 -7
  20. package/dist/src/facts/schema.js +71 -1
  21. package/dist/src/kb/answer-fingerprint.d.ts +44 -0
  22. package/dist/src/kb/answer-fingerprint.js +173 -0
  23. package/dist/src/kb/brief.d.ts +8 -1
  24. package/dist/src/kb/brief.js +18 -2
  25. package/dist/src/kb/land.js +3 -0
  26. package/dist/src/kb/register-kb-commands.js +7 -1
  27. package/dist/src/output/git-context.d.ts +8 -0
  28. package/dist/src/output/git-context.js +18 -0
  29. package/dist/src/output/scan-output-excludes.js +5 -1
  30. package/dist/src/output/write-scan-knowledge.d.ts +2 -0
  31. package/dist/src/output/write-scan-knowledge.js +1 -0
  32. package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
  33. package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
  34. package/dist/src/platform-api/upload-client.d.ts +1 -1
  35. package/dist/src/platform-api/upload-client.js +32 -1
  36. package/dist/src/platform-api/upload.types.d.ts +55 -0
  37. package/dist/src/sensitive-scan/process.d.ts +5 -0
  38. package/dist/src/sensitive-scan/process.js +48 -0
  39. package/dist/src/sensitive-scan/project.d.ts +12 -0
  40. package/dist/src/sensitive-scan/project.js +177 -0
  41. package/dist/src/sensitive-scan/report.d.ts +50 -0
  42. package/dist/src/sensitive-scan/report.js +32 -0
  43. package/dist/src/sensitive-scan/sessions.d.ts +2 -0
  44. package/dist/src/sensitive-scan/sessions.js +120 -0
  45. package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
  46. package/dist/src/ui/scan-progress-renderer.js +8 -0
  47. package/dist/src/upload/build-preview-url.d.ts +2 -2
  48. package/dist/src/upload/build-preview-url.js +4 -4
  49. package/dist/src/upload/run-upload.js +6 -2
  50. package/dist/src/upload/types.d.ts +2 -0
  51. package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
  52. package/dist/tests/unit/diff/run-diff.spec.js +189 -0
  53. package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
  54. package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
  55. package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
  56. package/dist/tests/unit/facts/build-facts.spec.js +67 -1
  57. package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
  58. package/dist/tests/unit/facts/identity.spec.js +148 -0
  59. package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
  60. package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
  61. package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
  62. package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
  63. package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
  64. package/dist/tests/unit/output/git-context.spec.js +19 -0
  65. package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
  66. package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
  67. package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
  68. package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
  69. package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
  70. package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
  71. package/dist/tests/unit/upload/run-upload.spec.js +32 -0
  72. package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
  73. package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
  74. package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
  75. package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
  76. package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
  77. package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
  78. package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
  79. package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
  80. package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
  81. package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
  82. package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
  83. package/dist/vendor/kb-compare/dist/src/index.js +34 -0
  84. package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
  85. package/dist/vendor/kb-compare/dist/src/input.js +75 -0
  86. package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
  87. package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
  88. package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
  89. package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
  90. package/dist/vendor/kb-compare/package.json +6 -0
  91. package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
  92. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
  93. package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
  94. package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
  95. package/dist/vendor/scanner/dist/src/index.js +4 -2
  96. package/dist/vendor/scanner/package.json +3 -1
  97. package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +10 -0
  98. package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
  99. package/dist/vendor/scanner/patterns/third-party.patterns.yaml +25 -0
  100. package/package.json +4 -3
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.confidenceBand = confidenceBand;
4
+ exports.canonicalize = canonicalize;
5
+ exports.canonicalJson = canonicalJson;
6
+ exports.sha256 = sha256;
7
+ exports.modelHash = modelHash;
8
+ const crypto_1 = require("crypto");
9
+ /** low: below 0.5; medium: 0.5 to below 0.8; high: 0.8 and above. */
10
+ function confidenceBand(confidence) {
11
+ if (confidence >= 0.8)
12
+ return "high";
13
+ if (confidence >= 0.5)
14
+ return "medium";
15
+ return "low";
16
+ }
17
+ function compareStrings(a, b) {
18
+ return a < b ? -1 : a > b ? 1 : 0;
19
+ }
20
+ /** Sorts by key, then by duplicate index, so the order never depends on the input order. */
21
+ function byKey(list) {
22
+ return [...list].sort((a, b) => compareStrings(a.key, b.key) || (a.duplicateIndex ?? 1) - (b.duplicateIndex ?? 1));
23
+ }
24
+ function duplicate(identity) {
25
+ return identity.duplicateIndex ? { duplicateIndex: identity.duplicateIndex } : {};
26
+ }
27
+ const filesOf = (locations) => [...new Set((locations ?? []).map((l) => l.filePath.split("\\").join("/")))].sort(compareStrings);
28
+ function canonicalize(facts) {
29
+ const withoutIdentity = [];
30
+ const keySources = { components: {}, dataFlows: {} };
31
+ const componentKey = new Map();
32
+ const components = [];
33
+ for (const c of facts.components) {
34
+ if (!c.identity) {
35
+ withoutIdentity.push({ subject: "component", id: c.id });
36
+ continue;
37
+ }
38
+ componentKey.set(c.id, c.identity.key);
39
+ keySources.components[c.identity.key] = { parts: c.identity.parts, files: filesOf(c.sourceLocations) };
40
+ components.push({
41
+ key: c.identity.key,
42
+ ...duplicate(c.identity),
43
+ name: c.name,
44
+ type: c.type,
45
+ subType: c.subType,
46
+ confidence: confidenceBand(c.confidence),
47
+ });
48
+ }
49
+ const keyOf = (id) => componentKey.get(id) ?? `id:${id}`;
50
+ const dataFlows = [];
51
+ for (const f of facts.dataFlows) {
52
+ if (!f.identity) {
53
+ withoutIdentity.push({ subject: "dataFlow", id: f.id });
54
+ continue;
55
+ }
56
+ keySources.dataFlows[f.identity.key] = { parts: f.identity.parts, files: filesOf(f.sourceLocations) };
57
+ dataFlows.push({
58
+ key: f.identity.key,
59
+ ...duplicate(f.identity),
60
+ source: keyOf(f.sourceComponentId),
61
+ target: keyOf(f.targetComponentId),
62
+ type: f.type,
63
+ targetScope: f.targetScope ?? null,
64
+ confidence: confidenceBand(f.confidence),
65
+ });
66
+ }
67
+ const dataItems = [];
68
+ for (const item of facts.dataItems) {
69
+ if (!item.identity) {
70
+ withoutIdentity.push({ subject: "dataItem", id: item.id });
71
+ continue;
72
+ }
73
+ const groups = [];
74
+ for (const g of item.groups) {
75
+ if (!g.identity) {
76
+ withoutIdentity.push({ subject: "group", id: g.id });
77
+ continue;
78
+ }
79
+ groups.push({
80
+ key: g.identity.key,
81
+ ...duplicate(g.identity),
82
+ label: g.label,
83
+ basis: g.basis ?? null,
84
+ handledBy: [...new Set(g.handledBy.map(keyOf))].sort(compareStrings),
85
+ });
86
+ }
87
+ dataItems.push({ key: item.identity.key, labels: [...new Set(item.labels)].sort(compareStrings), groups: byKey(groups) });
88
+ }
89
+ return {
90
+ components: byKey(components),
91
+ dataFlows: byKey(dataFlows),
92
+ dataItems: byKey(dataItems),
93
+ withoutIdentity: withoutIdentity.sort((a, b) => compareStrings(a.subject, b.subject) || compareStrings(a.id, b.id)),
94
+ keySources,
95
+ };
96
+ }
97
+ /** JSON with sorted object keys, so equal values always give equal text. */
98
+ function canonicalJson(value) {
99
+ if (Array.isArray(value))
100
+ return `[${value.map(canonicalJson).join(",")}]`;
101
+ if (value && typeof value === "object") {
102
+ const entries = Object.entries(value)
103
+ .filter(([, v]) => v !== undefined)
104
+ .sort(([a], [b]) => compareStrings(a, b));
105
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
106
+ }
107
+ return JSON.stringify(value);
108
+ }
109
+ function sha256(text) {
110
+ return (0, crypto_1.createHash)("sha256").update(text, "utf8").digest("hex");
111
+ }
112
+ /**
113
+ * The model hash: `sha256:` + the SHA-256 of the canonical form without `withoutIdentity`.
114
+ * Two scans with the same model hash say the same thing, so "nothing changed" is a hash compare.
115
+ */
116
+ function modelHash(scan) {
117
+ const { withoutIdentity: _ignored, keySources: _sources, ...model } = scan;
118
+ return `sha256:${sha256(canonicalJson(model))}`;
119
+ }
@@ -0,0 +1,144 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The change set (DATAP-850): what changed between a base scan and a head scan of one
4
+ * repository. Version 1 is a draft until rename matching (DATAP-861) lands, and nothing outside
5
+ * this repository reads it yet; it is frozen at the first release.
6
+ */
7
+ export declare const SUBJECTS: readonly ["component", "dataFlow", "dataItem", "group"];
8
+ export declare const propertyChangeSchema: z.ZodObject<{
9
+ property: z.ZodString;
10
+ before: z.ZodUnknown;
11
+ after: z.ZodUnknown;
12
+ }, z.core.$strip>;
13
+ export declare const changeSchema: z.ZodObject<{
14
+ changeId: z.ZodString;
15
+ change: z.ZodEnum<{
16
+ added: "added";
17
+ removed: "removed";
18
+ modified: "modified";
19
+ renamed: "renamed";
20
+ }>;
21
+ subject: z.ZodEnum<{
22
+ component: "component";
23
+ dataFlow: "dataFlow";
24
+ dataItem: "dataItem";
25
+ group: "group";
26
+ }>;
27
+ key: z.ZodString;
28
+ previousKey: z.ZodOptional<z.ZodString>;
29
+ name: z.ZodString;
30
+ parent: z.ZodOptional<z.ZodString>;
31
+ source: z.ZodOptional<z.ZodString>;
32
+ target: z.ZodOptional<z.ZodString>;
33
+ properties: z.ZodOptional<z.ZodArray<z.ZodObject<{
34
+ property: z.ZodString;
35
+ before: z.ZodUnknown;
36
+ after: z.ZodUnknown;
37
+ }, z.core.$strip>>>;
38
+ }, z.core.$strip>;
39
+ export declare const unmatchedSchema: z.ZodObject<{
40
+ side: z.ZodEnum<{
41
+ base: "base";
42
+ head: "head";
43
+ }>;
44
+ subject: z.ZodEnum<{
45
+ component: "component";
46
+ dataFlow: "dataFlow";
47
+ dataItem: "dataItem";
48
+ group: "group";
49
+ }>;
50
+ id: z.ZodString;
51
+ reason: z.ZodEnum<{
52
+ no_identity: "no_identity";
53
+ }>;
54
+ }, z.core.$strip>;
55
+ /**
56
+ * A split or a merge (DATAP-870): one base component whose files now belong to several head
57
+ * components of the same kind and name, or the reverse. It is recorded, not resolved: the added and
58
+ * removed components stay in `changes`, and a reader decides what happened.
59
+ */
60
+ export declare const splitSchema: z.ZodObject<{
61
+ kind: z.ZodEnum<{
62
+ split: "split";
63
+ merge: "merge";
64
+ }>;
65
+ subject: z.ZodLiteral<"component">;
66
+ name: z.ZodString;
67
+ base: z.ZodArray<z.ZodString>;
68
+ head: z.ZodArray<z.ZodString>;
69
+ }, z.core.$strip>;
70
+ export declare const changeSetSchema: z.ZodObject<{
71
+ kind: z.ZodLiteral<"dataparade_change_set">;
72
+ version: z.ZodLiteral<1>;
73
+ base: z.ZodObject<{
74
+ modelHash: z.ZodString;
75
+ }, z.core.$strip>;
76
+ head: z.ZodObject<{
77
+ modelHash: z.ZodString;
78
+ }, z.core.$strip>;
79
+ unchanged: z.ZodBoolean;
80
+ configChanged: z.ZodNullable<z.ZodBoolean>;
81
+ renames: z.ZodEnum<{
82
+ not_applied: "not_applied";
83
+ applied: "applied";
84
+ no_map: "no_map";
85
+ }>;
86
+ changes: z.ZodArray<z.ZodObject<{
87
+ changeId: z.ZodString;
88
+ change: z.ZodEnum<{
89
+ added: "added";
90
+ removed: "removed";
91
+ modified: "modified";
92
+ renamed: "renamed";
93
+ }>;
94
+ subject: z.ZodEnum<{
95
+ component: "component";
96
+ dataFlow: "dataFlow";
97
+ dataItem: "dataItem";
98
+ group: "group";
99
+ }>;
100
+ key: z.ZodString;
101
+ previousKey: z.ZodOptional<z.ZodString>;
102
+ name: z.ZodString;
103
+ parent: z.ZodOptional<z.ZodString>;
104
+ source: z.ZodOptional<z.ZodString>;
105
+ target: z.ZodOptional<z.ZodString>;
106
+ properties: z.ZodOptional<z.ZodArray<z.ZodObject<{
107
+ property: z.ZodString;
108
+ before: z.ZodUnknown;
109
+ after: z.ZodUnknown;
110
+ }, z.core.$strip>>>;
111
+ }, z.core.$strip>>;
112
+ splits: z.ZodArray<z.ZodObject<{
113
+ kind: z.ZodEnum<{
114
+ split: "split";
115
+ merge: "merge";
116
+ }>;
117
+ subject: z.ZodLiteral<"component">;
118
+ name: z.ZodString;
119
+ base: z.ZodArray<z.ZodString>;
120
+ head: z.ZodArray<z.ZodString>;
121
+ }, z.core.$strip>>;
122
+ unmatched: z.ZodArray<z.ZodObject<{
123
+ side: z.ZodEnum<{
124
+ base: "base";
125
+ head: "head";
126
+ }>;
127
+ subject: z.ZodEnum<{
128
+ component: "component";
129
+ dataFlow: "dataFlow";
130
+ dataItem: "dataItem";
131
+ group: "group";
132
+ }>;
133
+ id: z.ZodString;
134
+ reason: z.ZodEnum<{
135
+ no_identity: "no_identity";
136
+ }>;
137
+ }, z.core.$strip>>;
138
+ }, z.core.$strip>;
139
+ export type PropertyChange = z.infer<typeof propertyChangeSchema>;
140
+ export type Change = z.infer<typeof changeSchema>;
141
+ export type Unmatched = z.infer<typeof unmatchedSchema>;
142
+ export type Split = z.infer<typeof splitSchema>;
143
+ export type ChangeSet = z.infer<typeof changeSetSchema>;
144
+ export type Subject = (typeof SUBJECTS)[number];
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.changeSetSchema = exports.splitSchema = exports.unmatchedSchema = exports.changeSchema = exports.propertyChangeSchema = exports.SUBJECTS = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * The change set (DATAP-850): what changed between a base scan and a head scan of one
7
+ * repository. Version 1 is a draft until rename matching (DATAP-861) lands, and nothing outside
8
+ * this repository reads it yet; it is frozen at the first release.
9
+ */
10
+ exports.SUBJECTS = ["component", "dataFlow", "dataItem", "group"];
11
+ exports.propertyChangeSchema = zod_1.z.object({
12
+ property: zod_1.z.string(),
13
+ before: zod_1.z.unknown(),
14
+ after: zod_1.z.unknown(),
15
+ });
16
+ exports.changeSchema = zod_1.z.object({
17
+ /** Stable id: a hash of `change`, `subject`, `key` and `parent`. The same change in two runs has the same id. */
18
+ changeId: zod_1.z.string().regex(/^[0-9a-f]{16}$/),
19
+ change: zod_1.z.enum(["added", "removed", "modified", "renamed"]),
20
+ subject: zod_1.z.enum(exports.SUBJECTS),
21
+ /** `identity.key` of the element: from the head for added, modified and renamed, from the base for removed. */
22
+ key: zod_1.z.string(),
23
+ /** For `renamed`: the element's key in the base. Its file paths were renamed (DATAP-866). */
24
+ previousKey: zod_1.z.string().optional(),
25
+ /** A readable name: the component name, the data item name or the group label. */
26
+ name: zod_1.z.string(),
27
+ /** For a group: the key of its data item. */
28
+ parent: zod_1.z.string().optional(),
29
+ /** For a flow: the keys of its endpoints, so a reader can name them. */
30
+ source: zod_1.z.string().optional(),
31
+ target: zod_1.z.string().optional(),
32
+ /** For `modified`: each property whose value changed. */
33
+ properties: zod_1.z.array(exports.propertyChangeSchema).optional(),
34
+ });
35
+ exports.unmatchedSchema = zod_1.z.object({
36
+ side: zod_1.z.enum(["base", "head"]),
37
+ subject: zod_1.z.enum(exports.SUBJECTS),
38
+ /** The Fact id in that scan. */
39
+ id: zod_1.z.string(),
40
+ /** `no_identity`: the scan has no identity for this Fact (CLI 0.0.32 and earlier). */
41
+ reason: zod_1.z.enum(["no_identity"]),
42
+ });
43
+ /**
44
+ * A split or a merge (DATAP-870): one base component whose files now belong to several head
45
+ * components of the same kind and name, or the reverse. It is recorded, not resolved: the added and
46
+ * removed components stay in `changes`, and a reader decides what happened.
47
+ */
48
+ exports.splitSchema = zod_1.z.object({
49
+ kind: zod_1.z.enum(["split", "merge"]),
50
+ subject: zod_1.z.literal("component"),
51
+ /** The component name (normalized, as in its key). */
52
+ name: zod_1.z.string(),
53
+ /** Base keys, before renames: one for a split. */
54
+ base: zod_1.z.array(zod_1.z.string()).min(1),
55
+ /** Head keys: one for a merge. */
56
+ head: zod_1.z.array(zod_1.z.string()).min(1),
57
+ });
58
+ exports.changeSetSchema = zod_1.z.object({
59
+ kind: zod_1.z.literal("dataparade_change_set"),
60
+ version: zod_1.z.literal(1),
61
+ base: zod_1.z.object({ modelHash: zod_1.z.string() }),
62
+ head: zod_1.z.object({ modelHash: zod_1.z.string() }),
63
+ /** True when the model hashes are equal and every Fact in both scans has an identity. `changes` is then empty. */
64
+ unchanged: zod_1.z.boolean(),
65
+ /** Whether the scan configuration differs between the two revisions; null when the caller did not say. Both sides are scanned with the head's configuration. */
66
+ configChanged: zod_1.z.boolean().nullable(),
67
+ /**
68
+ * Rename matching (DATAP-866). `applied`: base file paths were rewritten through the rename map
69
+ * from `git diff -M` before matching, so an element whose files were renamed is `renamed`.
70
+ * `no_map`: no map was given, so such an element is removed plus added. (`not_applied` is kept for
71
+ * change sets written before rename matching.)
72
+ */
73
+ renames: zod_1.z.enum(["not_applied", "applied", "no_map"]),
74
+ /** Ordered by subject (component, dataFlow, dataItem, group), then key, then change. */
75
+ changes: zod_1.z.array(exports.changeSchema),
76
+ /** Splits and merges of components, ordered by name, then first base key. */
77
+ splits: zod_1.z.array(exports.splitSchema),
78
+ /** Facts that could not be matched at all. They are not in `changes`. */
79
+ unmatched: zod_1.z.array(exports.unmatchedSchema),
80
+ });
@@ -0,0 +1,23 @@
1
+ import type { FactsInput } from "./input";
2
+ /**
3
+ * Whether two scans can be compared (DATAP-877). In v1 only scans made by the same tools, with
4
+ * the same output settings, without AI enrichment and from a clean checkout can be compared. A
5
+ * comparison of anything else would report tool or AI differences as changes to the code.
6
+ *
7
+ * The code-structure graph (Graphify, stamp `structureGraph`) is optional and not checked: it only
8
+ * adds `codeRefs`, which the comparison does not read.
9
+ */
10
+ export declare const REFUSAL_REASONS: readonly ["unstamped", "stamps_differ", "ai_enriched", "dirty"];
11
+ export type RefusalReason = (typeof REFUSAL_REASONS)[number];
12
+ export declare class ComparisonRefused extends Error {
13
+ readonly reason: RefusalReason;
14
+ constructor(reason: RefusalReason, message: string);
15
+ }
16
+ export type Comparability = {
17
+ comparable: true;
18
+ } | {
19
+ comparable: false;
20
+ reason: RefusalReason;
21
+ message: string;
22
+ };
23
+ export declare function checkComparable(base: FactsInput, head: FactsInput): Comparability;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComparisonRefused = exports.REFUSAL_REASONS = void 0;
4
+ exports.checkComparable = checkComparable;
5
+ /**
6
+ * Whether two scans can be compared (DATAP-877). In v1 only scans made by the same tools, with
7
+ * the same output settings, without AI enrichment and from a clean checkout can be compared. A
8
+ * comparison of anything else would report tool or AI differences as changes to the code.
9
+ *
10
+ * The code-structure graph (Graphify, stamp `structureGraph`) is optional and not checked: it only
11
+ * adds `codeRefs`, which the comparison does not read.
12
+ */
13
+ exports.REFUSAL_REASONS = ["unstamped", "stamps_differ", "ai_enriched", "dirty"];
14
+ /** The stamps that must be equal on both sides. */
15
+ const TOOL_STAMPS = ["scannerCommit", "cliVersion", "catalogHash", "configHash"];
16
+ class ComparisonRefused extends Error {
17
+ constructor(reason, message) {
18
+ super(message);
19
+ this.reason = reason;
20
+ this.name = "ComparisonRefused";
21
+ }
22
+ }
23
+ exports.ComparisonRefused = ComparisonRefused;
24
+ function checkComparable(base, head) {
25
+ const refuse = (reason, message) => ({ comparable: false, reason, message });
26
+ const sides = [
27
+ ["base", base.scan?.stamps],
28
+ ["head", head.scan?.stamps],
29
+ ];
30
+ for (const [side, stamps] of sides) {
31
+ if (!stamps)
32
+ return refuse("unstamped", `The ${side} scan has no stamps (CLI 0.0.32 and earlier); scan it again with a newer CLI.`);
33
+ }
34
+ const [b, h] = [base.scan.stamps, head.scan.stamps];
35
+ const differ = TOOL_STAMPS.filter((name) => b[name] !== h[name]);
36
+ if (differ.length > 0) {
37
+ return refuse("stamps_differ", `The scans were made with different ${differ.join(", ")}: ${differ.map((n) => `${b[n]} vs ${h[n]}`).join("; ")}.`);
38
+ }
39
+ for (const [side, stamps] of sides) {
40
+ if (stamps.aiInference)
41
+ return refuse("ai_enriched", `The ${side} scan had AI enrichment; in v1 only scans made with AI off can be compared.`);
42
+ }
43
+ for (const [side, stamps] of sides) {
44
+ if (stamps.dirty === true)
45
+ return refuse("dirty", `The ${side} scan was made from a checkout with changes that were not committed.`);
46
+ }
47
+ return { comparable: true };
48
+ }
@@ -0,0 +1,52 @@
1
+ import { type ChangeSet } from "./change-set";
2
+ /** One renamed file, from `git diff -M` (`renames.json` of `dataparade diff`). */
3
+ export interface Rename {
4
+ from: string;
5
+ to: string;
6
+ }
7
+ export interface CompareOptions {
8
+ /**
9
+ * Renamed files between base and head (DATAP-866). Base file paths in keys and references are
10
+ * rewritten through it before matching. Leave it out when no map exists.
11
+ */
12
+ renames?: Rename[];
13
+ /** Whether the scan configuration differs between the two revisions. Unknown when left out. */
14
+ configChanged?: boolean;
15
+ /**
16
+ * Refuse pairs that cannot be compared (DATAP-877), with `ComparisonRefused`. Default true.
17
+ * Only tests of scans made before stamps existed turn it off.
18
+ */
19
+ checkStamps?: boolean;
20
+ }
21
+ interface Keyed {
22
+ key: string;
23
+ duplicateIndex?: number;
24
+ /** Set on base elements whose key the rename map changed: the key before the rewrite. */
25
+ previousKey?: string;
26
+ }
27
+ /** The key without its `#n` duplicate marker. */
28
+ export declare function baseKey(element: Keyed): string;
29
+ interface Matched<T> {
30
+ pairs: Array<[T, T]>;
31
+ removed: T[];
32
+ added: T[];
33
+ }
34
+ /**
35
+ * Matches elements by base key (DATAP-853). Elements that share a base key are compared as one
36
+ * group, never by their duplicate number, because that number follows source position: within a
37
+ * group, identical elements match first, then the rest pair up in duplicate order, and any extra
38
+ * element is added or removed.
39
+ */
40
+ export declare function matchByKey<T extends Keyed>(base: T[], head: T[]): Matched<T>;
41
+ /**
42
+ * Rewrites renamed file paths in a key or reference. A path matches only as a whole segment of the
43
+ * key: between the separators keys use (`|`, `"`, `{`, `}`, `@`, `#`, `,`, `[`, `]`) or the ends.
44
+ */
45
+ export declare function rewritePaths(text: string, renames: readonly Rename[]): string;
46
+ /**
47
+ * Compares two scans of one repository (DATAP-847). `base` and `head` are parsed `facts.json`
48
+ * values. The result follows `changeSetSchema`. Throws `ComparisonRefused` when the pair cannot be
49
+ * compared (DATAP-877).
50
+ */
51
+ export declare function compareScans(base: unknown, head: unknown, options?: CompareOptions): ChangeSet;
52
+ export {};