ucn 3.0.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.

Potentially problematic release.


This version of ucn might be problematic. Click here for more details.

Files changed (45) hide show
  1. package/.claude/skills/ucn/SKILL.md +77 -0
  2. package/LICENSE +21 -0
  3. package/README.md +135 -0
  4. package/cli/index.js +2437 -0
  5. package/core/discovery.js +513 -0
  6. package/core/imports.js +558 -0
  7. package/core/output.js +1274 -0
  8. package/core/parser.js +279 -0
  9. package/core/project.js +3261 -0
  10. package/index.js +52 -0
  11. package/languages/go.js +653 -0
  12. package/languages/index.js +267 -0
  13. package/languages/java.js +826 -0
  14. package/languages/javascript.js +1346 -0
  15. package/languages/python.js +667 -0
  16. package/languages/rust.js +950 -0
  17. package/languages/utils.js +457 -0
  18. package/package.json +42 -0
  19. package/test/fixtures/go/go.mod +3 -0
  20. package/test/fixtures/go/main.go +257 -0
  21. package/test/fixtures/go/service.go +187 -0
  22. package/test/fixtures/java/DataService.java +279 -0
  23. package/test/fixtures/java/Main.java +287 -0
  24. package/test/fixtures/java/Utils.java +199 -0
  25. package/test/fixtures/java/pom.xml +6 -0
  26. package/test/fixtures/javascript/main.js +109 -0
  27. package/test/fixtures/javascript/package.json +1 -0
  28. package/test/fixtures/javascript/service.js +88 -0
  29. package/test/fixtures/javascript/utils.js +67 -0
  30. package/test/fixtures/python/main.py +198 -0
  31. package/test/fixtures/python/pyproject.toml +3 -0
  32. package/test/fixtures/python/service.py +166 -0
  33. package/test/fixtures/python/utils.py +118 -0
  34. package/test/fixtures/rust/Cargo.toml +3 -0
  35. package/test/fixtures/rust/main.rs +253 -0
  36. package/test/fixtures/rust/service.rs +210 -0
  37. package/test/fixtures/rust/utils.rs +154 -0
  38. package/test/fixtures/typescript/main.ts +154 -0
  39. package/test/fixtures/typescript/package.json +1 -0
  40. package/test/fixtures/typescript/repository.ts +149 -0
  41. package/test/fixtures/typescript/types.ts +114 -0
  42. package/test/parser.test.js +3661 -0
  43. package/test/public-repos-test.js +477 -0
  44. package/test/systematic-test.js +619 -0
  45. package/ucn.js +8 -0
@@ -0,0 +1,287 @@
1
+ package fixtures;
2
+
3
+ import java.util.*;
4
+ import java.util.concurrent.CompletableFuture;
5
+ import java.util.function.Function;
6
+ import java.util.function.Predicate;
7
+ import java.util.stream.Collectors;
8
+
9
+ /**
10
+ * Main Java test fixtures.
11
+ * Tests classes, interfaces, generics, and annotations.
12
+ */
13
+ public class Main {
14
+
15
+ /**
16
+ * Status enum representing task states.
17
+ */
18
+ public enum Status {
19
+ PENDING("pending"),
20
+ ACTIVE("active"),
21
+ COMPLETED("completed"),
22
+ FAILED("failed");
23
+
24
+ private final String value;
25
+
26
+ Status(String value) {
27
+ this.value = value;
28
+ }
29
+
30
+ public String getValue() {
31
+ return value;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Task class representing a task entity.
37
+ */
38
+ public static class Task {
39
+ private String id;
40
+ private String name;
41
+ private Status status;
42
+ private int priority;
43
+ private Map<String, Object> metadata;
44
+
45
+ public Task(String id, String name) {
46
+ this.id = id;
47
+ this.name = name;
48
+ this.status = Status.PENDING;
49
+ this.priority = 1;
50
+ this.metadata = new HashMap<>();
51
+ }
52
+
53
+ public String getId() {
54
+ return id;
55
+ }
56
+
57
+ public String getName() {
58
+ return name;
59
+ }
60
+
61
+ public void setName(String name) {
62
+ this.name = name;
63
+ }
64
+
65
+ public Status getStatus() {
66
+ return status;
67
+ }
68
+
69
+ public void setStatus(Status status) {
70
+ this.status = status;
71
+ }
72
+
73
+ public int getPriority() {
74
+ return priority;
75
+ }
76
+
77
+ public void setPriority(int priority) {
78
+ this.priority = priority;
79
+ }
80
+
81
+ public Map<String, Object> getMetadata() {
82
+ return metadata;
83
+ }
84
+
85
+ public boolean isComplete() {
86
+ return status == Status.COMPLETED;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Generic task manager class.
92
+ * @param <T> The task type
93
+ */
94
+ public static class TaskManager<T extends Task> {
95
+ private final List<T> tasks;
96
+ private final DataService<T> service;
97
+
98
+ public TaskManager(DataService<T> service) {
99
+ this.tasks = new ArrayList<>();
100
+ this.service = service;
101
+ }
102
+
103
+ public void addTask(T task) throws ValidationException {
104
+ validateTask(task);
105
+ tasks.add(task);
106
+ }
107
+
108
+ public Optional<T> getTask(String id) {
109
+ return tasks.stream()
110
+ .filter(t -> t.getId().equals(id))
111
+ .findFirst();
112
+ }
113
+
114
+ public List<T> getTasks(Predicate<T> filter) {
115
+ if (filter == null) {
116
+ return new ArrayList<>(tasks);
117
+ }
118
+ return tasks.stream()
119
+ .filter(filter)
120
+ .collect(Collectors.toList());
121
+ }
122
+
123
+ public Optional<T> updateTask(String id, String name, Status status) {
124
+ return getTask(id).map(task -> {
125
+ if (name != null) {
126
+ task.setName(name);
127
+ }
128
+ if (status != null) {
129
+ task.setStatus(status);
130
+ }
131
+ return task;
132
+ });
133
+ }
134
+
135
+ public boolean deleteTask(String id) {
136
+ return tasks.removeIf(t -> t.getId().equals(id));
137
+ }
138
+
139
+ public CompletableFuture<Integer> syncTasks() {
140
+ return CompletableFuture.supplyAsync(() -> {
141
+ int count = 0;
142
+ for (T task : tasks) {
143
+ service.save(task);
144
+ count++;
145
+ }
146
+ return count;
147
+ });
148
+ }
149
+
150
+ public int count() {
151
+ return tasks.size();
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Validate a task.
157
+ */
158
+ public static void validateTask(Task task) throws ValidationException {
159
+ if (task == null) {
160
+ throw new ValidationException("Task cannot be null");
161
+ }
162
+ if (task.getId() == null || task.getId().isEmpty()) {
163
+ throw new ValidationException("Task ID is required");
164
+ }
165
+ if (task.getName() == null || task.getName().isEmpty()) {
166
+ throw new ValidationException("Task name is required");
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Custom exception for validation errors.
172
+ */
173
+ public static class ValidationException extends Exception {
174
+ public ValidationException(String message) {
175
+ super(message);
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Factory method to create a task.
181
+ */
182
+ public static Task createTask(String name, int priority) {
183
+ String id = generateId();
184
+ Task task = new Task(id, name);
185
+ task.setPriority(priority);
186
+ return task;
187
+ }
188
+
189
+ private static int idCounter = 0;
190
+
191
+ /**
192
+ * Generate a unique ID.
193
+ */
194
+ private static synchronized String generateId() {
195
+ return "task-" + (idCounter++);
196
+ }
197
+
198
+ /**
199
+ * Filter tasks by status.
200
+ */
201
+ public static List<Task> filterByStatus(List<Task> tasks, Status status) {
202
+ return tasks.stream()
203
+ .filter(t -> t.getStatus() == status)
204
+ .collect(Collectors.toList());
205
+ }
206
+
207
+ /**
208
+ * Filter tasks by minimum priority.
209
+ */
210
+ public static List<Task> filterByPriority(List<Task> tasks, int minPriority) {
211
+ return tasks.stream()
212
+ .filter(t -> t.getPriority() >= minPriority)
213
+ .collect(Collectors.toList());
214
+ }
215
+
216
+ /**
217
+ * Task processor class.
218
+ */
219
+ public static class TaskProcessor {
220
+ private final TaskManager<Task> manager;
221
+
222
+ public TaskProcessor(TaskManager<Task> manager) {
223
+ this.manager = manager;
224
+ }
225
+
226
+ public List<Map<String, Object>> processAll() {
227
+ return manager.getTasks(null).stream()
228
+ .map(this::processTask)
229
+ .collect(Collectors.toList());
230
+ }
231
+
232
+ public List<Map<String, Object>> processPending() {
233
+ return manager.getTasks(t -> t.getStatus() == Status.PENDING).stream()
234
+ .map(this::processTask)
235
+ .collect(Collectors.toList());
236
+ }
237
+
238
+ private Map<String, Object> processTask(Task task) {
239
+ return formatTask(task);
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Format a task as a map.
245
+ */
246
+ public static Map<String, Object> formatTask(Task task) {
247
+ Map<String, Object> map = new HashMap<>();
248
+ map.put("id", task.getId());
249
+ map.put("name", task.getName());
250
+ map.put("status", task.getStatus().getValue());
251
+ map.put("priority", task.getPriority());
252
+ return map;
253
+ }
254
+
255
+ /**
256
+ * Higher-order function example.
257
+ */
258
+ public static <T, R> Function<T, R> withLogging(Function<T, R> fn, String name) {
259
+ return input -> {
260
+ System.out.println("Calling " + name);
261
+ R result = fn.apply(input);
262
+ System.out.println("Finished " + name);
263
+ return result;
264
+ };
265
+ }
266
+
267
+ /**
268
+ * Unused method for deadcode detection.
269
+ */
270
+ @SuppressWarnings("unused")
271
+ private static String unusedMethod() {
272
+ return "never used";
273
+ }
274
+
275
+ public static void main(String[] args) {
276
+ DataService<Task> service = new DataService<>();
277
+ TaskManager<Task> manager = new TaskManager<>(service);
278
+
279
+ try {
280
+ Task task = createTask("Test Task", 1);
281
+ manager.addTask(task);
282
+ System.out.println("Created " + manager.count() + " tasks");
283
+ } catch (ValidationException e) {
284
+ System.err.println("Validation error: " + e.getMessage());
285
+ }
286
+ }
287
+ }
@@ -0,0 +1,199 @@
1
+ package fixtures;
2
+
3
+ import java.util.*;
4
+ import java.util.function.Function;
5
+ import java.util.stream.Collectors;
6
+
7
+ /**
8
+ * Utility functions for data manipulation.
9
+ */
10
+ public class Utils {
11
+
12
+ /**
13
+ * Format data as a map.
14
+ */
15
+ public static Map<String, Object> formatData(Object data) {
16
+ if (data == null) {
17
+ return new HashMap<>();
18
+ }
19
+ if (data instanceof Map) {
20
+ return new HashMap<>((Map<String, Object>) data);
21
+ }
22
+ Map<String, Object> result = new HashMap<>();
23
+ result.put("value", data);
24
+ return result;
25
+ }
26
+
27
+ /**
28
+ * Validate that a value is not null.
29
+ */
30
+ public static <T> T validateNotNull(T value, String message) {
31
+ if (value == null) {
32
+ throw new IllegalArgumentException(message);
33
+ }
34
+ return value;
35
+ }
36
+
37
+ /**
38
+ * Deep merge two maps.
39
+ */
40
+ public static Map<String, Object> deepMerge(
41
+ Map<String, Object> base,
42
+ Map<String, Object> updates) {
43
+ Map<String, Object> result = new HashMap<>(base);
44
+ for (Map.Entry<String, Object> entry : updates.entrySet()) {
45
+ String key = entry.getKey();
46
+ Object value = entry.getValue();
47
+ if (result.containsKey(key) &&
48
+ result.get(key) instanceof Map &&
49
+ value instanceof Map) {
50
+ result.put(key, deepMerge(
51
+ (Map<String, Object>) result.get(key),
52
+ (Map<String, Object>) value
53
+ ));
54
+ } else {
55
+ result.put(key, value);
56
+ }
57
+ }
58
+ return result;
59
+ }
60
+
61
+ /**
62
+ * Flatten a nested list.
63
+ */
64
+ public static <T> List<T> flatten(List<List<T>> nested) {
65
+ return nested.stream()
66
+ .flatMap(List::stream)
67
+ .collect(Collectors.toList());
68
+ }
69
+
70
+ /**
71
+ * Split a list into chunks.
72
+ */
73
+ public static <T> List<List<T>> chunk(List<T> items, int size) {
74
+ List<List<T>> chunks = new ArrayList<>();
75
+ for (int i = 0; i < items.size(); i += size) {
76
+ chunks.add(items.subList(i, Math.min(i + size, items.size())));
77
+ }
78
+ return chunks;
79
+ }
80
+
81
+ /**
82
+ * Safely get a nested value from a map.
83
+ */
84
+ public static Object safeGet(Map<String, Object> map, String path) {
85
+ String[] keys = path.split("\\.");
86
+ Object current = map;
87
+ for (String key : keys) {
88
+ if (current instanceof Map) {
89
+ current = ((Map<String, Object>) current).get(key);
90
+ } else {
91
+ return null;
92
+ }
93
+ }
94
+ return current;
95
+ }
96
+
97
+ /**
98
+ * Transform all keys in a map.
99
+ */
100
+ public static Map<String, Object> transformKeys(
101
+ Map<String, Object> map,
102
+ Function<String, String> transformer) {
103
+ Map<String, Object> result = new HashMap<>();
104
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
105
+ result.put(transformer.apply(entry.getKey()), entry.getValue());
106
+ }
107
+ return result;
108
+ }
109
+
110
+ /**
111
+ * Convert snake_case to camelCase.
112
+ */
113
+ public static String snakeToCamel(String name) {
114
+ StringBuilder result = new StringBuilder();
115
+ boolean capitalizeNext = false;
116
+ for (char c : name.toCharArray()) {
117
+ if (c == '_') {
118
+ capitalizeNext = true;
119
+ } else if (capitalizeNext) {
120
+ result.append(Character.toUpperCase(c));
121
+ capitalizeNext = false;
122
+ } else {
123
+ result.append(c);
124
+ }
125
+ }
126
+ return result.toString();
127
+ }
128
+
129
+ /**
130
+ * Convert camelCase to snake_case.
131
+ */
132
+ public static String camelToSnake(String name) {
133
+ StringBuilder result = new StringBuilder();
134
+ for (char c : name.toCharArray()) {
135
+ if (Character.isUpperCase(c)) {
136
+ if (result.length() > 0) {
137
+ result.append('_');
138
+ }
139
+ result.append(Character.toLowerCase(c));
140
+ } else {
141
+ result.append(c);
142
+ }
143
+ }
144
+ return result.toString();
145
+ }
146
+
147
+ /**
148
+ * Data transformer class.
149
+ */
150
+ public static class DataTransformer {
151
+ private final List<Function<Object, Object>> transformations;
152
+
153
+ public DataTransformer() {
154
+ this.transformations = new ArrayList<>();
155
+ }
156
+
157
+ /**
158
+ * Add a transformation.
159
+ */
160
+ public DataTransformer addTransformation(Function<Object, Object> fn) {
161
+ transformations.add(fn);
162
+ return this;
163
+ }
164
+
165
+ /**
166
+ * Apply all transformations.
167
+ */
168
+ public Object transform(Object data) {
169
+ Object result = data;
170
+ for (Function<Object, Object> fn : transformations) {
171
+ result = fn.apply(result);
172
+ }
173
+ return result;
174
+ }
175
+
176
+ /**
177
+ * Clear all transformations.
178
+ */
179
+ public void clear() {
180
+ transformations.clear();
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Process and format data.
186
+ */
187
+ public static Map<String, Object> processAndFormat(Object data) {
188
+ Object validated = validateNotNull(data, "Data cannot be null");
189
+ return formatData(validated);
190
+ }
191
+
192
+ /**
193
+ * Unused method for deadcode detection.
194
+ */
195
+ @SuppressWarnings("unused")
196
+ private static void unusedHelper() {
197
+ // This method is never called
198
+ }
199
+ }
@@ -0,0 +1,6 @@
1
+ <project>
2
+ <modelVersion>4.0.0</modelVersion>
3
+ <groupId>fixtures</groupId>
4
+ <artifactId>java-fixtures</artifactId>
5
+ <version>1.0.0</version>
6
+ </project>
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Main entry point for the JavaScript test fixtures.
3
+ * Tests various JavaScript constructs.
4
+ */
5
+
6
+ const { helper, utilFunc } = require('./utils');
7
+ const Service = require('./service');
8
+
9
+ // Constants
10
+ const CONFIG = {
11
+ timeout: 5000,
12
+ retries: 3
13
+ };
14
+
15
+ /**
16
+ * Process data using the helper function.
17
+ * @param {Object} data - Input data
18
+ * @returns {Object} Processed data
19
+ */
20
+ function processData(data) {
21
+ const validated = validateInput(data);
22
+ const result = helper(validated);
23
+ return transformOutput(result);
24
+ }
25
+
26
+ // Arrow function
27
+ const validateInput = (input) => {
28
+ if (!input) {
29
+ throw new Error('Input is required');
30
+ }
31
+ return { ...input, validated: true };
32
+ };
33
+
34
+ /**
35
+ * Transform the output data.
36
+ */
37
+ function transformOutput(data) {
38
+ return {
39
+ ...data,
40
+ transformed: true,
41
+ timestamp: Date.now()
42
+ };
43
+ }
44
+
45
+ // Async function
46
+ async function fetchAndProcess(url) {
47
+ const service = new Service();
48
+ const response = await service.fetch(url);
49
+ return processData(response);
50
+ }
51
+
52
+ // Higher-order function
53
+ function createProcessor(transformer) {
54
+ return function(data) {
55
+ const processed = processData(data);
56
+ return transformer(processed);
57
+ };
58
+ }
59
+
60
+ // Function with callback
61
+ function processWithCallback(data, callback) {
62
+ try {
63
+ const result = processData(data);
64
+ callback(null, result);
65
+ } catch (err) {
66
+ callback(err, null);
67
+ }
68
+ }
69
+
70
+ // Generator function
71
+ function* dataGenerator(items) {
72
+ for (const item of items) {
73
+ yield processData(item);
74
+ }
75
+ }
76
+
77
+ // Class usage
78
+ class DataProcessor {
79
+ constructor(config = CONFIG) {
80
+ this.config = config;
81
+ this.service = new Service();
82
+ }
83
+
84
+ async process(data) {
85
+ return fetchAndProcess(data);
86
+ }
87
+
88
+ static create(config) {
89
+ return new DataProcessor(config);
90
+ }
91
+ }
92
+
93
+ // Immediately invoked
94
+ const initialized = (function() {
95
+ return { ready: true };
96
+ })();
97
+
98
+ // Default export simulation
99
+ module.exports = {
100
+ processData,
101
+ validateInput,
102
+ transformOutput,
103
+ fetchAndProcess,
104
+ createProcessor,
105
+ processWithCallback,
106
+ dataGenerator,
107
+ DataProcessor,
108
+ CONFIG
109
+ };
@@ -0,0 +1 @@
1
+ {"name": "javascript-fixtures", "version": "1.0.0"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Service class for external operations.
3
+ */
4
+
5
+ const { deepClone, mergeObjects } = require('./utils');
6
+
7
+ class Service {
8
+ constructor(options = {}) {
9
+ this.baseUrl = options.baseUrl || 'https://api.example.com';
10
+ this.timeout = options.timeout || 5000;
11
+ this.headers = mergeObjects({ 'Content-Type': 'application/json' }, options.headers || {});
12
+ }
13
+
14
+ /**
15
+ * Fetch data from a URL.
16
+ * @param {string} url - The URL to fetch
17
+ * @returns {Promise<Object>} The response data
18
+ */
19
+ async fetch(url) {
20
+ const fullUrl = this.buildUrl(url);
21
+ const response = await this.makeRequest(fullUrl);
22
+ return this.parseResponse(response);
23
+ }
24
+
25
+ /**
26
+ * Build the full URL.
27
+ */
28
+ buildUrl(path) {
29
+ if (path.startsWith('http')) {
30
+ return path;
31
+ }
32
+ return `${this.baseUrl}${path}`;
33
+ }
34
+
35
+ /**
36
+ * Make the HTTP request.
37
+ */
38
+ async makeRequest(url) {
39
+ // Simulated request
40
+ return {
41
+ status: 200,
42
+ data: { url, timestamp: Date.now() }
43
+ };
44
+ }
45
+
46
+ /**
47
+ * Parse the response data.
48
+ */
49
+ parseResponse(response) {
50
+ if (response.status !== 200) {
51
+ throw new Error(`Request failed: ${response.status}`);
52
+ }
53
+ return deepClone(response.data);
54
+ }
55
+
56
+ /**
57
+ * Post data to a URL.
58
+ */
59
+ async post(url, data) {
60
+ const fullUrl = this.buildUrl(url);
61
+ const response = await this.makeRequest(fullUrl, 'POST', data);
62
+ return this.parseResponse(response);
63
+ }
64
+ }
65
+
66
+ // Singleton instance
67
+ let instance = null;
68
+
69
+ /**
70
+ * Get the singleton service instance.
71
+ */
72
+ function getService(options) {
73
+ if (!instance) {
74
+ instance = new Service(options);
75
+ }
76
+ return instance;
77
+ }
78
+
79
+ /**
80
+ * Reset the singleton (for testing).
81
+ */
82
+ function resetService() {
83
+ instance = null;
84
+ }
85
+
86
+ module.exports = Service;
87
+ module.exports.getService = getService;
88
+ module.exports.resetService = resetService;