micro-contracts 0.17.7 → 0.17.8
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.
|
@@ -8,6 +8,7 @@ export interface BuildInsightOptions {
|
|
|
8
8
|
configPath?: string;
|
|
9
9
|
}
|
|
10
10
|
export declare function buildExternalInsight(projectRoot: string, options?: BuildInsightOptions): ExternalInsight;
|
|
11
|
+
export declare function filterInsight(insight: ExternalInsight, query: InsightQuery): ExternalInsight;
|
|
11
12
|
export declare class MicroContractsInsightProvider implements InsightProvider {
|
|
12
13
|
readonly name = "micro-contracts";
|
|
13
14
|
provide(query: InsightQuery): Promise<ExternalInsight>;
|
|
@@ -231,10 +231,42 @@ export function buildExternalInsight(projectRoot, options = {}) {
|
|
|
231
231
|
anchorMapping: [...anchorByDomain.values()],
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
|
+
export function filterInsight(insight, query) {
|
|
235
|
+
const { changedFiles, artifactIds } = query;
|
|
236
|
+
if (!changedFiles?.length && !artifactIds?.length)
|
|
237
|
+
return insight;
|
|
238
|
+
const relevantIds = new Set();
|
|
239
|
+
if (changedFiles?.length) {
|
|
240
|
+
const changedSet = new Set(changedFiles);
|
|
241
|
+
for (const anchor of insight.anchorMapping ?? []) {
|
|
242
|
+
if (anchor.filePaths.some((fp) => changedSet.has(fp))) {
|
|
243
|
+
relevantIds.add(anchor.domainId);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (artifactIds?.length) {
|
|
248
|
+
for (const id of artifactIds) {
|
|
249
|
+
relevantIds.add(id);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const filteredEdges = insight.edges.filter((e) => relevantIds.has(e.from) || relevantIds.has(e.to));
|
|
253
|
+
const referencedIds = new Set();
|
|
254
|
+
for (const edge of filteredEdges) {
|
|
255
|
+
referencedIds.add(edge.from);
|
|
256
|
+
referencedIds.add(edge.to);
|
|
257
|
+
}
|
|
258
|
+
const filteredAnchors = (insight.anchorMapping ?? []).filter((a) => referencedIds.has(a.domainId));
|
|
259
|
+
return {
|
|
260
|
+
...insight,
|
|
261
|
+
edges: filteredEdges,
|
|
262
|
+
anchorMapping: filteredAnchors.length > 0 ? filteredAnchors : undefined,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
234
265
|
export class MicroContractsInsightProvider {
|
|
235
266
|
name = MICRO_CONTRACTS_INSIGHT_SOURCE;
|
|
236
267
|
async provide(query) {
|
|
237
|
-
|
|
268
|
+
const insight = buildExternalInsight(query.projectRoot);
|
|
269
|
+
return filterInsight(insight, query);
|
|
238
270
|
}
|
|
239
271
|
}
|
|
240
272
|
export const microContractsInsightProvider = new MicroContractsInsightProvider();
|