Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions dist/db.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,49 @@ interface Term {
createdAt: string;
updatedAt: string;
progress?: TermProgress;
progressHistory?: TermProgressHistory[];
topConfusionPairs?: TermConfusionPair[];
topReverseConfusionPairs?: TermConfusionPair[];
}
interface TermAtp {
id: number | string;
term: string;
def: string;
termSnapshot: string;
defSnapshot: string;
}
interface PracticeTest {
id: number;
studysetIds: (number | string)[];
questionTermIds: (number | string)[];
distractorTermIds: (number | string)[];
timestamp: string;
questionsCorrect: number;
questionsTotal: number;
questions: Question[];
questions?: PracticeTestQuestion[];
}
interface PracticeTestQuestion {
id: number;
practiceTestId: number;
termId: number | string;
termSnapshot: string;
defSnapshot: string;
type: "mcq" | "tfq" | "frq";
position: number;
correct: boolean;
answerWith: string;
data: MCQData | TFQData | FRQData;
}
interface MCQData {
distractors: TermAtp[];
correctChoiceIndex: number;
answeredIndex: number | null;
}
interface TFQData {
distractor?: TermAtp | null;
answeredBool: boolean;
}
interface FRQData {
answeredString: string;
userMarkedCorrect?: boolean;
}
interface Question {
id?: number;
mcq?: MCQ;
tfq?: TFQ;
frq?: FRQ;
Expand Down Expand Up @@ -87,17 +110,6 @@ interface TermProgress {
termLastReviewedAt?: string;
defFirstReviewedAt?: string;
defLastReviewedAt?: string;
termLeitnerSystemBox?: number;
defLeitnerSystemBox?: number;
}
interface TermProgressHistory {
id: number;
timestamp: string;
termId: number | string;
termCorrectCount: number;
termIncorrectCount: number;
defCorrectCount: number;
defIncorrectCount: number;
}
interface TermConfusionPair {
id: number;
Expand All @@ -117,10 +129,10 @@ declare const db: Dexie & {
studysets: EntityTable<Studyset, "id">;
terms: EntityTable<Term, "id">;
practiceTests: EntityTable<PracticeTest, "id">;
practiceTestQuestions: EntityTable<PracticeTestQuestion, "id">;
termProgress: EntityTable<TermProgress, "id">;
termProgressHistory: EntityTable<TermProgressHistory, "id">;
termConfusionPairs: EntityTable<TermConfusionPair, "id">;
images: EntityTable<Image, "key">;
};
export type { Studyset, Term, TermAtp, PracticeTest, Question, MCQ, TFQ, FRQ, TermProgress, TermProgressHistory, TermConfusionPair };
export type { Studyset, Term, TermAtp, PracticeTest, PracticeTestQuestion, MCQData, TFQData, FRQData, Question, MCQ, TFQ, FRQ, TermProgress, TermConfusionPair };
export { db };
92 changes: 89 additions & 3 deletions dist/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ db.version(16).stores({
// Helper to convert Term to TermAtp and track IDs
const toTermAtp = (t, isQuestion) => {
if (!t)
return { id: 0, term: '', def: '' };
return { id: 0, termSnapshot: '', defSnapshot: '' };
if (t.id) {
if (isQuestion)
questionTermIds.add(t.id);
Expand All @@ -194,8 +194,8 @@ db.version(16).stores({
studysetIds.add(t.studysetId);
return {
id: t.id,
term: t.term || '',
def: t.def || ''
termSnapshot: t.term || t.termSnapshot || '',
defSnapshot: t.def || t.defSnapshot || ''
};
};
if (q.mcq) {
Expand Down Expand Up @@ -270,4 +270,90 @@ db.version(16).stores({
}
});
});
db.version(17).stores({
practiceTests: "++id, timestamp, *studysetIds, questionsCorrect, questionsTotal",
practiceTestQuestions: "++id, practiceTestId, termId, [practiceTestId+position]",
termProgress: "++id, termId, termFirstReviewedAt, termLastReviewedAt, " +
"termReviewCount, defFirstReviewedAt, defLastReviewedAt, " +
"defReviewCount, termCorrectCount, termIncorrectCount, defCorrectCount, defIncorrectCount",
termProgressHistory: null
}).upgrade(async (tx) => {
await tx.table("termProgress").toCollection().modify(tp => {
delete tp.termLeitnerSystemBox;
delete tp.defLeitnerSystemBox;
});
await tx.table("practiceTests").toCollection().each(async (pt) => {
if (pt.questions && Array.isArray(pt.questions)) {
for (let i = 0; i < pt.questions.length; i++) {
const q = pt.questions[i];
let type = "mcq";
let qData = {};
let termAtp = null;
let correct = false;
let answerWith = "";
if (q.mcq) {
type = "mcq";
termAtp = q.mcq.term;
correct = q.mcq.correct;
answerWith = q.mcq.answerWith;
qData = {
distractors: (q.mcq.distractors || []).map((d) => ({
id: d.id,
termSnapshot: d.termSnapshot || d.term || "",
defSnapshot: d.defSnapshot || d.def || ""
})),
correctChoiceIndex: q.mcq.correctChoiceIndex,
answeredIndex: q.mcq.answeredIndex
};
}
else if (q.tfq) {
type = "tfq";
termAtp = q.tfq.term;
correct = q.tfq.correct;
answerWith = q.tfq.answerWith;
qData = {
distractor: q.tfq.distractor ? {
id: q.tfq.distractor.id,
termSnapshot: q.tfq.distractor.termSnapshot || q.tfq.distractor.term || "",
defSnapshot: q.tfq.distractor.defSnapshot || q.tfq.distractor.def || ""
} : null,
answeredBool: q.tfq.answeredBool
};
}
else if (q.frq) {
type = "frq";
termAtp = q.frq.term;
correct = q.frq.correct;
answerWith = q.frq.answerWith;
let userMarkedCorrect = q.frq.userMarkedCorrect;
if (!correct && userMarkedCorrect) {
correct = true;
userMarkedCorrect = true;
}
qData = {
answeredString: q.frq.answeredString,
userMarkedCorrect: userMarkedCorrect
};
}
if (termAtp) {
await tx.table("practiceTestQuestions").add({
practiceTestId: pt.id,
termId: termAtp.id,
termSnapshot: termAtp.termSnapshot || termAtp.term || "",
defSnapshot: termAtp.defSnapshot || termAtp.def || "",
type: type,
position: i,
correct: correct,
answerWith: answerWith,
data: qData
});
}
}
}
delete pt.questions;
delete pt.questionTermIds;
delete pt.distractorTermIds;
await tx.table("practiceTests").put(pt);
});
});
export { db };
8 changes: 4 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Term, TermConfusionPair } from "./db";
import { Term, TermConfusionPair, PracticeTestQuestion } from "./db";
type StudysetResolveProps = {
terms?: boolean | TermResolveProps;
practiceTests?: boolean;
};
type TermResolveProps = {
progress?: boolean;
progressHistory?: boolean;
topConfusionPairs?: boolean;
topReverseConfusionPairs?: boolean;
termImageUrl?: boolean;
Expand Down Expand Up @@ -34,7 +33,8 @@ export declare const idbApiLayer: {
getTopConfusionPairs: (termId: any, resolveProps?: any) => Promise<TermConfusionPair[]>;
getTopReverseConfusionPairs: (confusedTermId: any, resolveProps?: any) => Promise<TermConfusionPair[]>;
recordConfusionPairs: (confusionPairs: any) => Promise<boolean>;
recordPracticeTest: (practiceTest: any) => Promise<import("./db").PracticeTest | undefined>;
updatePracticeTest: (id: number, practiceTest: any) => Promise<import("./db").PracticeTest | undefined>;
recordPracticeTest: (practiceTest: any) => Promise<import("./db").PracticeTest | null>;
getPracticeTestWithQuestions: (ptId: number) => Promise<import("./db").PracticeTest | null>;
updatePracticeTestQuestion: (id: number, correct: boolean, userMarkedCorrect?: boolean) => Promise<PracticeTestQuestion | undefined>;
getPracticeTestsByTermId: (termId: number | string) => Promise<import("./db").PracticeTest[]>;
};
Loading
Loading