mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-22 10:32:40 +08:00
feat(ql3): establish 3.0 incubation baseline
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
export interface LegacyExecutionIdentity {
|
||||
pid?: number;
|
||||
logArtifactId?: string;
|
||||
}
|
||||
|
||||
export function selectOneLegacyExecution<T extends LegacyExecutionIdentity>(
|
||||
candidates: readonly T[],
|
||||
selector: LegacyExecutionIdentity,
|
||||
): T[] {
|
||||
const byLog =
|
||||
selector.logArtifactId === undefined
|
||||
? []
|
||||
: candidates.filter(
|
||||
(candidate) => candidate.logArtifactId === selector.logArtifactId,
|
||||
);
|
||||
const byPid =
|
||||
selector.pid === undefined
|
||||
? []
|
||||
: candidates.filter((candidate) => candidate.pid === selector.pid);
|
||||
|
||||
if (selector.logArtifactId !== undefined && selector.pid !== undefined) {
|
||||
const byPidSet = new Set(byPid);
|
||||
const intersection = byLog.filter((candidate) => byPidSet.has(candidate));
|
||||
if (intersection.length === 1) return intersection;
|
||||
if (intersection.length > 1) return [];
|
||||
if (byLog.length === 0 && byPid.length === 1) return byPid;
|
||||
if (byPid.length === 0 && byLog.length === 1) return byLog;
|
||||
if (byLog.length === 0 && byPid.length === 0) {
|
||||
return candidates.length === 1 ? [...candidates] : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
if (selector.logArtifactId !== undefined) {
|
||||
if (byLog.length === 1) return byLog;
|
||||
return byLog.length === 0 && candidates.length === 1 ? [...candidates] : [];
|
||||
}
|
||||
if (selector.pid !== undefined) {
|
||||
if (byPid.length === 1) return byPid;
|
||||
return byPid.length === 0 && candidates.length === 1 ? [...candidates] : [];
|
||||
}
|
||||
return candidates.length === 1 ? [...candidates] : [];
|
||||
}
|
||||
Reference in New Issue
Block a user