import { createClient , PostgrestResponse , SupabaseClient } from '@supabase/supabase-js' ; import type { definitions } from '@inlang/database' ; import { ensureDirectoryExistence , pgResp2val } from './helpers' ; import { readEnvir as readSupaEnvir } from './services/supabase' ; import { exportI18nNext } from './adapters/reacti18n' ; import * as fs from 'fs' ; export async function download2prj ( pid ) { const sb = readSupaEnvir ( ) ; const dbR = await dbReadTrans ( sb ! , pid ) ; console . log ( dbR ) ; const exportFs = exportI18nNext ( { translations : dbR } ) ; exportFs . files . forEach ( ( file ) => { ensureDirectoryExistence ( file . path ) ; fs . writeFileSync ( file . path , JSON . stringify ( file . content , null , 4 ) ) ; } ) ; } async function readData ( sb , loggedInUserId , text ) { let progO = await sb . from < definitions [ 'project' ] > ( 'project' ) . select ( '*' ) . eq ( 'id' , loggedInUserId ) . single ( ) ; } async function writeData ( sb , loggedInUserId , text , json ) { let { data , error } = await sb . from ( 'messages' ) . upsert ( { id : 3 } ) ; } async function loginWithToken ( sb , jwt ) { let x = await sb . auth . api . getUser ( jwt ) ; let user = x . user ; console . log ( x . error ) ; return user ; } async function dbReadProj ( sb ) { let prj = ( await sb . from < definitions [ 'project' ] > ( 'project' ) . select ( '*' ) ) . data ; } async function dbReadTrans ( sb , projId ) { let translations = await sb . from < definitions [ 'translation' ] > ( 'translation' ) . select ( '*' ) . match ( { id : projId } ) ; return pgResp2val ( translations , 'dbReadTrans' ) ; } type dbGetArgs = { projectId : definitions [ 'project' ] [ 'id' ] ; } ; export async function dbRead ( sb , args ) { const project = await sb . from < definitions [ 'project' ] > ( 'project' ) . select ( '*' ) . match ( { id : args . projectId } ) . single ( ) ; const languages = await sb . from < definitions [ 'language' ] > ( 'language' ) . select ( '*' ) . match ( { project_id : args . projectId } ) ; const keys = await sb . from < definitions [ 'key' ] > ( 'key' ) . select ( '*' ) . match ( { project_id : args . projectId } ) ; const translations = await sb . from < definitions [ 'translation' ] > ( 'translation' ) . select ( '*' ) ; }