Implementa o MVP do Adaptador de Planilhas no Elo Pro.
O módulo usa a identidade Supabase, isola cada workspace e registra storage, TTL, runner e biblioteca XLSX como decisões ainda abertas. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
6e23f1533b
144 files changed
+19060
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { createMemoryDb } from "@/infra/db/pglite";
|
||||
import { migrate } from "@/infra/db/migrate";
|
||||
import type { Db } from "@/infra/db/types";
|
||||
import { MemoryCoordinator } from "@/infra/redis/memory";
|
||||
import { MemoryStorage } from "@/infra/storage/memory";
|
||||
import type { AppDeps } from "@/server/spreadsheet-adapter/deps";
|
||||
import { FIXTURES } from "@/dev/fixtures";
|
||||
import type { RequestContext, Role } from "@/domain/spreadsheet-adapter/types";
|
||||
|
||||
export const IDS = FIXTURES;
|
||||
|
||||
export async function createReadyDb(): Promise<Db> {
|
||||
const db = await createMemoryDb();
|
||||
await migrate(db);
|
||||
await db.withService(async (query) => {
|
||||
await query.query(`insert into public.profiles (id, display_name, is_superadmin) values
|
||||
($1,'Ana Owner', false), ($2,'Bruno Agent', false), ($3,'Carla Gestor', false), ($4,'Diego Admin', false), ($5,'Eva Agent', true)`, [
|
||||
IDS.ana, IDS.bruno, IDS.carla, IDS.diego, IDS.eva,
|
||||
]);
|
||||
await query.query(`insert into public.workspaces (id, name) values ($1,'Alpha'), ($2,'Beta')`, [IDS.alpha, IDS.beta]);
|
||||
await query.query(
|
||||
`insert into public.workspace_members (workspace_id, user_id, role) values
|
||||
($1,$2,'owner'), ($1,$3,'agent'), ($1,$4,'gestor'), ($5,$6,'admin'), ($5,$7,'agent')`,
|
||||
[IDS.alpha, IDS.ana, IDS.bruno, IDS.carla, IDS.beta, IDS.diego, IDS.eva],
|
||||
);
|
||||
await query.query(
|
||||
`insert into public.workspace_module_flags (workspace_id, module_key, enabled) values
|
||||
($1,'spreadsheet_adapter', true), ($2,'spreadsheet_adapter', false)`,
|
||||
[IDS.alpha, IDS.beta],
|
||||
);
|
||||
});
|
||||
return db;
|
||||
}
|
||||
|
||||
export function depsOf(db: Db, coordinator = new MemoryCoordinator()): AppDeps & { storage: MemoryStorage } {
|
||||
return { db, storage: new MemoryStorage(), coordinator, ttlSeconds: 3600, now: () => new Date("2026-10-02T12:00:00.000Z") };
|
||||
}
|
||||
|
||||
export function ctxOf(user: keyof typeof IDS, workspace: "alpha" | "beta", role: Role, moduleEnabled: boolean, allow = false): RequestContext {
|
||||
return {
|
||||
userId: IDS[user],
|
||||
displayName: user,
|
||||
isSuperadmin: user === "eva",
|
||||
workspaceId: IDS[workspace],
|
||||
workspaceName: workspace,
|
||||
role,
|
||||
moduleEnabled,
|
||||
allowNonAdminModelUpload: allow,
|
||||
};
|
||||
}
|
||||
|
||||
export async function readDownSql(): Promise<string> {
|
||||
return readFile(path.join(process.cwd(), "migrations", "down", "0002_spreadsheet_adapter_down.sql"), "utf8");
|
||||
}
|
||||
Reference in new issue
Block a user