• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphty-org / graphty-element / 20194755040

13 Dec 2025 04:28PM UTC coverage: 86.405% (+0.02%) from 86.388%
20194755040

push

github

apowers313
Merge branch 'master' of https://github.com/graphty-org/graphty-element

3688 of 4321 branches covered (85.35%)

Branch coverage included in aggregate %.

17476 of 20173 relevant lines covered (86.63%)

8620.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.85
/src/utils/queue-migration.ts
1
import type {OperationCategory, OperationContext} from "../managers/OperationQueueManager";
1✔
2

3
export interface QueueableOptions {
4
    /**
5
     * Skip the operation queue and execute immediately (for backwards compatibility)
6
     */
7
    skipQueue?: boolean;
8

9
    /**
10
     * Custom description for the operation (for debugging/logging)
11
     */
12
    description?: string;
13

14
    /**
15
     * Categories that this operation should obsolete
16
     */
17
    obsoletes?: OperationCategory[];
18

19
    /**
20
     * Whether to respect progress when obsoleting (don't cancel >90% complete)
21
     */
22
    respectProgress?: boolean;
23
}
24

25
/**
26
 * Algorithm-specific options (source, target, startNode, etc.)
27
 * These are passed through to the algorithm's configure method.
28
 */
29
export interface AlgorithmSpecificOptions {
30
    source?: string | number;
31
    target?: string | number;
32
    startNode?: string | number;
33
    sink?: string | number;
34
    [key: string]: unknown;
35
}
36

37
export interface RunAlgorithmOptions extends QueueableOptions {
38
    /**
39
     * Automatically apply suggested styles after running the algorithm
40
     */
41
    applySuggestedStyles?: boolean;
42

43
    /**
44
     * Algorithm-specific options (source, target, etc.)
45
     * These are passed to the algorithm's configure method.
46
     */
47
    algorithmOptions?: AlgorithmSpecificOptions;
48
}
49

50
/**
51
 * Helper to wrap a method with queue support while maintaining backwards compatibility
52
 */
53
export function wrapWithQueue<T extends (... args: unknown[]) => unknown>(
×
54
    queueOperation: (category: OperationCategory, execute: (context: OperationContext) => Promise<void> | void, metadata?: Record<string, unknown>) => string,
×
55
    category: OperationCategory,
×
56
    method: T,
×
57
    getDescription?: (... args: Parameters<T>) => string,
×
58
): T {
×
59
    return (async(... args: Parameters<T>): Promise<ReturnType<T>> => {
×
60
        // Check if last argument contains queue options
61
        const lastArg = args[args.length - 1];
×
62
        const hasQueueOptions = lastArg && typeof lastArg === "object" &&
×
63
            ("skipQueue" in lastArg || "description" in lastArg || "obsoletes" in lastArg);
×
64

65
        const options: QueueableOptions = hasQueueOptions ? (lastArg as QueueableOptions) : {};
×
66

67
        if (options.skipQueue) {
×
68
            // Execute directly without queuing
69
            return method(... args) as ReturnType<T>;
×
70
        }
×
71

72
        // Default description if not provided
73
        const description = options.description ?? (getDescription ? getDescription(... args) : undefined);
×
74

75
        // Queue the operation
76
        return new Promise((resolve, reject) => {
×
77
            queueOperation(
×
78
                category,
×
79
                async(context) => {
×
80
                    try {
×
81
                        // Check for cancellation
82
                        if (context.signal.aborted) {
×
83
                            reject(new Error("Operation cancelled"));
×
84
                            return;
×
85
                        }
×
86

87
                        const result = await method(... args);
×
88
                        resolve(result as ReturnType<T>);
×
89
                    } catch (error) {
×
90
                        reject(error instanceof Error ? error : new Error(String(error)));
×
91
                    }
×
92
                },
×
93
                {
×
94
                    description,
×
95
                    obsoletes: options.obsoletes,
×
96
                    respectProgress: options.respectProgress,
×
97
                },
×
98
            );
×
99
        });
×
100
    }) as T;
×
101
}
×
102

103
/**
104
 * Helper to create a batch operation context
105
 */
106
export class BatchOperationContext {
×
107
    private operations: (() => Promise<void>)[] = [];
×
108

109
    add(operation: () => Promise<void>): void {
×
110
        this.operations.push(operation);
×
111
    }
×
112

113
    async execute(): Promise<void> {
×
114
        for (const operation of this.operations) {
×
115
            await operation();
×
116
        }
×
117
    }
×
118

119
    get count(): number {
×
120
        return this.operations.length;
×
121
    }
×
122
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc