Skip to content

Commit

Permalink
big commit -- tease apart later
Browse files Browse the repository at this point in the history
  • Loading branch information
dtkav committed Jul 9, 2024
1 parent 7ea3e15 commit 40e11a4
Show file tree
Hide file tree
Showing 33 changed files with 1,666 additions and 706 deletions.
2 changes: 1 addition & 1 deletion debug-tools/unused.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const projectRoot = path.join(__dirname, 'src'); // Adjust this to your project's source directory
const projectRoot = path.join(__dirname, "..", 'src'); // Adjust this to your project's source directory
const fileExtensions = ['.ts', '.tsx', '.svelte']; // Including .svelte files

async function getAllFiles(dir) {
Expand Down
8 changes: 6 additions & 2 deletions src/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SharedFolder } from "./SharedFolder";
import { YText } from "yjs/dist/src/internals";
import { curryLog } from "./debug";
import { LoginManager } from "./LoginManager";
import { S3RN, S3Document } from "./S3RN";
import { S3Document, S3RN, S3RemoteDocument } from "./S3RN";

export class Document extends HasProvider {
guid: string;
Expand All @@ -21,7 +21,11 @@ export class Document extends HasProvider {
loginManager: LoginManager,
parent: SharedFolder
) {
const s3rn = S3RN.encode(new S3Document(parent.guid, guid));
const s3rn = S3RN.encode(
parent.relayId
? new S3RemoteDocument(parent.relayId, parent.guid, guid)
: new S3Document(parent.guid, guid)
);
super(s3rn, parent.tokenStore, loginManager);
this.guid = guid;
this._parent = parent;
Expand Down
39 changes: 0 additions & 39 deletions src/FolderSuggest.ts

This file was deleted.

12 changes: 9 additions & 3 deletions src/HasProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { LoginManager } from "./LoginManager";
import { LiveTokenStore } from "./LiveTokenStore";
import type { ClientToken } from "./y-sweet";
import { promiseWithTimeout } from "./promiseUtils";
import { S3Document, S3RN, S3Relay, type S3RNType } from "./S3RN";
import {
S3RemoteDocument,
S3RN,
S3Relay,
type S3RNType,
S3RemoteFolder,
} from "./S3RN";
import { Platform } from "obsidian";

export type ConnectionStatus =
Expand Down Expand Up @@ -45,9 +51,9 @@ function s3rnToYsweetDocId(s3rn: string): string {
// YSweet has various restrictions on the allowed characterset
const entity: S3RNType = S3RN.decode(s3rn);
let ysweetDocId: string;
if (entity instanceof S3Document) {
if (entity instanceof S3RemoteDocument) {
ysweetDocId = entity.relayId + "-" + entity.documentId;
} else if (entity instanceof S3Relay) {
} else if (entity instanceof S3RemoteFolder) {
ysweetDocId = entity.relayId;
} else {
throw new Error("Invalid type");
Expand Down
12 changes: 9 additions & 3 deletions src/LiveTokenStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { requestUrl } from "obsidian";
import { curryLog } from "./debug";
import type { ClientToken } from "./y-sweet";
import { LocalStorage } from "./LocalStorage";
import { S3RN, S3Document, S3Relay, type S3RNType } from "./S3RN";
import {
S3RN,
S3RemoteDocument,
S3Relay,
type S3RNType,
S3RemoteFolder,
} from "./S3RN";

declare const API_URL: string;

Expand Down Expand Up @@ -35,12 +41,12 @@ async function refresh(
log(`${documentId}`);
const entity: S3RNType = S3RN.decode(documentId);
let payload: string;
if (entity instanceof S3Document) {
if (entity instanceof S3RemoteDocument) {
payload = JSON.stringify({
docId: entity.documentId,
relay: entity.relayId,
});
} else if (entity instanceof S3Relay) {
} else if (entity instanceof S3RemoteFolder) {
payload = JSON.stringify({
relay: entity.relayId,
docId: entity.relayId,
Expand Down
3 changes: 3 additions & 0 deletions src/LoginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export class LoginManager extends Observable<LoginManager> {
};
this.openSettings = openSettings;
this.url = new OAuth2Url();
this.user = this.pb.authStore.isValid
? this.makeUser(this.pb.authStore)
: undefined;
}

log(message: string, ...args: unknown[]) {
Expand Down
42 changes: 22 additions & 20 deletions src/Relay.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
import type { SharedFolder } from "./SharedFolder";

export type Role = "Owner" | "Member";

// A relay is a shared folder "constructor"
// It is a centralized concept, whereas each user can mount the relay into their own vault as a shared folder.
// The relay has a single owner and a limit on the number of users.
// A relay can have billing information associated with it.
// The billing information can be complex, but the subscription manager will also control user_limit and type.
export interface Relay {
interface Identified {
id: string;
}
interface Updatable<T> {
update(update: unknown): T;
}

export interface RemoteSharedFolder
extends Identified,
Updatable<RemoteSharedFolder> {
id: string;
guid: string;
name: string;
private: boolean;
relay: Relay;
}

export interface Relay extends Identified, Updatable<Relay> {
id: string;
guid: string;
name: string;
path?: string;
user_limit: number;
role: Role;
owner: boolean;
folder?: SharedFolder;
invitation?: RelayInvitation;

update(update: unknown): Relay;
}

export interface RelayRoleUser {
export interface RelayRoleUser extends Identified {
id: string;
name: string;
}

export interface RelayRole {
export interface RelayRole extends Identified, Updatable<RelayRole> {
id: string;
user: RelayRoleUser;
userId: string;
role: Role;
relay?: Relay;

update(update: unknown): RelayRole;
relay: Relay;
}

export interface RelayInvitation {
export interface RelayInvitation extends Updatable<RelayInvitation> {
id: string;
role: Role;
relay: Relay;
key: string;

update(update: unknown): RelayInvitation;
}
Loading

0 comments on commit 40e11a4

Please sign in to comment.