@saptools/service-flow 0.1.53 → 0.1.54

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.
@@ -23,6 +23,25 @@ export function projectBounded<T>(
23
23
  };
24
24
  }
25
25
 
26
+ /**
27
+ * Evidence producers establish semantic order before calling the generic
28
+ * recursive bounder. Re-sorting here would make a selected decision appear
29
+ * to be explained by a different candidate.
30
+ */
31
+ export function projectBoundedInOrder<T>(
32
+ values: readonly T[],
33
+ limit = DEFAULT_EVIDENCE_CANDIDATE_LIMIT,
34
+ ): BoundedProjection<T> {
35
+ const normalizedLimit = positiveLimit(limit);
36
+ const items = values.slice(0, normalizedLimit);
37
+ return {
38
+ totalCount: values.length,
39
+ shownCount: items.length,
40
+ omittedCount: Math.max(0, values.length - items.length),
41
+ items,
42
+ };
43
+ }
44
+
26
45
  export function positiveLimit(value: number | undefined): number {
27
46
  return Number.isFinite(value) && Number(value) > 0
28
47
  ? Math.floor(Number(value))
@@ -73,7 +92,7 @@ export function boundCandidateLikeEvidence(
73
92
  output[key] = boundNestedEvidence(value, limit);
74
93
  continue;
75
94
  }
76
- const projection = projectBounded(value, compareEvidenceValue, limit);
95
+ const projection = projectBoundedInOrder(value, limit);
77
96
  output[key] = projection.items.map((item) => boundNestedEvidence(item, limit));
78
97
  addCollectionCounts(output, evidence, key, projection);
79
98
  }
@@ -138,20 +157,6 @@ function collectionStem(key: string): string {
138
157
  return stems[key] ?? 'candidate';
139
158
  }
140
159
 
141
- function compareEvidenceValue(left: unknown, right: unknown): number {
142
- return stableProjectionValue(left).localeCompare(stableProjectionValue(right));
143
- }
144
-
145
- export function stableProjectionValue(value: unknown): string {
146
- if (Array.isArray(value))
147
- return `[${value.map(stableProjectionValue).join(',')}]`;
148
- if (isEvidenceRecord(value)) {
149
- return `{${Object.keys(value).sort().map((key) =>
150
- `${JSON.stringify(key)}:${stableProjectionValue(value[key])}`).join(',')}}`;
151
- }
152
- return JSON.stringify(value) ?? '';
153
- }
154
-
155
160
  function numericValue(value: unknown): number {
156
161
  return typeof value === 'number' && Number.isFinite(value) ? value : 0;
157
162
  }