remove pnpm as package manager. fix jest test issues. use npm for now.

This commit is contained in:
Jordan
2025-02-08 08:29:52 -08:00
parent 97ca20ed57
commit 58a3829347
14 changed files with 20661 additions and 6019 deletions

View File

@ -14,12 +14,6 @@ export class Message {
constructor (public conversation : Conversation, public speaker : Speaker, public text? : string) {}
public async translate() {
const translator = this.conversation.translator
if (!this.text) throw new Error("No text")
this.translation = await translator.translate(this.text, this.otherLanguage);
}
get otherSpeaker() {
return this.speaker.id === this.conversation.host.id ? this.conversation.guest : this.conversation.host
}
@ -27,6 +21,13 @@ export class Message {
get otherLanguage() {
return this.otherSpeaker.language
}
public async translate() {
const translator = this.conversation.translator
if (!this.text) throw new Error("No text")
console.log("Translating from %s -> %s", this.speaker.language, this.otherSpeaker.language);
this.translation = await translator.translate(this.text, this.otherLanguage);
}
}
export class Conversation extends Array<Message> {

View File

@ -1,6 +1,4 @@
import SQLite from "react-native-sqlite-storage"
SQLite.enablePromise(true);
import * as SQLite from 'expo-sqlite';
export const MIGRATE_UP = {
1: [
@ -19,15 +17,12 @@ export const MIGRATE_DOWN = {
}
export async function getDb(migrationDirection : "up" | "down" = "up") {
const db = await SQLite.openDatabase({
name: "translation_terrace",
});
const db = await SQLite.openDatabaseAsync('translation_terrace');
for (let [migration, statements] of Object.entries(MIGRATE_UP)) {
for (let statement of statements) {
await db.transaction(async (tx) => {
await tx.executeSql(statement)
});
console.log(statement)
await db.runAsync(statement);
}
}

View File

@ -1,30 +1,42 @@
import { SQLiteDatabase } from "react-native-sqlite-storage";
import { SQLiteDatabase } from "expo-sqlite";
export class Settings {
static KEYS = [
"host_language",
"libretranslate_base_url",
'ui_direction',
]
constructor(public db: SQLiteDatabase) {
}
private async getValue(key: string) {
// For security...ensure key is a valid value
if (!Settings.KEYS.includes(key)) {
throw new Error(`Invalid setting: '${key}'`)
}
const query = `
SELECT ${key}
SELECT ?
FROM settings
LIMIT 1`
const result = await this.db.executeSql(
const result = await this.db.getFirstAsync(
query
);
result[0].rows.item(0).host_language;
return result ? (result as any)[key] : null;
}
private async setValue(key: string, value: any) {
if (!Settings.KEYS.includes(key)) {
throw new Error(`Invalid setting: '${key}'`)
}
const statement = `INSERT INTO settings (${key})
SELECT '?'
ON CONFLICT DO UPDATE SET ${key} = ?`
await this.db.transaction(async (tx) => {
await tx.executeSql(statement, [value, value]);
})
await this.db.runAsync(statement, [value, value]);
}
async setHostLanguage(value: string) {