Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
22,794 changes: 22,427 additions & 367 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@babel/plugin-proposal-optional-chaining": "^7.11.0",
"@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-typescript": "^7.10.1",
"@parcel/transformer-typescript-types": "^2.0.1",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@types/pouchdb": "^6.4.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ export class Session implements SessionMetadata {
return this.#storage.sessionNumAttempts(this._id);
}

// function to get all attempts in a session. Can be very slow for large sessions
async getAllAttempts(): Promise<StoredAttempt[]> {
Comment thread
infraredCoding marked this conversation as resolved.
Outdated
var totalSolves = await this.numAttempts();
return this.#cache.nMostRecent(totalSolves);
}

/******** Debug ********/

private async debugPouch(): Promise<Storage> {
Expand Down
7 changes: 6 additions & 1 deletion src/TimerDB.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventName, StoredAttempt, Attempt } from "./data/Attempt";
import { PouchDBStorage } from "./storage/PouchDBStorage";
import { Session, SessionCreationOptions } from "./session";
import { Session, SessionCreationOptions } from "./Session";
import { Storage } from "./storage/Storage";

export class TimerDB {
Expand All @@ -13,6 +13,11 @@ export class TimerDB {
this.storage.connectRemoteDB(params.username, params.password);
}

// takes DB URL as a param
startSyncCustom(params: { dbURL: string, username: string; password: string }): void {
this.storage.connectRemoteDBCustom(params.dbURL, params.username, params.password);
}

// TODO: provide a way to get only sessions with solves.
async getSessions(): Promise<Session[]> {
const sessionMetadataList = await this.storage.getAllSessions();
Expand Down
4 changes: 4 additions & 0 deletions src/data/Attempt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface Attempt {
solution?: AlgString; // TODO
penalties?: Penalty[]; // TODO

// simplified way of indicating Penalty, users must write their own penalty logic
// Ok = 0, +2 = 1, DNF = -1 (csTimer style)
penaltyCode?: number;
Comment thread
infraredCoding marked this conversation as resolved.
Outdated

device?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/storage/AttemptCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { StoredAttempt } from "../data/Attempt";
import { PouchDBStorage } from "./PouchDBStorage";
import { AttemptUUID, SessionUUID } from "../UUID";
import { Storage } from "./storage";
import { Storage } from "./Storage";

const MIN_SIZE_CAP = 1000;
const MAX_SIZE_CAP = 1050;
Expand Down
20 changes: 19 additions & 1 deletion src/storage/PouchDBStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isValidStoredSessionMetadata,
isValidSessionMetadata,
} from "../data/validate";
import { SyncChangeListener } from "./storage";
import { SyncChangeListener } from "./Storage";

PouchDB.plugin(PouchDBFind);

Expand Down Expand Up @@ -54,6 +54,24 @@ export class PouchDBStorage {
this.sync.on("error", this.onSyncError.bind(this));
}

// takes DB URL as a param
connectRemoteDBCustom(dbURL: string, username: string, password: string): void {
Comment thread
infraredCoding marked this conversation as resolved.
Outdated
const url = new URL(dbURL);
url.username = username;
url.password = password;
url.pathname = `results-${localStorage.timerDBUsername}`;
const authedURL = url.toString();

this.remoteDB = new PouchDB(authedURL);

this.sync = this.localDB.sync(this.remoteDB, {
live: true,
retry: true,
});
this.sync.on("change", this.onSyncChange.bind(this));
this.sync.on("error", this.onSyncError.bind(this));
}

addListener(listener: SyncChangeListener): void {
this.listeners.push(listener);
}
Expand Down
1 change: 1 addition & 0 deletions src/storage/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type SyncChangeListener = (attempt: StoredAttempt[]) => void;

export declare interface Storage {
connectRemoteDB(username: string, password: string): void;
Comment thread
infraredCoding marked this conversation as resolved.
Outdated
connectRemoteDBCustom(dbURL: string, username: string, password: string): void;

// Sessions
createSession(
Expand Down