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.
- package/.claude/skills/ucn/SKILL.md +77 -0
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/cli/index.js +2437 -0
- package/core/discovery.js +513 -0
- package/core/imports.js +558 -0
- package/core/output.js +1274 -0
- package/core/parser.js +279 -0
- package/core/project.js +3261 -0
- package/index.js +52 -0
- package/languages/go.js +653 -0
- package/languages/index.js +267 -0
- package/languages/java.js +826 -0
- package/languages/javascript.js +1346 -0
- package/languages/python.js +667 -0
- package/languages/rust.js +950 -0
- package/languages/utils.js +457 -0
- package/package.json +42 -0
- package/test/fixtures/go/go.mod +3 -0
- package/test/fixtures/go/main.go +257 -0
- package/test/fixtures/go/service.go +187 -0
- package/test/fixtures/java/DataService.java +279 -0
- package/test/fixtures/java/Main.java +287 -0
- package/test/fixtures/java/Utils.java +199 -0
- package/test/fixtures/java/pom.xml +6 -0
- package/test/fixtures/javascript/main.js +109 -0
- package/test/fixtures/javascript/package.json +1 -0
- package/test/fixtures/javascript/service.js +88 -0
- package/test/fixtures/javascript/utils.js +67 -0
- package/test/fixtures/python/main.py +198 -0
- package/test/fixtures/python/pyproject.toml +3 -0
- package/test/fixtures/python/service.py +166 -0
- package/test/fixtures/python/utils.py +118 -0
- package/test/fixtures/rust/Cargo.toml +3 -0
- package/test/fixtures/rust/main.rs +253 -0
- package/test/fixtures/rust/service.rs +210 -0
- package/test/fixtures/rust/utils.rs +154 -0
- package/test/fixtures/typescript/main.ts +154 -0
- package/test/fixtures/typescript/package.json +1 -0
- package/test/fixtures/typescript/repository.ts +149 -0
- package/test/fixtures/typescript/types.ts +114 -0
- package/test/parser.test.js +3661 -0
- package/test/public-repos-test.js +477 -0
- package/test/systematic-test.js +619 -0
- package/ucn.js +8 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main TypeScript test fixtures.
|
|
3
|
+
* Tests interfaces, generics, enums, and type annotations.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Repository, DataService } from './repository';
|
|
7
|
+
import { Config, Logger, LogLevel } from './types';
|
|
8
|
+
|
|
9
|
+
// Enum definition
|
|
10
|
+
enum Status {
|
|
11
|
+
Pending = 'pending',
|
|
12
|
+
Active = 'active',
|
|
13
|
+
Completed = 'completed',
|
|
14
|
+
Failed = 'failed'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Interface
|
|
18
|
+
interface Task {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
status: Status;
|
|
22
|
+
priority: number;
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Type alias
|
|
27
|
+
type TaskFilter = (task: Task) => boolean;
|
|
28
|
+
type TaskTransformer<T> = (task: Task) => T;
|
|
29
|
+
|
|
30
|
+
// Generic function
|
|
31
|
+
function filterTasks<T extends Task>(tasks: T[], predicate: TaskFilter): T[] {
|
|
32
|
+
return tasks.filter(predicate);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Generic class
|
|
36
|
+
class TaskManager<T extends Task> {
|
|
37
|
+
private tasks: T[] = [];
|
|
38
|
+
private repository: Repository<T>;
|
|
39
|
+
private logger: Logger;
|
|
40
|
+
|
|
41
|
+
constructor(config: Config) {
|
|
42
|
+
this.repository = new Repository<T>(config);
|
|
43
|
+
this.logger = new Logger(config.logLevel || LogLevel.Info);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async addTask(task: T): Promise<void> {
|
|
47
|
+
this.logger.info(`Adding task: ${task.name}`);
|
|
48
|
+
this.tasks.push(task);
|
|
49
|
+
await this.repository.save(task);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async getTasks(filter?: TaskFilter): Promise<T[]> {
|
|
53
|
+
const allTasks = await this.repository.findAll();
|
|
54
|
+
if (filter) {
|
|
55
|
+
return filterTasks(allTasks, filter);
|
|
56
|
+
}
|
|
57
|
+
return allTasks;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async updateTask(id: string, updates: Partial<T>): Promise<T | null> {
|
|
61
|
+
const task = await this.repository.findById(id);
|
|
62
|
+
if (!task) {
|
|
63
|
+
this.logger.warn(`Task not found: ${id}`);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const updated = { ...task, ...updates };
|
|
67
|
+
await this.repository.save(updated);
|
|
68
|
+
return updated;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async deleteTask(id: string): Promise<boolean> {
|
|
72
|
+
this.logger.info(`Deleting task: ${id}`);
|
|
73
|
+
return this.repository.delete(id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
transformTasks<R>(transformer: TaskTransformer<R>): R[] {
|
|
77
|
+
return this.tasks.map(transformer);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Async generator
|
|
82
|
+
async function* taskGenerator(manager: TaskManager<Task>): AsyncGenerator<Task> {
|
|
83
|
+
const tasks = await manager.getTasks();
|
|
84
|
+
for (const task of tasks) {
|
|
85
|
+
yield task;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Utility functions
|
|
90
|
+
function createTask(name: string, priority: number = 1): Task {
|
|
91
|
+
return {
|
|
92
|
+
id: generateId(),
|
|
93
|
+
name,
|
|
94
|
+
status: Status.Pending,
|
|
95
|
+
priority
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function generateId(): string {
|
|
100
|
+
return Math.random().toString(36).substring(2, 15);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Higher-order function with generics
|
|
104
|
+
function withRetry<T>(
|
|
105
|
+
fn: () => Promise<T>,
|
|
106
|
+
retries: number = 3
|
|
107
|
+
): () => Promise<T> {
|
|
108
|
+
return async () => {
|
|
109
|
+
let lastError: Error | null = null;
|
|
110
|
+
for (let i = 0; i < retries; i++) {
|
|
111
|
+
try {
|
|
112
|
+
return await fn();
|
|
113
|
+
} catch (err) {
|
|
114
|
+
lastError = err as Error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
throw lastError;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Overloaded function
|
|
122
|
+
function processTask(task: Task): string;
|
|
123
|
+
function processTask(tasks: Task[]): string[];
|
|
124
|
+
function processTask(input: Task | Task[]): string | string[] {
|
|
125
|
+
if (Array.isArray(input)) {
|
|
126
|
+
return input.map(t => t.name);
|
|
127
|
+
}
|
|
128
|
+
return input.name;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Decorator-style function (for class methods)
|
|
132
|
+
function logged(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
133
|
+
const original = descriptor.value;
|
|
134
|
+
descriptor.value = function(...args: any[]) {
|
|
135
|
+
console.log(`Calling ${propertyKey}`);
|
|
136
|
+
return original.apply(this, args);
|
|
137
|
+
};
|
|
138
|
+
return descriptor;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
Status,
|
|
143
|
+
Task,
|
|
144
|
+
TaskFilter,
|
|
145
|
+
TaskTransformer,
|
|
146
|
+
TaskManager,
|
|
147
|
+
filterTasks,
|
|
148
|
+
taskGenerator,
|
|
149
|
+
createTask,
|
|
150
|
+
generateId,
|
|
151
|
+
withRetry,
|
|
152
|
+
processTask,
|
|
153
|
+
logged
|
|
154
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "typescript-fixtures", "version": "1.0.0"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository pattern implementation with generics.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Config, Logger, LogLevel } from './types';
|
|
6
|
+
|
|
7
|
+
// Generic interface for entities
|
|
8
|
+
interface Entity {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Repository interface
|
|
13
|
+
interface IRepository<T extends Entity> {
|
|
14
|
+
save(entity: T): Promise<void>;
|
|
15
|
+
findById(id: string): Promise<T | null>;
|
|
16
|
+
findAll(): Promise<T[]>;
|
|
17
|
+
delete(id: string): Promise<boolean>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Abstract base class
|
|
21
|
+
abstract class BaseRepository<T extends Entity> implements IRepository<T> {
|
|
22
|
+
protected logger: Logger;
|
|
23
|
+
|
|
24
|
+
constructor(protected config: Config) {
|
|
25
|
+
this.logger = new Logger(config.logLevel || LogLevel.Info);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
abstract save(entity: T): Promise<void>;
|
|
29
|
+
abstract findById(id: string): Promise<T | null>;
|
|
30
|
+
abstract findAll(): Promise<T[]>;
|
|
31
|
+
abstract delete(id: string): Promise<boolean>;
|
|
32
|
+
|
|
33
|
+
protected logOperation(operation: string, entity?: T): void {
|
|
34
|
+
this.logger.debug(`${operation}: ${entity?.id || 'unknown'}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Concrete repository implementation
|
|
39
|
+
class Repository<T extends Entity> extends BaseRepository<T> {
|
|
40
|
+
private storage: Map<string, T> = new Map();
|
|
41
|
+
|
|
42
|
+
constructor(config: Config) {
|
|
43
|
+
super(config);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async save(entity: T): Promise<void> {
|
|
47
|
+
this.logOperation('save', entity);
|
|
48
|
+
this.storage.set(entity.id, entity);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async findById(id: string): Promise<T | null> {
|
|
52
|
+
this.logOperation('findById');
|
|
53
|
+
return this.storage.get(id) || null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async findAll(): Promise<T[]> {
|
|
57
|
+
this.logOperation('findAll');
|
|
58
|
+
return Array.from(this.storage.values());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async delete(id: string): Promise<boolean> {
|
|
62
|
+
this.logOperation('delete');
|
|
63
|
+
return this.storage.delete(id);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async findWhere(predicate: (entity: T) => boolean): Promise<T[]> {
|
|
67
|
+
const all = await this.findAll();
|
|
68
|
+
return all.filter(predicate);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
clear(): void {
|
|
72
|
+
this.storage.clear();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Data service that uses repository
|
|
77
|
+
class DataService<T extends Entity> {
|
|
78
|
+
private repository: Repository<T>;
|
|
79
|
+
|
|
80
|
+
constructor(config: Config) {
|
|
81
|
+
this.repository = new Repository<T>(config);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async create(entity: T): Promise<T> {
|
|
85
|
+
await this.repository.save(entity);
|
|
86
|
+
return entity;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async get(id: string): Promise<T | null> {
|
|
90
|
+
return this.repository.findById(id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async list(): Promise<T[]> {
|
|
94
|
+
return this.repository.findAll();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async remove(id: string): Promise<boolean> {
|
|
98
|
+
return this.repository.delete(id);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async query(predicate: (entity: T) => boolean): Promise<T[]> {
|
|
102
|
+
return this.repository.findWhere(predicate);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Caching repository decorator
|
|
107
|
+
class CachedRepository<T extends Entity> implements IRepository<T> {
|
|
108
|
+
private cache: Map<string, T> = new Map();
|
|
109
|
+
|
|
110
|
+
constructor(private wrapped: IRepository<T>) {}
|
|
111
|
+
|
|
112
|
+
async save(entity: T): Promise<void> {
|
|
113
|
+
this.cache.set(entity.id, entity);
|
|
114
|
+
await this.wrapped.save(entity);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async findById(id: string): Promise<T | null> {
|
|
118
|
+
if (this.cache.has(id)) {
|
|
119
|
+
return this.cache.get(id)!;
|
|
120
|
+
}
|
|
121
|
+
const entity = await this.wrapped.findById(id);
|
|
122
|
+
if (entity) {
|
|
123
|
+
this.cache.set(id, entity);
|
|
124
|
+
}
|
|
125
|
+
return entity;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async findAll(): Promise<T[]> {
|
|
129
|
+
return this.wrapped.findAll();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async delete(id: string): Promise<boolean> {
|
|
133
|
+
this.cache.delete(id);
|
|
134
|
+
return this.wrapped.delete(id);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
clearCache(): void {
|
|
138
|
+
this.cache.clear();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
Entity,
|
|
144
|
+
IRepository,
|
|
145
|
+
BaseRepository,
|
|
146
|
+
Repository,
|
|
147
|
+
DataService,
|
|
148
|
+
CachedRepository
|
|
149
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions and utility types.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Log levels enum
|
|
6
|
+
export enum LogLevel {
|
|
7
|
+
Debug = 0,
|
|
8
|
+
Info = 1,
|
|
9
|
+
Warn = 2,
|
|
10
|
+
Error = 3
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Configuration interface
|
|
14
|
+
export interface Config {
|
|
15
|
+
apiUrl?: string;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
logLevel?: LogLevel;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
retries?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Utility types
|
|
23
|
+
export type Nullable<T> = T | null;
|
|
24
|
+
export type Optional<T> = T | undefined;
|
|
25
|
+
export type DeepPartial<T> = {
|
|
26
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Result type for error handling
|
|
30
|
+
export type Result<T, E = Error> =
|
|
31
|
+
| { success: true; value: T }
|
|
32
|
+
| { success: false; error: E };
|
|
33
|
+
|
|
34
|
+
// Event types
|
|
35
|
+
export interface Event<T = unknown> {
|
|
36
|
+
type: string;
|
|
37
|
+
payload: T;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type EventHandler<T = unknown> = (event: Event<T>) => void | Promise<void>;
|
|
42
|
+
|
|
43
|
+
// Logger class
|
|
44
|
+
export class Logger {
|
|
45
|
+
private level: LogLevel;
|
|
46
|
+
|
|
47
|
+
constructor(level: LogLevel = LogLevel.Info) {
|
|
48
|
+
this.level = level;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private log(level: LogLevel, message: string, ...args: unknown[]): void {
|
|
52
|
+
if (level >= this.level) {
|
|
53
|
+
const prefix = LogLevel[level].toUpperCase();
|
|
54
|
+
console.log(`[${prefix}] ${message}`, ...args);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
debug(message: string, ...args: unknown[]): void {
|
|
59
|
+
this.log(LogLevel.Debug, message, ...args);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
info(message: string, ...args: unknown[]): void {
|
|
63
|
+
this.log(LogLevel.Info, message, ...args);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
warn(message: string, ...args: unknown[]): void {
|
|
67
|
+
this.log(LogLevel.Warn, message, ...args);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
error(message: string, ...args: unknown[]): void {
|
|
71
|
+
this.log(LogLevel.Error, message, ...args);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setLevel(level: LogLevel): void {
|
|
75
|
+
this.level = level;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Type guards
|
|
80
|
+
export function isError(value: unknown): value is Error {
|
|
81
|
+
return value instanceof Error;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function isResult<T>(value: unknown): value is Result<T> {
|
|
85
|
+
return (
|
|
86
|
+
typeof value === 'object' &&
|
|
87
|
+
value !== null &&
|
|
88
|
+
'success' in value
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Factory function
|
|
93
|
+
export function createConfig(overrides?: Partial<Config>): Config {
|
|
94
|
+
return {
|
|
95
|
+
apiUrl: 'https://api.example.com',
|
|
96
|
+
timeout: 5000,
|
|
97
|
+
logLevel: LogLevel.Info,
|
|
98
|
+
debug: false,
|
|
99
|
+
retries: 3,
|
|
100
|
+
...overrides
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Utility function with generics
|
|
105
|
+
export function unwrapResult<T>(result: Result<T>): T {
|
|
106
|
+
if (result.success) {
|
|
107
|
+
return result.value;
|
|
108
|
+
}
|
|
109
|
+
throw result.error;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Mapped type example
|
|
113
|
+
export type ReadonlyConfig = Readonly<Config>;
|
|
114
|
+
export type ConfigKeys = keyof Config;
|