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

graphty-org / graphty-element / 20514590651

26 Dec 2025 02:37AM UTC coverage: 70.559% (-0.3%) from 70.836%
20514590651

push

github

apowers313
ci: fix npm ci

9591 of 13363 branches covered (71.77%)

Branch coverage included in aggregate %.

25136 of 35854 relevant lines covered (70.11%)

6233.71 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";
10✔
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
 * @param queueOperation - Function to queue operations with category and execution logic
53
 * @param category - The category of the operation being queued
54
 * @param method - The method to be wrapped with queue support
55
 * @param getDescription - Optional function to generate a description from method arguments
56
 * @returns The wrapped method with queue support
57
 */
58
export function wrapWithQueue<T extends (... args: unknown[]) => unknown>(
×
59
    queueOperation: (category: OperationCategory, execute: (context: OperationContext) => Promise<void> | void, metadata?: Record<string, unknown>) => string,
×
60
    category: OperationCategory,
×
61
    method: T,
×
62
    getDescription?: (... args: Parameters<T>) => string,
×
63
): T {
×
64
    return (async(... args: Parameters<T>): Promise<ReturnType<T>> => {
×
65
        // Check if last argument contains queue options
66
        const lastArg = args[args.length - 1];
×
67
        const hasQueueOptions = lastArg && typeof lastArg === "object" &&
×
68
            ("skipQueue" in lastArg || "description" in lastArg || "obsoletes" in lastArg);
×
69

70
        const options: QueueableOptions = hasQueueOptions ? (lastArg as QueueableOptions) : {};
×
71

72
        if (options.skipQueue) {
×
73
            // Execute directly without queuing
74
            return method(... args) as ReturnType<T>;
×
75
        }
×
76

77
        // Default description if not provided
78
        const description = options.description ?? (getDescription ? getDescription(... args) : undefined);
×
79

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

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

108
/**
109
 * Helper to create a batch operation context
110
 */
111
export class BatchOperationContext {
×
112
    private operations: (() => Promise<void>)[] = [];
×
113

114
    /**
115
     * Add an operation to the batch
116
     * @param operation - Async operation to add to the batch
117
     */
118
    add(operation: () => Promise<void>): void {
×
119
        this.operations.push(operation);
×
120
    }
×
121

122
    /**
123
     * Execute all batched operations sequentially
124
     */
125
    async execute(): Promise<void> {
×
126
        for (const operation of this.operations) {
×
127
            await operation();
×
128
        }
×
129
    }
×
130

131
    /**
132
     * Get the number of operations in the batch
133
     * @returns The count of pending operations
134
     */
135
    get count(): number {
×
136
        return this.operations.length;
×
137
    }
×
138
}
×
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

© 2025 Coveralls, Inc