style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
+37
-10
@@ -19,7 +19,13 @@ export interface CategoryTemplate {
|
||||
}
|
||||
|
||||
const BASE_COLUMNS: SQLiteColumnDefinition[] = [
|
||||
{ name: "id", type: "INTEGER", primaryKey: true, notNull: true, editable: false },
|
||||
{
|
||||
name: "id",
|
||||
type: "INTEGER",
|
||||
primaryKey: true,
|
||||
notNull: true,
|
||||
editable: false,
|
||||
},
|
||||
{ name: "nome", type: "TEXT", notNull: true, editable: true },
|
||||
{ name: "image_url", type: "TEXT", editable: true },
|
||||
{ name: "image_local_path", type: "TEXT", editable: true },
|
||||
@@ -50,7 +56,9 @@ function getDatabase(): any {
|
||||
return cachedDatabase;
|
||||
}
|
||||
|
||||
function normalizeColumnType(type: SQLiteColumnType | string): SQLiteColumnType {
|
||||
function normalizeColumnType(
|
||||
type: SQLiteColumnType | string,
|
||||
): SQLiteColumnType {
|
||||
const upper = type.toUpperCase();
|
||||
switch (upper) {
|
||||
case "INTEGER":
|
||||
@@ -82,7 +90,9 @@ function ensureImageDirectory(category: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function mapPragmaColumns(columns: Array<{ name: string; type: string; notnull: number; pk: number }>): SQLiteColumnDefinition[] {
|
||||
function mapPragmaColumns(
|
||||
columns: Array<{ name: string; type: string; notnull: number; pk: number }>,
|
||||
): SQLiteColumnDefinition[] {
|
||||
const mapped = columns.map((column) => {
|
||||
const baseMatch = BASE_COLUMNS.find((base) => base.name === column.name);
|
||||
return {
|
||||
@@ -100,11 +110,15 @@ function mapPragmaColumns(columns: Array<{ name: string; type: string; notnull:
|
||||
export function listCategoryTemplates(): CategoryTemplate[] {
|
||||
const db = getDatabase();
|
||||
const tables = db
|
||||
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")
|
||||
.prepare(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'",
|
||||
)
|
||||
.all() as Array<{ name: string }>;
|
||||
|
||||
return tables.map((table) => {
|
||||
const pragma = db.prepare(`PRAGMA table_info(${table.name})`).all() as Array<{
|
||||
const pragma = db
|
||||
.prepare(`PRAGMA table_info(${table.name})`)
|
||||
.all() as Array<{
|
||||
name: string;
|
||||
type: string;
|
||||
notnull: number;
|
||||
@@ -124,7 +138,9 @@ export function listCategoryTemplates(): CategoryTemplate[] {
|
||||
|
||||
function validateCategoryName(name: string) {
|
||||
if (!/^[a-z0-9_]+$/i.test(name)) {
|
||||
throw new Error("Nome da categoria deve conter apenas letras, números ou sublinhado.");
|
||||
throw new Error(
|
||||
"Nome da categoria deve conter apenas letras, números ou sublinhado.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +149,9 @@ export interface CreateCategoryInput {
|
||||
columns?: SQLiteColumnDefinition[];
|
||||
}
|
||||
|
||||
export function createCategoryTemplate(input: CreateCategoryInput): CategoryTemplate {
|
||||
export function createCategoryTemplate(
|
||||
input: CreateCategoryInput,
|
||||
): CategoryTemplate {
|
||||
const db = getDatabase();
|
||||
const name = input.name.trim().toLowerCase();
|
||||
validateCategoryName(name);
|
||||
@@ -184,7 +202,9 @@ export interface AddColumnInput {
|
||||
column: SQLiteColumnDefinition;
|
||||
}
|
||||
|
||||
export function addColumnToCategory(input: AddColumnInput): SQLiteColumnDefinition {
|
||||
export function addColumnToCategory(
|
||||
input: AddColumnInput,
|
||||
): SQLiteColumnDefinition {
|
||||
const db = getDatabase();
|
||||
const name = input.category.trim().toLowerCase();
|
||||
validateCategoryName(name);
|
||||
@@ -262,7 +282,11 @@ export function insertCategoryItem(input: UpsertItemInput): number {
|
||||
return Number(result.lastInsertRowid);
|
||||
}
|
||||
|
||||
export function updateCategoryItem(category: string, id: number, data: Record<string, unknown>) {
|
||||
export function updateCategoryItem(
|
||||
category: string,
|
||||
id: number,
|
||||
data: Record<string, unknown>,
|
||||
) {
|
||||
const db = getDatabase();
|
||||
const normalized = category.trim().toLowerCase();
|
||||
validateCategoryName(normalized);
|
||||
@@ -282,7 +306,10 @@ export function updateCategoryItem(category: string, id: number, data: Record<st
|
||||
db.prepare(sql).run(...values, id);
|
||||
}
|
||||
|
||||
export function getCategoryItem(category: string, id: number): Record<string, unknown> | null {
|
||||
export function getCategoryItem(
|
||||
category: string,
|
||||
id: number,
|
||||
): Record<string, unknown> | null {
|
||||
const db = getDatabase();
|
||||
const normalized = category.trim().toLowerCase();
|
||||
validateCategoryName(normalized);
|
||||
|
||||
Reference in new issue
Block a user