Home / Class/ ResolveSelectNamed Class — drizzle-orm Architecture

ResolveSelectNamed Class — drizzle-orm Architecture

Architecture documentation for the ResolveSelectNamed class in views.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  293df77e_078e_46e3_943d_76b30d99a2f0["ResolveSelectNamed"]
  217e2cbd_4fb7_ceab_251c_5733ece08a8f["views.ts"]
  293df77e_078e_46e3_943d_76b30d99a2f0 -->|defined in| 217e2cbd_4fb7_ceab_251c_5733ece08a8f
  4dd6678c_ebb3_5de5_a0d9_cea74560e7e2["constructor()"]
  293df77e_078e_46e3_943d_76b30d99a2f0 -->|method| 4dd6678c_ebb3_5de5_a0d9_cea74560e7e2
  44745ed9_988e_1fa0_cc99_28dbd533cd76["render()"]
  293df77e_078e_46e3_943d_76b30d99a2f0 -->|method| 44745ed9_988e_1fa0_cc99_28dbd533cd76
  e36d6b47_7feb_2ae2_ed5f_59273d2dc424["result()"]
  293df77e_078e_46e3_943d_76b30d99a2f0 -->|method| e36d6b47_7feb_2ae2_ed5f_59273d2dc424

Relationship Graph

Source Code

drizzle-kit/src/cli/views.ts lines 167–236

export class ResolveSelectNamed<T extends Named> extends Prompt<
	RenamePropmtItem<T> | T
> {
	private readonly state: SelectState<RenamePropmtItem<T> | T>;

	constructor(
		private readonly base: T,
		data: (RenamePropmtItem<T> | T)[],
		private readonly entityType: 'role' | 'policy',
	) {
		super();
		this.on('attach', (terminal) => terminal.toggleCursor('hide'));
		this.state = new SelectState(data);
		this.state.bind(this);
		this.base = base;
	}

	render(status: 'idle' | 'submitted' | 'aborted'): string {
		if (status === 'submitted' || status === 'aborted') {
			return '';
		}
		const key = this.base.name;

		let text = `\nIs ${chalk.bold.blue(key)} ${this.entityType} created or renamed from another ${this.entityType}?\n`;

		const isSelectedRenamed = isRenamePromptItem(
			this.state.items[this.state.selectedIdx],
		);

		const selectedPrefix = isSelectedRenamed
			? chalk.yellow('❯ ')
			: chalk.green('❯ ');

		const labelLength: number = this.state.items
			.filter((it) => isRenamePromptItem(it))
			.map((_) => {
				const it = _ as RenamePropmtItem<T>;
				const keyFrom = it.from.name;
				return key.length + 3 + keyFrom.length;
			})
			.reduce((a, b) => {
				if (a > b) {
					return a;
				}
				return b;
			}, 0);

		const entityType = this.entityType;
		this.state.items.forEach((it, idx) => {
			const isSelected = idx === this.state.selectedIdx;
			const isRenamed = isRenamePromptItem(it);

			const title = isRenamed
				? `${it.from.name} › ${it.to.name}`.padEnd(labelLength, ' ')
				: it.name.padEnd(labelLength, ' ');

			const label = isRenamed
				? `${chalk.yellow('~')} ${title} ${chalk.gray(`rename ${entityType}`)}`
				: `${chalk.green('+')} ${title} ${chalk.gray(`create ${entityType}`)}`;

			text += isSelected ? `${selectedPrefix}${label}` : `  ${label}`;
			text += idx != this.state.items.length - 1 ? '\n' : '';
		});
		return text;
	}

	result(): RenamePropmtItem<T> | T {
		return this.state.items[this.state.selectedIdx]!;
	}
}

Domain

Frequently Asked Questions

What is the ResolveSelectNamed class?
ResolveSelectNamed is a class in the drizzle-orm codebase, defined in drizzle-kit/src/cli/views.ts.
Where is ResolveSelectNamed defined?
ResolveSelectNamed is defined in drizzle-kit/src/cli/views.ts at line 167.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free