@elisra-devops/docgen-data-provider 1.132.0 → 1.134.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.
@@ -362,5 +362,17 @@ export default class TicketsDataProvider {
362
362
  * @returns An object containing the categorized requirements and total processed count.
363
363
  */
364
364
  GetCategorizedRequirementsByType(wiqlHref: string): Promise<any>;
365
+ /**
366
+ * Returns per-side valid column lists for trace analysis Column Settings dialog.
367
+ * Uses the WIT field schema (~6 ADO calls, constant cost) to determine which
368
+ * declared query columns are valid for the Requirement side vs the Test Case side.
369
+ *
370
+ * Known limitation: assumes one WIT type per side (determined by sampling the first
371
+ * source + first target work item). Trace queries are single-type per side in practice.
372
+ */
373
+ GetTraceColumnsByType(reqTestWiqlHref: string | undefined, testReqWiqlHref: string | undefined, project: string): Promise<{
374
+ Requirement: any[];
375
+ 'Test Case': any[];
376
+ }>;
365
377
  }
366
378
  export {};
@@ -2767,6 +2767,122 @@ class TicketsDataProvider {
2767
2767
  throw err;
2768
2768
  }
2769
2769
  }
2770
+ /**
2771
+ * Returns per-side valid column lists for trace analysis Column Settings dialog.
2772
+ * Uses the WIT field schema (~6 ADO calls, constant cost) to determine which
2773
+ * declared query columns are valid for the Requirement side vs the Test Case side.
2774
+ *
2775
+ * Known limitation: assumes one WIT type per side (determined by sampling the first
2776
+ * source + first target work item). Trace queries are single-type per side in practice.
2777
+ */
2778
+ async GetTraceColumnsByType(reqTestWiqlHref, testReqWiqlHref, project) {
2779
+ const normalizeCols = (columns) => (columns || []).map((c) => ({
2780
+ referenceName: c.referenceName,
2781
+ name: c.name,
2782
+ }));
2783
+ const mergeCols = (a, b) => {
2784
+ const seen = new Set();
2785
+ const result = [];
2786
+ for (const col of [...a, ...b]) {
2787
+ if (!seen.has(col.referenceName)) {
2788
+ seen.add(col.referenceName);
2789
+ result.push(col);
2790
+ }
2791
+ }
2792
+ return result;
2793
+ };
2794
+ // Sample one work item to read its System.WorkItemType.
2795
+ // In OneHop query relations: !relation.source means root (target = source WI);
2796
+ // relation.source present means link (target = target WI).
2797
+ const sampleWitType = async (relations, isSource) => {
2798
+ var _a, _b, _c;
2799
+ let url;
2800
+ if (isSource) {
2801
+ const rootRel = relations.find((r) => { var _a; return !r.source && ((_a = r.target) === null || _a === void 0 ? void 0 : _a.url); });
2802
+ url = (_a = rootRel === null || rootRel === void 0 ? void 0 : rootRel.target) === null || _a === void 0 ? void 0 : _a.url;
2803
+ }
2804
+ else {
2805
+ const linkRel = relations.find((r) => { var _a; return r.source && ((_a = r.target) === null || _a === void 0 ? void 0 : _a.url); });
2806
+ url = (_b = linkRel === null || linkRel === void 0 ? void 0 : linkRel.target) === null || _b === void 0 ? void 0 : _b.url;
2807
+ }
2808
+ if (!url)
2809
+ return undefined;
2810
+ try {
2811
+ const wi = await tfs_1.TFSServices.getItemContent(url, this.token);
2812
+ return (_c = wi === null || wi === void 0 ? void 0 : wi.fields) === null || _c === void 0 ? void 0 : _c['System.WorkItemType'];
2813
+ }
2814
+ catch (_d) {
2815
+ return undefined;
2816
+ }
2817
+ };
2818
+ const fetchTypeFieldSet = async (typeName) => {
2819
+ var _a;
2820
+ const query = new URLSearchParams({ 'api-version': '5.1' }).toString();
2821
+ const url = `${this.orgUrl}${encodeURIComponent(project)}/_apis/wit/workitemtypes/${encodeURIComponent(typeName)}/fields?${query}`;
2822
+ const res = await tfs_1.TFSServices.getItemContent(url, this.token);
2823
+ const fields = (_a = res === null || res === void 0 ? void 0 : res.value) !== null && _a !== void 0 ? _a : [];
2824
+ return new Set(fields.map((f) => f.referenceName));
2825
+ };
2826
+ try {
2827
+ // Step 1: fetch declared columns from provided query hrefs
2828
+ let reqTestCols = [];
2829
+ let testReqCols = [];
2830
+ let reqTestRelations = [];
2831
+ let testReqRelations = [];
2832
+ if (reqTestWiqlHref) {
2833
+ const qr = await tfs_1.TFSServices.getItemContent(reqTestWiqlHref, this.token);
2834
+ reqTestCols = normalizeCols((qr === null || qr === void 0 ? void 0 : qr.columns) || []);
2835
+ reqTestRelations = (qr === null || qr === void 0 ? void 0 : qr.workItemRelations) || [];
2836
+ }
2837
+ if (testReqWiqlHref) {
2838
+ const qr = await tfs_1.TFSServices.getItemContent(testReqWiqlHref, this.token);
2839
+ testReqCols = normalizeCols((qr === null || qr === void 0 ? void 0 : qr.columns) || []);
2840
+ testReqRelations = (qr === null || qr === void 0 ? void 0 : qr.workItemRelations) || [];
2841
+ }
2842
+ const declaredCols = mergeCols(reqTestCols, testReqCols);
2843
+ if (declaredCols.length === 0) {
2844
+ return { Requirement: [], 'Test Case': [] };
2845
+ }
2846
+ // Step 2: sample WIT type names
2847
+ // reqTest: source = Requirement, target = Test Case
2848
+ // testReq: source = Test Case, target = Requirement
2849
+ let reqTypeName;
2850
+ let tcTypeName;
2851
+ if (reqTestRelations.length > 0) {
2852
+ [reqTypeName, tcTypeName] = await Promise.all([
2853
+ sampleWitType(reqTestRelations, true),
2854
+ sampleWitType(reqTestRelations, false),
2855
+ ]);
2856
+ }
2857
+ if ((!reqTypeName || !tcTypeName) && testReqRelations.length > 0) {
2858
+ const [tSrc, tTgt] = await Promise.all([
2859
+ sampleWitType(testReqRelations, true),
2860
+ sampleWitType(testReqRelations, false),
2861
+ ]);
2862
+ if (!tcTypeName)
2863
+ tcTypeName = tSrc;
2864
+ if (!reqTypeName)
2865
+ reqTypeName = tTgt;
2866
+ }
2867
+ if (!reqTypeName || !tcTypeName) {
2868
+ logger_1.default.warn('GetTraceColumnsByType: could not determine WIT type names — returning merged columns');
2869
+ return { Requirement: declaredCols, 'Test Case': declaredCols };
2870
+ }
2871
+ // Step 3: fetch WIT field schemas and intersect with declared columns
2872
+ const [reqFieldSet, tcFieldSet] = await Promise.all([
2873
+ fetchTypeFieldSet(reqTypeName),
2874
+ fetchTypeFieldSet(tcTypeName),
2875
+ ]);
2876
+ return {
2877
+ Requirement: declaredCols.filter((c) => reqFieldSet.has(c.referenceName)),
2878
+ 'Test Case': declaredCols.filter((c) => tcFieldSet.has(c.referenceName)),
2879
+ };
2880
+ }
2881
+ catch (err) {
2882
+ logger_1.default.error(`GetTraceColumnsByType failed: ${err.message}`);
2883
+ return { Requirement: [], 'Test Case': [] };
2884
+ }
2885
+ }
2770
2886
  }
2771
2887
  exports.default = TicketsDataProvider;
2772
2888
  //# sourceMappingURL=TicketsDataProvider.js.map