@bluemarble/bi 0.0.0-stage → 0.1.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/server/compile.ts","../../src/server/defineModel.ts","../../src/server/modelFile.ts","../../src/server/normalize.ts","../../src/server/devtools.ts","../../src/server/runQuery.ts"],"sourcesContent":["import { type AggregateMeasure, aggregateSql, isAggregate } from '../model'\nimport { type Edge, joinPlan, measureHome, modelEdges, reachFrom, referencedTables } from '../star'\nimport type { DashboardQuery } from '../types'\nimport type { ModelDef } from './defineModel'\n\nexport class DashboardQueryError extends Error {}\n\n/** Pedaço da consulta, pronto para o devtools medir: devolve uma linha com `n` (linhas do pedaço). */\nexport type CompiledPart = { name: string; sql: string; params: (string | number)[] }\n\nexport type CompiledQuery = {\n sql: string\n params: (string | number)[]\n /** Pedaços do SQL, para o devtools medir cada um: `fato:<tabela>` (a agregação de cada tabela). */\n parts: CompiledPart[]\n}\n\nexport type CompileOptions = {\n /** `LIMIT` em cada tabela: o devtools valida o SQL do modelo com poucas linhas, sem custo. */\n sampleLimit?: number\n}\n\nconst MAX_FILTER_VALUES = 1000\n\nconst quote = (identifier: string) => `\\`${identifier}\\``\n\n/**\n * Expressão de uma medida. `leaf` diz como sai cada agregação (`sum`, `count`, `avg`...): a coluna\n * já agregada pela tabela de origem.\n */\nfunction measureSql(\n model: ModelDef,\n name: string,\n leaf: (name: string, measure: AggregateMeasure) => string,\n stack: string[] = []\n): string {\n if (stack.includes(name))\n throw new DashboardQueryError(`Medida circular: ${[...stack, name].join(' -> ')}`)\n const measure = model.measures[name]\n if (!measure) throw new DashboardQueryError(`Medida desconhecida: \"${name}\"`)\n if (isAggregate(measure)) return leaf(name, measure)\n const next = [...stack, name]\n const ref = (other: string) => measureSql(model, other, leaf, next)\n if (measure.type === 'ratio')\n return `(${ref(measure.numerator)}) / NULLIF(${ref(measure.denominator)}, 0)`\n return `(${measure.expression.replace(/\\{([A-Za-z_][A-Za-z0-9_]*)\\}/g, (_, other) => `(${ref(other)})`)})`\n}\n\n/** Agregações de que as medidas pedidas dependem (razões e fórmulas abertas). */\nfunction leafMeasures(model: ModelDef, names: string[]): string[] {\n const leaves = new Set<string>()\n for (const name of names)\n measureSql(model, name, (leaf, measure) => {\n leaves.add(leaf)\n return measure.sql\n })\n return [...leaves]\n}\n\ntype Filter = { dimension: string; clause: string; params: (string | number)[] }\n\nfunction compileFilters(model: ModelDef, query: DashboardQuery): Filter[] {\n const filters: Filter[] = []\n for (const [name, values] of Object.entries(query.filters ?? {})) {\n const dimension = model.dimensions[name]\n if (!dimension) throw new DashboardQueryError(`Filtro em dimensão desconhecida: \"${name}\"`)\n if (!Array.isArray(values) || !values.length) continue\n if (values.length > MAX_FILTER_VALUES)\n throw new DashboardQueryError(`Valores demais no filtro \"${name}\"`)\n for (const value of values) {\n const valid = dimension.type === 'number' ? Number.isFinite(value) : typeof value === 'string'\n if (!valid) throw new DashboardQueryError(`Valor inválido no filtro \"${name}\": ${value}`)\n }\n filters.push({\n dimension: name,\n clause: `${dimension.sql} IN (${values.map(() => '?').join(', ')})`,\n params: values\n })\n }\n return filters\n}\n\n/**\n * Transforma uma consulta (dimensões + medidas + filtros) em SQL parametrizado (ver `compileStar`).\n *\n * Nomes de dimensões/medidas só são aceitos se existirem no modelo; valores de filtro vão sempre\n * como parâmetro — nada vindo da request é concatenado no SQL.\n */\nexport function compileQuery(\n model: ModelDef,\n query: DashboardQuery,\n options: CompileOptions = {}\n): CompiledQuery {\n const dimensions = query.dimensions ?? []\n const measures = query.measures ?? []\n if (!dimensions.length && !measures.length)\n throw new DashboardQueryError('Informe ao menos uma dimensão ou medida')\n\n for (const name of dimensions) {\n if (!model.dimensions[name]) throw new DashboardQueryError(`Dimensão desconhecida: \"${name}\"`)\n }\n\n const filters = compileFilters(model, query)\n return compileStar(model, dimensions, measures, filters, options)\n}\n\nconst range = (count: number) => Array.from({ length: count }, (_, index) => index + 1).join(', ')\n\n/**\n * Cada tabela de origem (a das medidas pedidas) vira uma agregação no próprio\n * grão, com LEFT JOIN só nas tabelas que levam às dimensões e filtros usados:\n *\n * SELECT <dimensões>, SUM(<medida>) FROM fPesagem\n * LEFT JOIN dOperacao ON dOperacao.id = fPesagem.navio_operacao_id\n * WHERE <filtros> GROUP BY <dimensões>\n *\n * Com medidas de mais de uma fato, cada uma agrega separada e o resultado é somado por dimensão\n * (`UNION ALL` + `GROUP BY`) — juntar duas fatos antes de somar multiplicaria os valores. Razões e\n * fórmulas são calculadas no fim, sobre os totais.\n *\n * Filtro numa dimensão que a fato não alcança é ignorado por ela (como no Power BI, a medida não é\n * filtrada); agrupar por uma dimensão que ela não alcança é erro.\n */\nfunction compileStar(\n model: ModelDef,\n dimensions: string[],\n measures: string[],\n filters: Filter[],\n { sampleLimit }: CompileOptions\n): CompiledQuery {\n const { tables } = model\n const tableNames = Object.keys(tables)\n const edges = modelEdges(model)\n const tableOf = (sql: string) => referencedTables(sql, tableNames)\n const dimensionTable = (name: string) => tableOf(model.dimensions[name].sql)[0]\n\n // Agregações agrupadas pela tabela onde agregam\n const groups = new Map<string, string[]>()\n const leafOf = (name: string) => model.measures[name] as AggregateMeasure\n for (const leaf of leafMeasures(model, measures)) {\n const measure = model.measures[leaf]\n if (!isAggregate(measure)) continue\n const home = measureHome(tableOf(measure.sql), edges)\n if (!home) throw new DashboardQueryError(`Medida \"${leaf}\" sem tabela de origem`)\n groups.set(home, [...(groups.get(home) ?? []), leaf])\n }\n if (!groups.size) groups.set(dimensionHome(model, dimensions, filters, edges), [])\n\n const source = (name: string) => {\n const sql = tables[name].sql\n return sampleLimit === undefined\n ? `(${sql})`\n : `(SELECT * FROM (${sql}) t LIMIT ${Math.max(0, Math.trunc(sampleLimit))})`\n }\n\n const aggregate = (home: string, leaves: string[]) => {\n const { paths } = reachFrom(home, edges)\n for (const name of dimensions)\n if (!paths.has(dimensionTable(name)))\n throw new DashboardQueryError(\n leaves.length\n ? `A dimensão \"${name}\" (${dimensionTable(name)}) não se relaciona com ${home}, de onde vêm ${leaves.join(', ')}`\n : `As dimensões ${dimensions.join(', ')} não se relacionam entre si`\n )\n const applied = filters.filter((filter) => paths.has(dimensionTable(filter.dimension)))\n const needed = new Set([\n ...dimensions.map(dimensionTable),\n ...applied.map((filter) => dimensionTable(filter.dimension)),\n ...leaves.flatMap((leaf) => tableOf(leafOf(leaf).sql))\n ])\n const joins = joinPlan(home, needed, edges).map(\n ({ table, edge }) =>\n `${edge.inner ? 'JOIN' : 'LEFT JOIN'} ${source(table)} ${quote(table)}\\n ON ${quote(table)}.${quote(edge.to.column)} = ${quote(edge.from.table)}.${quote(edge.from.column)}`\n )\n const select = [\n ...dimensions.map((name) => `${model.dimensions[name].sql} AS ${quote(name)}`),\n ...leaves.map((leaf) => `${aggregateSql(leafOf(leaf))} AS ${quote(leaf)}`)\n ]\n const sql = [\n `SELECT ${select.join(',\\n ')}`,\n `FROM ${source(home)} ${quote(home)}`,\n ...joins,\n applied.length ? `WHERE ${applied.map((filter) => filter.clause).join(' AND ')}` : '',\n dimensions.length ? `GROUP BY ${range(dimensions.length)}` : ''\n ]\n .filter(Boolean)\n .join('\\n')\n return { home, sql, params: applied.flatMap((filter) => filter.params) }\n }\n\n const aggregates = [...groups].map(([home, leaves]) => aggregate(home, leaves))\n const parts = aggregates.map(({ home, sql, params }) => ({\n name: `fato:${home}`,\n sql: `SELECT COUNT(*) AS n FROM (${sql}) g`,\n params\n }))\n const orderBy = dimensions.length ? `\\nORDER BY ${range(dimensions.length)}` : ''\n\n // Uma tabela só: as medidas saem direto da agregação\n if (aggregates.length === 1) {\n const [only] = aggregates\n if (!measures.length || measures.every((name) => isAggregate(model.measures[name])))\n return { sql: `${only.sql}${orderBy}`, params: only.params, parts }\n }\n\n // Várias (ou razões/fórmulas): junta as colunas já agregadas e calcula as medidas por cima. Cada\n // fato tem uma linha por grupo e as colunas das outras vêm NULL, então o SUM de fora só pega o\n // valor da própria fato — vale para qualquer agregação (média, contagem distinta...), sem reagregar\n const columns = [...dimensions, ...[...groups.values()].flat()]\n const union = aggregates\n .map(({ home }, index) => {\n const own = new Set(groups.get(home))\n const select = columns.map((column) =>\n dimensions.includes(column) || own.has(column) ? quote(column) : `NULL AS ${quote(column)}`\n )\n return `SELECT ${select.join(', ')} FROM ${quote(`__fato${index}`)}`\n })\n .join('\\n UNION ALL ')\n const leaf = (name: string) => `SUM(${quote('__u')}.${quote(name)})`\n const select = [\n ...dimensions.map((name) => `${quote('__u')}.${quote(name)} AS ${quote(name)}`),\n ...measures.map((name) => `${measureSql(model, name, leaf)} AS ${quote(name)}`)\n ]\n const sql = [\n `WITH ${aggregates.map(({ sql }, index) => `${quote(`__fato${index}`)} AS (\\n${sql}\\n)`).join(',\\n')}`,\n `SELECT ${select.join(',\\n ')}`,\n `FROM (\\n ${union}\\n) ${quote('__u')}`,\n dimensions.length ? `GROUP BY ${range(dimensions.length)}${orderBy}` : ''\n ]\n .filter(Boolean)\n .join('\\n')\n return { sql, params: aggregates.flatMap((item) => item.params), parts }\n}\n\n/**\n * Consulta só de dimensões (ex.: opções de um filtro): parte da tabela que alcança todas as\n * dimensões pedidas e o maior número de filtros ativos — com \"Mês = Janeiro\", a lista de navios sai\n * da fato que liga navio e calendário, e só mostra quem tem lançamento em janeiro. Sem filtro, a\n * própria tabela da dimensão (lista tudo, mesmo sem lançamento).\n */\nfunction dimensionHome(\n model: ModelDef,\n dimensions: string[],\n filters: Filter[],\n edges: Edge[]\n): string {\n const tableNames = Object.keys(model.tables)\n const tableOf = (name: string) => referencedTables(model.dimensions[name].sql, tableNames)[0]\n const own = tableOf(dimensions[0])\n const targets = dimensions.map(tableOf)\n const filterTables = filters.map((filter) => tableOf(filter.dimension))\n let best: { table: string; score: number } | null = null\n // A tabela da própria dimensão primeiro: em empate, ela ganha\n for (const table of [own, ...tableNames.filter((name) => name !== own)]) {\n const { paths } = reachFrom(table, edges)\n if (!targets.every((target) => paths.has(target))) continue\n const score = filterTables.filter((target) => paths.has(target)).length\n if (!best || score > best.score) best = { table, score }\n }\n return best?.table ?? own\n}\n","/**\n * Modelo semântico de um dashboard: o equivalente ao modelo do Power BI (tabelas, relacionamentos e\n * medidas DAX), só que versionado em código.\n *\n * - `tables`: tabelas fato (lançamentos, lado N) e dimensão (cadastros, lado 1). O SQL é a consulta\n * de origem — tabela, view ou SELECT, sem agregar.\n * - `relationships`: N:1 (`from: 'fato.coluna'`, `to: 'dimensao.coluna'`); o filtro vai do lado 1\n * para o lado N. Cada medida agrega no grão da própria tabela, então juntar fatos não duplica\n * valores (o problema de \"fan-out\").\n * - `dimensions`: por onde se agrupa e filtra, citando `tabela.coluna` de uma tabela.\n * - `measures`: agregações (`sum`, `count`, `countDistinct`, `avg`, `min`, `max`) sobre\n * `tabela.coluna`, razões entre medidas (`ratio`) ou fórmulas (`formula`).\n *\n * Dialeto: MySQL/MariaDB.\n */\n\nimport {\n type AggregateMeasure,\n type Aggregation,\n type FormulaMeasure,\n type MeasureMeta,\n type ModelDef,\n type RatioMeasure,\n type SumMeasure,\n validateModel\n} from '../model'\n\nexport type {\n AggregateMeasure,\n Aggregation,\n DimensionDef,\n FieldMeta,\n FormulaMeasure,\n MeasureDef,\n MeasureMeta,\n ModelDef,\n RatioMeasure,\n RelationshipDef,\n SumMeasure,\n TableDef\n} from '../model'\n\nexport const sum = (sql: string, meta?: MeasureMeta): SumMeasure => ({ ...meta, type: 'sum', sql })\n\nconst aggregate =\n <T extends Aggregation>(type: T) =>\n (sql: string, meta?: MeasureMeta): AggregateMeasure & { type: T } => ({ ...meta, type, sql })\n\n/** `COUNT(sql)`: valores não nulos. Para contar linhas, use uma coluna que nunca é nula (a chave). */\nexport const count = aggregate('count')\n/** `COUNT(DISTINCT sql)`: ex. quantas operações têm lançamento (`fVeiculo.navio_operacao_id`). */\nexport const countDistinct = aggregate('countDistinct')\n/** `AVG(sql)`: média das linhas (no estrela, das linhas da própria tabela, não de totais). */\nexport const avg = aggregate('avg')\nexport const min = aggregate('min')\nexport const max = aggregate('max')\n\n/** `numerator / denominator`, ambos nomes de medidas do mesmo modelo (nulo quando o divisor é 0). */\nexport const ratio = (\n numerator: string,\n denominator: string,\n meta?: MeasureMeta\n): RatioMeasure => ({\n ...meta,\n type: 'ratio',\n numerator,\n denominator\n})\n\n/**\n * Combina medidas já agregadas: `{nome}` vira o valor da medida. Ex.:\n * `formula('COALESCE({custoMmo}, 0) + COALESCE({custoAppa}, 0)')` — o jeito de somar medidas de\n * fatos diferentes no modelo estrela.\n */\nexport const formula = (expression: string, meta?: MeasureMeta): FormulaMeasure => ({\n ...meta,\n type: 'formula',\n expression\n})\n\n/** Valida o modelo na carga do módulo: erro de definição aparece no deploy, não na primeira query. */\nexport function defineModel<const M extends ModelDef>(model: M): M {\n const errors = validateModel(model)\n if (errors.length) throw new Error(`[${model.name}] ${errors.join('; ')}`)\n return model\n}\n","import { modelImports, modelObjectCode } from '../codegen'\nimport { AGGREGATIONS, type ModelDef } from '../model'\n\n/**\n * Troca, dentro do arquivo do modelo, só o objeto passado ao `defineModel(...)` e o import do\n * `@bluemarble/bi/server`. O resto do arquivo (JSDoc do modelo, outros exports) fica como está.\n */\n\nexport class ModelFileError extends Error {}\n\n/** Índice do `)` que fecha o `(` em `open`, pulando strings, templates e comentários. */\nfunction findClosingParen(source: string, open: number) {\n let depth = 0\n let comments = false\n // Pilha de contexto: '(' / '{' de código, '`' de template, '${' de interpolação\n const stack: string[] = []\n for (let i = open; i < source.length; i++) {\n const char = source[i]\n const next = source[i + 1]\n const inTemplate = stack[stack.length - 1] === '`'\n\n if (inTemplate) {\n if (char === '\\\\') i++\n else if (char === '`') stack.pop()\n else if (char === '$' && next === '{') {\n stack.push('${')\n i++\n }\n continue\n }\n if (char === \"'\" || char === '\"') {\n for (i++; i < source.length && source[i] !== char; i++) if (source[i] === '\\\\') i++\n continue\n }\n if (char === '/' && next === '/') {\n comments = true\n while (i < source.length && source[i] !== '\\n') i++\n continue\n }\n if (char === '/' && next === '*') {\n comments = true\n i = source.indexOf('*/', i + 2) + 1\n if (i === 0) break\n continue\n }\n if (char === '`') stack.push('`')\n else if (char === '{') stack.push('{')\n else if (char === '}')\n stack.pop() // fecha '{' ou '${'\n else if (char === '(') depth++\n else if (char === ')' && --depth === 0) return { close: i, comments }\n }\n throw new ModelFileError('Não encontrei o fim da chamada `defineModel(...)`')\n}\n\nexport function replaceModelInFile(source: string, model: ModelDef) {\n const warnings: string[] = []\n const call = new RegExp(`export\\\\s+const\\\\s+${model.name}\\\\s*=\\\\s*defineModel(?:<[^>]*>)?\\\\s*\\\\(`)\n const match = call.exec(source)\n if (!match)\n throw new ModelFileError(`O arquivo não tem \\`export const ${model.name} = defineModel(...)\\``)\n\n const open = match.index + match[0].length - 1\n const { close, comments } = findClosingParen(source, open)\n if (comments)\n warnings.push('Comentários dentro do defineModel(...) serão perdidos (os de fora ficam).')\n\n let content = `${source.slice(0, open + 1)}${modelObjectCode(model)}${source.slice(close)}`\n\n // Import: mantém o que mais vier do package e acerta os helpers de medida conforme o uso\n const importRegex = /import\\s*\\{([^}]*)\\}\\s*from\\s*'@bluemarble\\/bi\\/server'/\n const current = importRegex.exec(content)\n const helpers = new Set(['defineModel', 'formula', 'ratio', ...AGGREGATIONS])\n const others = (current?.[1] ?? '')\n .split(',')\n .map((name) => name.trim())\n .filter((name) => name && !helpers.has(name))\n const names = [...others, ...modelImports(model)].sort((a, b) =>\n a.localeCompare(b, 'en', { sensitivity: 'base' })\n )\n const line = `import { ${names.join(', ')} } from '@bluemarble/bi/server'`\n content = current ? content.replace(importRegex, line) : `${line}\\n${content}`\n\n const outside = source.slice(0, match.index) + source.slice(close + 1)\n const measureHelpers = [...helpers].filter((name) => name !== 'defineModel')\n if (new RegExp(`\\\\b(${measureHelpers.join('|')})\\\\(`).test(outside))\n warnings.push('O arquivo usa os helpers de medida fora do modelo; confira o import.')\n\n return { content, warnings }\n}\n","import type { DashboardRow } from '../types'\n\n/** Decimal do Prisma, bigint e afins viram number; datas viram ISO. */\nexport function normalizeValue(value: unknown): string | number | null {\n if (value === null || value === undefined) return null\n if (typeof value === 'string' || typeof value === 'number') return value\n if (typeof value === 'bigint') return Number(value)\n if (value instanceof Date) return value.toISOString()\n const number = Number(value)\n return Number.isNaN(number) ? String(value) : number\n}\n\nexport function normalizeRow(row: Record<string, unknown>): DashboardRow {\n const normalized: DashboardRow = {}\n for (const [key, value] of Object.entries(row)) normalized[key] = normalizeValue(value)\n return normalized\n}\n","import {\n type ChartsLayout,\n layoutFileContent,\n layoutModelWarnings,\n validateLayout\n} from '../layout'\nimport { isAggregate, modelMeta, validateModel } from '../model'\nimport { parseColumnRef, referencedTables } from '../star'\nimport type {\n DashboardDevtoolsRequest,\n DashboardQuery,\n DashboardResult,\n DashboardRow,\n DashboardSnapshot,\n ModelColumns,\n ModelValidation,\n ProfileStep,\n SchemaTable\n} from '../types'\nimport { compileQuery, DashboardQueryError } from './compile'\nimport type { ModelDef } from './defineModel'\nimport { ModelFileError, replaceModelInFile } from './modelFile'\nimport { normalizeValue } from './normalize'\n\n/**\n * Pedidos do devtools (`query.devtools`) que não são uma consulta comum. Só chega aqui com\n * `runQuery(..., { devtools })` ligado — tudo isso executa SQL vindo do browser ou escreve em disco.\n */\n\nexport type DevtoolsServerOptions = {\n /**\n * Pasta dos arquivos de modelo (`<pasta>/<nome>.ts`, caminho absoluto). Habilita \"Salvar no\n * arquivo\"; só arquivos que já existem são reescritos.\n */\n modelsDir?: string\n /** Pasta dos snapshots de regressão (`<pasta>/<modelo>/<nome>.json`, caminho absoluto). */\n snapshotsDir?: string\n /**\n * Pasta dos layouts de gráficos (`<pasta>/<id>.json`, caminho absoluto). Habilita \"Salvar no\n * arquivo\" na aba Layout; só arquivos que já existem são reescritos.\n */\n layoutsDir?: string\n /**\n * Formata o arquivo do modelo antes do preview/gravação (ex.: Biome), para o diff mostrar só o\n * que mudou de fato. Sem isso, o arquivo sai com a formatação do gerador.\n */\n format?: (code: string, path: string) => Promise<string>\n}\n\ntype Executor = (sql: string, params: (string | number)[]) => Promise<Record<string, unknown>[]>\n\ntype Context = {\n registered: ModelDef\n /** Rascunho, se houver; senão o registrado. */\n model: ModelDef\n query: DashboardQuery\n request: DashboardDevtoolsRequest\n execute: Executor\n normalize: (row: Record<string, unknown>) => DashboardRow\n options: DevtoolsServerOptions\n /** Executa a consulta normal (com cache) e devolve as linhas. */\n runRows: (model: ModelDef) => Promise<DashboardRow[]>\n}\n\nconst fs = () => import('node:fs/promises')\n\n/** Mensagem do banco sem o embrulho do Prisma (`Raw query failed. Code: ... Message: ...`). */\nexport function dbMessage(error: unknown) {\n const err = error as { meta?: { message?: string }; message?: string }\n const message = err?.meta?.message ?? err?.message ?? String(error)\n return message.match(/Message: `?([\\s\\S]*?)`?$/)?.[1] ?? message\n}\n\nconst timed = async <T>(load: () => Promise<T>) => {\n const startedAt = performance.now()\n const result = await load()\n return { result, durationMs: Math.round(performance.now() - startedAt) }\n}\n\nconst SLUG = /^[A-Za-z0-9_-]{1,80}$/\n\nexport async function handleDevtoolsRequest(context: Context): Promise<DashboardResult | null> {\n const { request } = context\n if (request.describe) return describe(context)\n if (request.schema) return { rows: [], devtools: { schema: await loadSchema(context.execute) } }\n if (request.columns) {\n const { columns, errors } = await describeColumns(context)\n return { rows: [], devtools: { columns, columnErrors: errors } }\n }\n if (request.validate) return { rows: [], devtools: { validation: await validateSql(context) } }\n if (request.save) return { rows: [], devtools: { save: await saveModel(context) } }\n if (request.saveLayout) return { rows: [], devtools: { save: await saveLayout(context) } }\n if (request.snapshots) return { rows: [], devtools: { snapshots: await listSnapshots(context) } }\n if (request.snapshot) return { rows: [], devtools: { snapshot: await saveSnapshot(context) } }\n if (request.explain) {\n const { sql, params } = compileQuery(context.model, context.query)\n const rows = await context.execute(`EXPLAIN ${sql}`, params)\n return { rows: [], devtools: { explain: rows.map(context.normalize) } }\n }\n if (request.profile) return { rows: [], devtools: { profile: await profile(context) } }\n return null\n}\n\nfunction describe({ registered, options }: Context): DashboardResult {\n return {\n rows: [],\n meta: modelMeta(registered),\n devtools: {\n model: registered,\n capabilities: {\n saveModel: !!options.modelsDir,\n snapshots: !!options.snapshotsDir,\n saveLayout: !!options.layoutsDir\n }\n }\n }\n}\n\nasync function profile({ model, query, execute }: Context): Promise<ProfileStep[]> {\n const { sql, params, parts } = compileQuery(model, query)\n // Em sequência: medições em paralelo disputariam o banco e os tempos não diriam nada\n const steps: ProfileStep[] = []\n for (const part of parts) {\n const { result, durationMs } = await timed(() => execute(part.sql, part.params))\n steps.push({ name: part.name, durationMs, rows: Number(result[0]?.n ?? 0) })\n }\n const total = await timed(() => execute(sql, params))\n steps.push({ name: 'consulta', durationMs: total.durationMs, rows: total.result.length })\n return steps\n}\n\nasync function loadSchema(execute: Executor): Promise<SchemaTable[]> {\n const rows = await execute(\n `SELECT c.TABLE_NAME AS tableName, t.TABLE_TYPE AS tableType,\n c.COLUMN_NAME AS columnName, c.DATA_TYPE AS dataType\n FROM information_schema.COLUMNS c\n JOIN information_schema.TABLES t\n ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME\n WHERE c.TABLE_SCHEMA = DATABASE()\n ORDER BY c.TABLE_NAME, c.ORDINAL_POSITION`,\n []\n )\n const tables = new Map<string, SchemaTable>()\n for (const row of rows) {\n const name = String(row.tableName)\n let table = tables.get(name)\n if (!table) {\n table = { name, type: String(row.tableType).includes('VIEW') ? 'view' : 'table', columns: [] }\n tables.set(name, table)\n }\n table.columns.push({ name: String(row.columnName), type: String(row.dataType) })\n }\n return [...tables.values()]\n}\n\n/** Poucas chaves bastam para o banco acusar erro de SQL e para descobrir as colunas. */\nconst SAMPLE_KEYS = 20\n\nconst emptyColumns = (): ModelColumns => ({ tables: {}, numeric: [] })\n\n/** Colunas numéricas da primeira linha (Decimal do Prisma e bigint contam). */\nfunction numericColumns(node: string, row: Record<string, unknown> | undefined) {\n return Object.entries(row ?? {})\n .filter(([, value]) => typeof normalizeValue(value) === 'number')\n .map(([column]) => `${node}.${column}`)\n}\n\n/**\n * Colunas de cada tabela do modelo (uma linha de cada). `errors` traz o que o banco recusou, com as\n * chaves da validação (`table:<nome>`).\n */\nasync function loadColumns(model: ModelDef, execute: Executor) {\n const columns = emptyColumns()\n const errors: Record<string, string> = {}\n const attempt = async (key: string, sql: string) => {\n try {\n return await execute(sql, [])\n } catch (error) {\n errors[key] = dbMessage(error)\n return null\n }\n }\n for (const [name, table] of Object.entries(model.tables)) {\n const rows = await attempt(`table:${name}`, `SELECT * FROM (${table.sql}) t LIMIT 1`)\n if (!rows) continue\n columns.tables[name] = Object.keys(rows[0] ?? {})\n columns.numeric.push(...numericColumns(name, rows[0]))\n }\n return { columns, errors }\n}\n\nasync function describeColumns({ model, execute }: Context) {\n const errors = validateModel(model)\n if (errors.length) throw new DashboardQueryError(`Modelo inválido: ${errors.join('; ')}`)\n return loadColumns(model, execute)\n}\n\nasync function validateSql({ model, execute }: Context): Promise<ModelValidation> {\n const validation: ModelValidation = { errors: {}, warnings: {}, columns: emptyColumns() }\n const modelErrors = validateModel(model)\n if (modelErrors.length) {\n validation.errors.model = modelErrors.join('; ')\n return validation\n }\n\n const attempt = async (key: string, sql: string) => {\n try {\n return await execute(sql, [])\n } catch (error) {\n validation.errors[key] = dbMessage(error)\n return null\n }\n }\n\n const loaded = await loadColumns(model, execute)\n validation.columns = loaded.columns\n Object.assign(validation.errors, loaded.errors)\n const tableNames = Object.keys(model.tables)\n\n for (const [index, relationship] of (model.relationships ?? []).entries()) {\n const key = `relationship:${index}`\n const from = parseColumnRef(relationship.from)\n const to = parseColumnRef(relationship.to)\n if (!from || !to) continue\n const missing = [from, to].find(\n (ref) =>\n validation.columns.tables[ref.table]?.length &&\n !validation.columns.tables[ref.table].includes(ref.column)\n )\n if (missing) {\n validation.errors[key] = `a tabela \"${missing.table}\" não tem a coluna \"${missing.column}\"`\n continue\n }\n // O lado 1 precisa ser único, senão a fato multiplica linhas ao juntar\n const toSql = model.tables[to.table]?.sql\n if (!toSql || validation.errors[`table:${to.table}`]) continue\n const repeated = await attempt(\n key,\n `SELECT \\`${to.column}\\` AS v FROM (${toSql}) t WHERE \\`${to.column}\\` IS NOT NULL GROUP BY 1 HAVING COUNT(*) > 1 LIMIT 1`\n )\n if (repeated?.length)\n validation.errors[key] =\n `o lado 1 (${relationship.to}) tem valor repetido: ${String(normalizeValue(repeated[0].v))}`\n }\n\n for (const [name, dimension] of Object.entries(model.dimensions)) {\n const table = referencedTables(dimension.sql, tableNames)[0]\n if (validation.errors[`table:${table}`]) continue\n const sql = `SELECT ${dimension.sql} AS v FROM (SELECT * FROM (${model.tables[table]?.sql}) t LIMIT ${SAMPLE_KEYS}) \\`${table}\\` WHERE ${dimension.sql} IS NOT NULL LIMIT 1`\n const rows = await attempt(`dimension:${name}`, sql)\n const value = rows?.[0]?.v\n if (value === undefined || value === null) continue\n const isNumber = typeof value === 'number' || typeof value === 'bigint'\n if (dimension.type === 'number' && !isNumber && Number.isNaN(Number(value)))\n validation.warnings[`dimension:${name}`] = `tipo number, mas o banco devolveu \"${value}\"`\n if (dimension.type === 'string' && isNumber)\n validation.warnings[`dimension:${name}`] =\n 'tipo string, mas o banco devolveu número (filtros vão chegar como texto)'\n }\n\n for (const [name, measure] of Object.entries(model.measures)) {\n if (!isAggregate(measure)) continue // razão e fórmula só combinam outras medidas\n const failed = referencedTables(measure.sql, tableNames).some(\n (table) => validation.errors[`table:${table}`]\n )\n if (failed) continue\n const { sql, params } = compileQuery(\n model,\n { model: model.name, measures: [name] },\n { sampleLimit: SAMPLE_KEYS }\n )\n try {\n await execute(sql, params)\n } catch (error) {\n validation.errors[`measure:${name}`] = dbMessage(error)\n }\n }\n\n return validation\n}\n\nasync function saveModel({ registered, model, request, options }: Context) {\n if (!options.modelsDir) throw new DashboardQueryError('O endpoint não configurou `modelsDir`')\n if (!request.model) throw new DashboardQueryError('Nada para salvar: não há rascunho')\n if (model.name !== registered.name)\n throw new DashboardQueryError('O rascunho não pode trocar o nome do modelo')\n\n const path = `${options.modelsDir.replace(/\\/+$/, '')}/${registered.name}.ts`\n const { readFile, writeFile } = await fs()\n let previous: string\n try {\n previous = await readFile(path, 'utf8')\n } catch {\n throw new DashboardQueryError(`Arquivo do modelo não encontrado: ${path}`)\n }\n\n try {\n const replaced = replaceModelInFile(previous, model)\n const { warnings } = replaced\n const content = options.format ? await options.format(replaced.content, path) : replaced.content\n const written = request.save === 'write' && content !== previous\n if (written) await writeFile(path, content, 'utf8')\n return { path, previous, content, written, warnings }\n } catch (error) {\n if (error instanceof ModelFileError) throw new DashboardQueryError(error.message)\n throw error\n }\n}\n\nasync function saveLayout({ model, request, options }: Context) {\n if (!options.layoutsDir) throw new DashboardQueryError('O endpoint não configurou `layoutsDir`')\n const { layout, mode } = request.saveLayout ?? ({} as { layout?: ChartsLayout; mode?: string })\n const errors = layout ? validateLayout(layout) : ['Nada para salvar: não há layout']\n if (errors.length) throw new DashboardQueryError(`Layout inválido: ${errors.join('; ')}`)\n const valid = layout as ChartsLayout\n\n const path = `${options.layoutsDir.replace(/\\/+$/, '')}/${valid.id}.json`\n const { readFile, writeFile } = await fs()\n let previous: string\n try {\n previous = await readFile(path, 'utf8')\n } catch {\n throw new DashboardQueryError(`Arquivo do layout não encontrado: ${path}`)\n }\n\n const raw = layoutFileContent(valid)\n const content = options.format ? await options.format(raw, path) : raw\n const written = mode === 'write' && content !== previous\n if (written) await writeFile(path, content, 'utf8')\n // Contra o modelo em vigor na página (o rascunho, se houver)\n return { path, previous, content, written, warnings: layoutModelWarnings(valid, model) }\n}\n\nconst snapshotDir = (options: DevtoolsServerOptions, model: string) => {\n if (!options.snapshotsDir)\n throw new DashboardQueryError('O endpoint não configurou `snapshotsDir`')\n return `${options.snapshotsDir.replace(/\\/+$/, '')}/${model}`\n}\n\nasync function saveSnapshot({ registered, query, request, options, runRows }: Context) {\n const { name, overwrite } = request.snapshot ?? { name: '' }\n if (!SLUG.test(name))\n throw new DashboardQueryError('Nome do snapshot: letras, números, \"-\" e \"_\" (até 80)')\n const dir = snapshotDir(options, registered.name)\n const path = `${dir}/${name}.json`\n const { mkdir, readFile, writeFile } = await fs()\n\n if (!overwrite) {\n const exists = await readFile(path, 'utf8').then(\n () => true,\n () => false\n )\n if (exists) throw new DashboardQueryError(`Já existe um snapshot \"${name}\"`)\n }\n\n // Sempre o modelo registrado: o snapshot é a referência que o rascunho tem que bater\n const snapshot: DashboardSnapshot = {\n name,\n createdAt: new Date().toISOString(),\n query: {\n model: registered.name,\n dimensions: query.dimensions ?? [],\n measures: query.measures ?? [],\n filters: query.filters ?? {}\n },\n rows: await runRows(registered)\n }\n await mkdir(dir, { recursive: true })\n await writeFile(path, `${JSON.stringify(snapshot, null, 2)}\\n`, 'utf8')\n return { path }\n}\n\nasync function listSnapshots({ registered, options }: Context): Promise<DashboardSnapshot[]> {\n const dir = snapshotDir(options, registered.name)\n const { readdir, readFile } = await fs()\n const files = await readdir(dir).catch(() => [] as string[])\n const snapshots = await Promise.all(\n files\n .filter((file) => file.endsWith('.json'))\n .sort()\n .map(\n async (file) => JSON.parse(await readFile(`${dir}/${file}`, 'utf8')) as DashboardSnapshot\n )\n )\n return snapshots\n}\n","import { modelMeta, validateModel } from '../model'\nimport type { DashboardQuery, DashboardResult, DashboardRow } from '../types'\nimport { compileQuery, DashboardQueryError } from './compile'\nimport type { ModelDef } from './defineModel'\nimport { type DevtoolsServerOptions, dbMessage, handleDevtoolsRequest } from './devtools'\nimport { normalizeRow } from './normalize'\n\n/** Executa o SQL no banco do app (ex.: `(sql, params) => prisma.$queryRawUnsafe(sql, ...params)`). */\nexport type QueryExecutor = (sql: string, params: (string | number)[]) => Promise<unknown[]>\n\nexport type RunQueryOptions = {\n /**\n * Por quanto tempo reaproveitar o resultado de uma mesma consulta (mesmo SQL + parâmetros).\n * Faz o papel do \"refresh\" do Power BI: alternar filtros não recalcula tudo de novo. 0 = sem cache.\n */\n cacheTtlMs?: number\n /**\n * Aceita os pedidos do devtools (`query.devtools`): debug, rascunho de modelo, EXPLAIN, validação\n * de SQL etc. O rascunho é SQL vindo do browser — ligue SÓ em desenvolvimento. Passe as pastas\n * (`modelsDir`, `snapshotsDir`) para habilitar salvar o modelo e os snapshots.\n */\n devtools?: boolean | DevtoolsServerOptions\n}\n\ntype Execution = { rows: DashboardRow[]; durationMs: number }\n\nconst MAX_CACHE_ENTRIES = 500\nconst cache = new Map<string, { expiresAt: number; execution: Promise<Execution> }>()\n\nfunction fromCache(key: string, ttl: number, load: () => Promise<Execution>) {\n const now = Date.now()\n const hit = cache.get(key)\n if (hit && hit.expiresAt > now) return { execution: hit.execution, cached: true }\n\n if (cache.size >= MAX_CACHE_ENTRIES) {\n for (const [k, entry] of cache) if (entry.expiresAt <= now) cache.delete(k)\n if (cache.size >= MAX_CACHE_ENTRIES) cache.delete(cache.keys().next().value as string)\n }\n // Guarda a promise: requests simultâneas da mesma consulta esperam a mesma execução\n const execution = load()\n cache.set(key, { expiresAt: now + ttl, execution })\n execution.catch(() => cache.delete(key))\n return { execution, cached: false }\n}\n\nexport async function runQuery(\n models: Record<string, ModelDef>,\n query: DashboardQuery,\n execute: QueryExecutor,\n options: RunQueryOptions = {}\n): Promise<DashboardResult> {\n // `debug` desligado é só ignorado (a página continua funcionando com um endpoint sem devtools);\n // o resto expõe ou altera o modelo e é recusado\n const { debug, ...privileged } = query?.devtools ?? {}\n const devtools = options.devtools ? query?.devtools : undefined\n if (!options.devtools && Object.values(privileged).some(Boolean))\n throw new DashboardQueryError('Devtools desabilitado neste ambiente')\n\n const registered = models[query?.model]\n if (!registered) throw new DashboardQueryError(`Modelo desconhecido: \"${query?.model}\"`)\n\n const draft = devtools?.model\n if (draft) {\n const errors = validateModel(draft)\n if (errors.length) throw new DashboardQueryError(`Rascunho inválido: ${errors.join('; ')}`)\n }\n const model = draft ?? registered\n\n // Rótulos/formatos (sem SQL): liberado em produção, os componentes usam como padrão\n if (query.meta) return { rows: [], meta: modelMeta(model) }\n\n const ttl = options.cacheTtlMs ?? 0\n const run = async (target: ModelDef) => {\n const { sql, params } = compileQuery(target, query)\n const load = async (): Promise<Execution> => {\n const startedAt = performance.now()\n const rows = (await execute(sql, params)) as Record<string, unknown>[]\n return { durationMs: Math.round(performance.now() - startedAt), rows: rows.map(normalizeRow) }\n }\n // O rascunho muda o SQL, então nunca colide com o cache do modelo registrado\n const { execution, cached } =\n ttl > 0\n ? fromCache(JSON.stringify([sql, params]), ttl, load)\n : { execution: load(), cached: false }\n return { sql, params, cached, ...(await execution) }\n }\n\n if (devtools) {\n if (devtools.clearCache) cache.clear()\n try {\n const handled = await handleDevtoolsRequest({\n registered,\n model,\n query,\n request: devtools,\n execute: (sql, params) => execute(sql, params) as Promise<Record<string, unknown>[]>,\n normalize: normalizeRow,\n options: typeof options.devtools === 'object' ? options.devtools : {},\n runRows: async (target) => (await run(target)).rows\n })\n if (handled) return handled\n } catch (error) {\n // Erro de SQL no devtools é do rascunho/consulta, não do servidor: vira 400 com a mensagem do banco\n if (error instanceof DashboardQueryError) throw error\n throw new DashboardQueryError(dbMessage(error))\n }\n }\n\n const { rows, sql, params, durationMs, cached } = await run(model)\n if (!devtools?.debug) return { rows }\n return { rows, devtools: { debug: { sql, params, durationMs, cached, draft: !!draft } } }\n}\n"],"mappings":";;;AAKA,IAAa,sBAAb,cAAyC,MAAM,CAAC;AAiBhD,MAAM,oBAAoB;AAE1B,MAAM,SAAS,eAAuB,KAAK,WAAW;;;;;AAMtD,SAAS,WACP,OACA,MACA,MACA,QAAkB,CAAC,GACX;CACR,IAAI,MAAM,SAAS,IAAI,GACrB,MAAM,IAAI,oBAAoB,oBAAoB,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,KAAK,MAAM,GAAG;CACnF,MAAM,UAAU,MAAM,SAAS;CAC/B,IAAI,CAAC,SAAS,MAAM,IAAI,oBAAoB,yBAAyB,KAAK,EAAE;CAC5E,IAAI,YAAY,OAAO,GAAG,OAAO,KAAK,MAAM,OAAO;CACnD,MAAM,OAAO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,KAAK,IAAI,IAClD;GAAE,WAAW,KAAK;GAAG,QAAQ;EAAM;EACzC,OAAO;GAAE;GAAK;GAAQ;GAAQ,GAAI,MAAM;EAAW;CACrD;CAEA,IAAI,UAAU;EACZ,IAAI,SAAS,YAAY,MAAM,MAAM;EACrC,IAAI;GACF,MAAM,UAAU,MAAM,sBAAsB;IAC1C;IACA;IACA;IACA,SAAS;IACT,UAAU,KAAK,WAAW,QAAQ,KAAK,MAAM;IAC7C,WAAW;IACX,SAAS,OAAO,QAAQ,aAAa,WAAW,QAAQ,WAAW,CAAC;IACpE,SAAS,OAAO,YAAY,MAAM,IAAI,MAAM,EAAA,CAAG;GACjD,CAAC;GACD,IAAI,SAAS,OAAO;EACtB,SAAS,OAAO;GAEd,IAAI,iBAAiB,qBAAqB,MAAM;GAChD,MAAM,IAAI,oBAAoB,UAAU,KAAK,CAAC;EAChD;CACF;CAEA,MAAM,EAAE,MAAM,KAAK,QAAQ,YAAY,WAAW,MAAM,IAAI,KAAK;CACjE,IAAI,CAAC,UAAU,OAAO,OAAO,EAAE,KAAK;CACpC,OAAO;EAAE;EAAM,UAAU,EAAE,OAAO;GAAE;GAAK;GAAQ;GAAY;GAAQ,OAAO,CAAC,CAAC;EAAM,EAAE;CAAE;AAC1F"}
@@ -0,0 +1,371 @@
1
+ //#region src/model.d.ts
2
+ /**
3
+ * Tipos e validação do modelo semântico. Fica fora de `server/` porque o devtools (client) também
4
+ * valida o rascunho editado antes de mandá-lo pro servidor.
5
+ */
6
+ /**
7
+ * Dicionário: nome de negócio e explicação de cada campo. Os componentes usam como padrão (rótulo,
8
+ * formatação) e o `ModelDictionary` vira a documentação do modelo para quem usa o dashboard.
9
+ */
10
+ type FieldMeta = {
11
+ label?: string;
12
+ description?: string;
13
+ };
14
+ declare const VALUE_FORMATS: readonly ['number', 'integer', 'currency', 'percent'];
15
+ type ValueFormat = (typeof VALUE_FORMATS)[number];
16
+ type MeasureMeta = FieldMeta & {
17
+ /** `percent` espera a fração (0.25 = 25%). */
18
+ format?: ValueFormat;
19
+ /** Casas decimais; sem isso, vale o padrão do componente. */
20
+ decimals?: number;
21
+ };
22
+ type DimensionDef = FieldMeta & {
23
+ sql: string;
24
+ type: 'number' | 'string';
25
+ };
26
+ /**
27
+ * Agregações sobre uma expressão SQL (`tabela.coluna`). Todas valem nos dois formatos; no estrela,
28
+ * agregam no grão da tabela de origem, como a soma.
29
+ */
30
+ declare const AGGREGATIONS: readonly ['sum', 'count', 'countDistinct', 'avg', 'min', 'max'];
31
+ type Aggregation = (typeof AGGREGATIONS)[number];
32
+ /** `COUNT` conta os valores não nulos; para contar linhas, use uma coluna que nunca é nula. */
33
+ type AggregateMeasure = MeasureMeta & {
34
+ type: Aggregation;
35
+ sql: string;
36
+ };
37
+ type SumMeasure = AggregateMeasure & {
38
+ type: 'sum';
39
+ };
40
+ type RatioMeasure = MeasureMeta & {
41
+ type: 'ratio';
42
+ numerator: string;
43
+ denominator: string;
44
+ };
45
+ /**
46
+ * Combinação de outras medidas, já agregadas: `{nome}` vira o valor da medida (como `[Medida]` no
47
+ * DAX). É o jeito de juntar medidas de fatos diferentes: `COALESCE({custoMmo}, 0) + COALESCE({custoAppa}, 0)`.
48
+ */
49
+ type FormulaMeasure = MeasureMeta & {
50
+ type: 'formula';
51
+ expression: string;
52
+ };
53
+ type MeasureDef = AggregateMeasure | RatioMeasure | FormulaMeasure;
54
+ /**
55
+ * Tabela do modelo: o SQL é a "consulta de origem" (tabela, view ou SELECT). Não há tipo fato ou
56
+ * dimensão: o papel sai dos relacionamentos (quem está no lado 1 filtra quem está no lado N) e de
57
+ * onde ficam as medidas.
58
+ */
59
+ type TableDef = FieldMeta & {
60
+ sql: string;
61
+ /** Coluna única da tabela; o diagrama usa ela para decidir o lado 1 ao criar relacionamentos. */
62
+ key?: string;
63
+ };
64
+ /** Relacionamento N:1 — o filtro do lado 1 (`to`) chega às linhas do lado N (`from`). */
65
+ type RelationshipDef = {
66
+ /** `tabela.coluna` do lado N (os lançamentos). */
67
+ from: string;
68
+ /** `tabela.coluna` do lado 1 (a chave do cadastro). */
69
+ to: string;
70
+ /**
71
+ * "Pressupor integridade referencial" do Power BI: INNER JOIN em vez de LEFT JOIN, e a tabela do
72
+ * lado 1 entra sempre na consulta da fato. Linhas do lado N sem par no lado 1 ficam de fora (em
73
+ * vez de virar um grupo "em branco") — é o jeito de um filtro fixo da dimensão valer para a fato.
74
+ */
75
+ inner?: boolean;
76
+ };
77
+ /**
78
+ * Modelo estrela: `tables` (fato/dimensão) + `relationships`. Dimensões e medidas citam as colunas
79
+ * como `tabela.coluna`; cada medida de agregação agrega no grão da própria tabela e chega às
80
+ * dimensões seguindo os relacionamentos.
81
+ */
82
+ type ModelDef = {
83
+ name: string;
84
+ tables: Record<string, TableDef>;
85
+ relationships?: RelationshipDef[];
86
+ dimensions: Record<string, DimensionDef>;
87
+ measures: Record<string, MeasureDef>;
88
+ /**
89
+ * Posição de cada card no diagrama do devtools (tabela -> canto superior esquerdo). Só visual: não muda nenhuma consulta. Card sem posição entra no layout automático.
90
+ */
91
+ diagram?: Record<string, DiagramPosition>;
92
+ };
93
+ type DiagramPosition = {
94
+ x: number;
95
+ y: number;
96
+ };
97
+ /** Só os metadados (sem SQL): é o que o client recebe fora do devtools. */
98
+ type ModelMeta = {
99
+ name: string;
100
+ dimensions: Record<string, FieldMeta & {
101
+ type: DimensionDef['type'];
102
+ }>;
103
+ measures: Record<string, MeasureMeta & {
104
+ type: MeasureDef['type'];
105
+ numerator?: string;
106
+ denominator?: string;
107
+ /** Medidas que a fórmula combina (a expressão em si fica no servidor). */
108
+ refs?: string[];
109
+ }>;
110
+ };
111
+ declare function modelMeta(model: ModelDef): ModelMeta;
112
+ /**
113
+ * Lista os problemas do modelo (vazio = válido). Confere também a forma do objeto, porque o rascunho
114
+ * do devtools chega como JSON da request.
115
+ */
116
+ declare function validateModel(model: ModelDef): string[];
117
+ //#endregion
118
+ //#region src/layout.d.ts
119
+ declare const CHART_TYPES: readonly ['kpi', 'combo', 'bar', 'donut', 'table'];
120
+ type ChartType = (typeof CHART_TYPES)[number];
121
+ type BaseChartDef = {
122
+ /** Identificador estável do gráfico dentro do layout (letras, números, "-" e "_"). */
123
+ id: string;
124
+ title: string;
125
+ /** Colunas ocupadas (1 a 12). Padrão: 12. */
126
+ span?: number;
127
+ height?: number;
128
+ };
129
+ type ComboChartDef = BaseChartDef & {
130
+ type: 'combo';
131
+ dimension: string;
132
+ bar: string;
133
+ line: string;
134
+ detail?: string;
135
+ barLabel?: string;
136
+ lineLabel?: string;
137
+ detailLabel?: string;
138
+ /** Nome de um formatter passado ao `<DashboardCharts formatters>` (funções não cabem no JSON). */
139
+ formatDimension?: string;
140
+ clickToFilter?: boolean;
141
+ hideEmpty?: boolean;
142
+ maxLabels?: number;
143
+ barColor?: string;
144
+ lineColor?: string;
145
+ };
146
+ type BarChartDef = BaseChartDef & {
147
+ type: 'bar';
148
+ dimension: string;
149
+ /** Uma série por medida. */
150
+ measures: string[];
151
+ orientation?: 'vertical' | 'horizontal';
152
+ stacked?: boolean;
153
+ /** `dimension` = ordem da dimensão; `desc`/`asc` = pela primeira medida. */
154
+ sort?: 'dimension' | 'desc' | 'asc';
155
+ /** Só os N primeiros depois de ordenar. */
156
+ limit?: number;
157
+ formatDimension?: string;
158
+ clickToFilter?: boolean;
159
+ hideEmpty?: boolean;
160
+ showValues?: boolean;
161
+ };
162
+ type DonutChartDef = BaseChartDef & {
163
+ type: 'donut';
164
+ dimension: string;
165
+ measure: string;
166
+ /** Fatias além dessa quantidade viram "Outros". */
167
+ maxSlices?: number;
168
+ formatDimension?: string;
169
+ clickToFilter?: boolean;
170
+ };
171
+ type TableChartDef = BaseChartDef & {
172
+ type: 'table';
173
+ dimensions?: string[];
174
+ measures: string[];
175
+ /** Formatter por dimensão (`{ mes: 'nomeMes' }`). */
176
+ formatDimensions?: Record<string, string>;
177
+ /** Linha de total, consultada sem as dimensões (razões saem certas, não somadas). */
178
+ showTotal?: boolean;
179
+ /** Coluna (dimensão ou medida) da ordem inicial; o usuário reordena clicando no cabeçalho. */
180
+ sortBy?: string;
181
+ sortDirection?: 'asc' | 'desc';
182
+ clickToFilter?: boolean;
183
+ };
184
+ type KpiChartDef = Omit<BaseChartDef, 'height'> & {
185
+ type: 'kpi';
186
+ /** Medida do número grande (total com os filtros da página). */
187
+ measure: string;
188
+ /** Medida extra numa linha menor embaixo (ex.: volume, custo/t). */
189
+ secondary?: string;
190
+ secondaryLabel?: string;
191
+ };
192
+ type ChartDef = KpiChartDef | ComboChartDef | BarChartDef | DonutChartDef | TableChartDef;
193
+ /** Filtro (slicer) da página: múltipla escolha de uma dimensão, com filtro cruzado. */
194
+ type FilterDef = {
195
+ dimension: string;
196
+ /** Padrão: `label` da dimensão no dicionário. */
197
+ label?: string;
198
+ width?: number;
199
+ /** Nome de um formatter do `<DashboardFilters formatters>` para as opções. */
200
+ formatLabel?: string;
201
+ };
202
+ /**
203
+ * Tela de tamanho fixo: o `<DashboardCanvas>` desenha o dashboard nessas dimensões e o escala para
204
+ * caber na largura da tela, mantendo a proporção — os gráficos não se reorganizam (como o "Ajustar à
205
+ * largura" do Power BI).
206
+ */
207
+ type CanvasDef = {
208
+ /** Largura de projeto, em px (ex.: 1920). */
209
+ width: number;
210
+ /** Altura mínima de projeto, em px (ex.: 1080); conteúdo mais alto estende a tela. */
211
+ height?: number;
212
+ };
213
+ type ChartsLayout = {
214
+ /** Nome do arquivo (`<layoutsDir>/<id>.json`) e chave do rascunho no devtools. */
215
+ id: string;
216
+ /** Ausente = responsivo (12 colunas em telas largas, um gráfico por linha no celular). */
217
+ canvas?: CanvasDef;
218
+ /** Renderizados pelo `<DashboardFilters>`, na ordem. */
219
+ filters?: FilterDef[];
220
+ charts: ChartDef[];
221
+ };
222
+ /**
223
+ * Problemas de forma do layout (vazio = válido). Confere a forma do objeto porque o rascunho do
224
+ * devtools chega como JSON da request.
225
+ */
226
+ declare function validateLayout(layout: ChartsLayout): string[];
227
+ /**
228
+ * Dimensões/medidas que o layout usa e o modelo não tem. Não impede salvar (o modelo pode estar
229
+ * sendo editado junto), mas o gráfico vai mostrar erro.
230
+ */
231
+ declare function layoutModelWarnings(layout: ChartsLayout, model: Pick<ModelDef, 'dimensions' | 'measures'>): string[];
232
+ //#endregion
233
+ //#region src/types.d.ts
234
+ type FilterValue = string | number;
235
+ /** Filtros por dimensão; lista vazia (ou ausente) = sem filtro ("Todos"). */
236
+ type DashboardFilters = Record<string, FilterValue[]>;
237
+ /**
238
+ * Pedidos do devtools. O servidor só aceita quando o `runQuery` recebe `devtools` (em dev); fora
239
+ * disso `debug` é ignorado e o resto é recusado com 400.
240
+ */
241
+ type DashboardDevtoolsRequest = {
242
+ /** Devolve SQL compilado, parâmetros e tempos em `result.devtools.debug`. */
243
+ debug?: boolean;
244
+ /** Rascunho do modelo editado no devtools: substitui o modelo registrado só nesta consulta. */
245
+ model?: ModelDef;
246
+ /** Devolve a definição do modelo registrado e o que o servidor permite (`capabilities`). */
247
+ describe?: boolean;
248
+ /** Esvazia o cache de resultados do processo antes de executar. */
249
+ clearCache?: boolean;
250
+ /** Devolve o `EXPLAIN` da consulta em vez das linhas. */
251
+ explain?: boolean;
252
+ /** Mede a agregação de cada fato usada pela consulta, isoladamente. */
253
+ profile?: boolean;
254
+ /** Tabelas e colunas do banco (`information_schema`), para o autocomplete do editor. */
255
+ schema?: boolean;
256
+ /** Colunas de cada tabela (uma linha de cada), para o diagrama do modelo. */
257
+ columns?: boolean;
258
+ /** Executa cada pedaço do modelo (`devtools.model` ou o registrado) contra o banco. */
259
+ validate?: boolean;
260
+ /** Grava o rascunho no arquivo do modelo (`preview` só devolve o conteúdo novo). */
261
+ save?: 'preview' | 'write';
262
+ /** Grava o layout de gráficos em `<layoutsDir>/<id>.json` (`preview` só devolve o conteúdo novo). */
263
+ saveLayout?: {
264
+ layout: ChartsLayout;
265
+ mode: 'preview' | 'write';
266
+ };
267
+ /** Grava o resultado da consulta (modelo registrado) como snapshot de regressão. */
268
+ snapshot?: {
269
+ name: string;
270
+ overwrite?: boolean;
271
+ };
272
+ /** Lista os snapshots salvos deste modelo. */
273
+ snapshots?: boolean;
274
+ };
275
+ type DashboardQuery = {
276
+ model: string;
277
+ /** Dimensões agrupadas (viram GROUP BY). */
278
+ dimensions?: string[];
279
+ /** Medidas calculadas para cada grupo. */
280
+ measures?: string[];
281
+ filters?: DashboardFilters;
282
+ /** Devolve só os metadados do modelo (rótulos, descrições, formatos; sem SQL) em `result.meta`. */
283
+ meta?: boolean;
284
+ devtools?: DashboardDevtoolsRequest;
285
+ };
286
+ type DashboardRow = Record<string, string | number | null>;
287
+ type DashboardQueryDebug = {
288
+ sql: string;
289
+ params: (string | number)[];
290
+ /** Tempo da execução no banco (num cache hit, o da execução original). */
291
+ durationMs: number;
292
+ cached: boolean;
293
+ /** A consulta rodou contra o rascunho do devtools, não contra o modelo registrado. */
294
+ draft: boolean;
295
+ };
296
+ type ProfileStep = {
297
+ /** `fato:<tabela>` ou `consulta` (a consulta inteira). */
298
+ name: string;
299
+ durationMs: number;
300
+ /** Linhas da agregação da fato (grupos) com os filtros aplicados. */
301
+ rows: number | null;
302
+ };
303
+ type SchemaTable = {
304
+ name: string;
305
+ type: 'table' | 'view';
306
+ columns: {
307
+ name: string;
308
+ type: string;
309
+ }[];
310
+ };
311
+ /** Colunas devolvidas por cada pedaço do modelo (vazio quando não veio nenhuma linha). */
312
+ type ModelColumns = {
313
+ /** Colunas de cada tabela. */
314
+ tables: Record<string, string[]>;
315
+ /** `tabela.coluna` com valor numérico na linha lida. */
316
+ numeric: string[];
317
+ };
318
+ type ModelValidation = {
319
+ /**
320
+ * Erro do banco por pedaço: `table:<nome>`, `relationship:<índice>`, `dimension:<nome>`,
321
+ * `measure:<nome>`.
322
+ */
323
+ errors: Record<string, string>;
324
+ warnings: Record<string, string>;
325
+ columns: ModelColumns;
326
+ };
327
+ type SaveModelResult = {
328
+ path: string;
329
+ previous: string;
330
+ content: string;
331
+ written: boolean;
332
+ warnings: string[];
333
+ };
334
+ type DashboardSnapshot = {
335
+ name: string;
336
+ createdAt: string;
337
+ query: Omit<DashboardQuery, 'devtools' | 'meta'>;
338
+ rows: DashboardRow[];
339
+ };
340
+ type DevtoolsCapabilities = {
341
+ /** O endpoint sabe onde ficam os arquivos dos modelos (`modelsDir`). */
342
+ saveModel: boolean;
343
+ /** O endpoint sabe onde gravar snapshots (`snapshotsDir`). */
344
+ snapshots: boolean;
345
+ /** O endpoint sabe onde ficam os arquivos de layout de gráficos (`layoutsDir`). */
346
+ saveLayout: boolean;
347
+ };
348
+ type DashboardResult = {
349
+ rows: DashboardRow[];
350
+ meta?: ModelMeta;
351
+ devtools?: {
352
+ model?: ModelDef;
353
+ capabilities?: DevtoolsCapabilities;
354
+ debug?: DashboardQueryDebug;
355
+ explain?: DashboardRow[];
356
+ profile?: ProfileStep[];
357
+ schema?: SchemaTable[];
358
+ validation?: ModelValidation;
359
+ columns?: ModelColumns;
360
+ /** Pedaços que o banco recusou ao ler as colunas (mesmas chaves da validação). */
361
+ columnErrors?: Record<string, string>;
362
+ save?: SaveModelResult;
363
+ snapshot?: {
364
+ path: string;
365
+ };
366
+ snapshots?: DashboardSnapshot[];
367
+ };
368
+ };
369
+ //#endregion
370
+ export { FieldMeta as A, ValueFormat as B, KpiChartDef as C, AggregateMeasure as D, validateLayout as E, ModelMeta as F, validateModel as H, RatioMeasure as I, RelationshipDef as L, MeasureDef as M, MeasureMeta as N, Aggregation as O, ModelDef as P, SumMeasure as R, FilterDef as S, layoutModelWarnings as T, modelMeta as V, ChartDef as _, DashboardResult as a, ComboChartDef as b, DevtoolsCapabilities as c, ModelValidation as d, ProfileStep as f, CanvasDef as g, BarChartDef as h, DashboardQueryDebug as i, FormulaMeasure as j, DimensionDef as k, FilterValue as l, SchemaTable as m, DashboardFilters as n, DashboardRow as o, SaveModelResult as p, DashboardQuery as r, DashboardSnapshot as s, DashboardDevtoolsRequest as t, ModelColumns as u, ChartType as v, TableChartDef as w, DonutChartDef as x, ChartsLayout as y, TableDef as z };
371
+ //# sourceMappingURL=types-CB4sK4jP.d.ts.map
@@ -0,0 +1,2 @@
1
+ import { A as FieldMeta, B as ValueFormat, C as KpiChartDef, F as ModelMeta, L as RelationshipDef, M as MeasureDef, N as MeasureMeta, P as ModelDef, S as FilterDef, _ as ChartDef, a as DashboardResult, b as ComboChartDef, c as DevtoolsCapabilities, d as ModelValidation, f as ProfileStep, g as CanvasDef, h as BarChartDef, i as DashboardQueryDebug, j as FormulaMeasure, k as DimensionDef, l as FilterValue, m as SchemaTable, n as DashboardFilters, o as DashboardRow, p as SaveModelResult, r as DashboardQuery, s as DashboardSnapshot, t as DashboardDevtoolsRequest, u as ModelColumns, v as ChartType, w as TableChartDef, x as DonutChartDef, y as ChartsLayout, z as TableDef } from "./types-CB4sK4jP.js";
2
+ export { type BarChartDef, type CanvasDef, type ChartDef, type ChartType, type ChartsLayout, type ComboChartDef, DashboardDevtoolsRequest, DashboardFilters, DashboardQuery, DashboardQueryDebug, DashboardResult, DashboardRow, DashboardSnapshot, DevtoolsCapabilities, type DimensionDef, type DonutChartDef, type FieldMeta, type FilterDef, FilterValue, type FormulaMeasure, type KpiChartDef, type MeasureDef, type MeasureMeta, ModelColumns, type ModelDef, type ModelMeta, ModelValidation, ProfileStep, type RelationshipDef, SaveModelResult, SchemaTable, type TableChartDef, type TableDef, type ValueFormat };
package/dist/types.js ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "name": "@bluemarble/bi",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "Camada semântica (defineModel) + componentes de dashboard e devtools para substituir o Power BI",
5
+ "license": "MIT",
6
+ "author": "bluemarble",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/bluemarble-network/bm-bi.git"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "exports": {
17
+ "./server": {
18
+ "types": "./dist/server/index.d.ts",
19
+ "default": "./dist/server/index.js"
20
+ },
21
+ "./client": {
22
+ "types": "./dist/client/index.d.ts",
23
+ "default": "./dist/client/index.js"
24
+ },
25
+ "./types": {
26
+ "types": "./dist/types.d.ts",
27
+ "default": "./dist/types.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "vp pack",
36
+ "dev": "vp pack --watch",
37
+ "test": "vp test",
38
+ "playground": "vp dev playground",
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "check": "vp check",
41
+ "verify": "vp pack && vp check && vp run typecheck && vp test",
42
+ "release": "bumpp",
43
+ "prepack": "vp pack",
44
+ "prepare": "vp config"
45
+ },
46
+ "devDependencies": {
47
+ "@emotion/react": "^11",
48
+ "@emotion/styled": "^11",
49
+ "@mui/material": "^7",
50
+ "@types/node": "^26.1.1",
51
+ "@types/react": "^19",
52
+ "@types/react-dom": "^19",
53
+ "bumpp": "^11.1.0",
54
+ "mysql2": "^3.24.6",
55
+ "react": "^19",
56
+ "react-dom": "^19",
57
+ "recharts": "^3",
58
+ "typescript": "^7.0.2",
59
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
60
+ "vite-plus": "^0.2.4"
61
+ },
62
+ "peerDependencies": {
63
+ "@mui/material": "^7",
64
+ "react": "^19",
65
+ "recharts": "^3"
66
+ },
67
+ "overrides": {
68
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.1"
69
+ },
70
+ "devEngines": {
71
+ "packageManager": {
72
+ "name": "bun",
73
+ "version": "1.4.3",
74
+ "onFail": "warn"
75
+ }
76
+ }
77
+ }