diff --git a/dist/index.js b/dist/index.js index 61194554..d51f5aeb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -554,22 +554,22 @@ return [...this.getTaskPath(boardId, fileId), versionId]; }; // handler - handleFileVersion = (fileVersion) => { - if (checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) == true) { - this.handleBoard(fileVersion); - } else if (checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true) { - this.handleTask(fileVersion); + handleFileContent = (fileContent) => { + if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) { + this.handleBoard(fileContent); + } else if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true) { + this.handleTask(fileContent); } }; - handleBoard = (boardInfoFileVersion) => { - console.log("board", boardInfoFileVersion); + handleBoard = (boardInfoFileContent) => { + console.log("board", boardInfoFileContent); }; - handleTask = (taskFileVersion) => { + handleTask = (taskFileContent) => { }; // boards createBoard = (name) => { - const boardInfoFileVersion = _TaskModel.createBoardInfoFileVersion(v4_default(), name, "standard" /* Standard */); - this.createOrUpdateBoard(boardInfoFileVersion); + const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */); + this.createOrUpdateBoard(boardInfoFileContent); }; listBoardIds = () => { const boardContainerPath = this.getBoardContainerPath(); @@ -577,35 +577,33 @@ return boardNames; }; getBoardInfo = (fileId) => { - const boardInfoFileVersionOrNull = this.fileModel.getLatestFileVersion( + const boardInfoFileContentOrNull = this.fileModel.getLatestFileContent( fileId, - BoardInfoFileVersionReference + BoardInfoFileContentReference ); - return boardInfoFileVersionOrNull; + return boardInfoFileContentOrNull; }; - createOrUpdateBoard = (boardInfoFileVersion) => { - this.fileModel.addFileVersion(boardInfoFileVersion); + createOrUpdateBoard = (boardInfoFileContent) => { + this.fileModel.addFileContent(boardInfoFileContent); const boardDirectoryPath = this.getBoardDirectoryPath( - boardInfoFileVersion.fileId + boardInfoFileContent.fileId ); this.storageModel.write(boardDirectoryPath, ""); }; deleteBoard = (boardId) => { const boardFilePath = this.getBoardFilePath(boardId); const boardDirectoryPath = this.getBoardDirectoryPath(boardId); - console.log(boardFilePath); - console.log(boardDirectoryPath); this.storageModel.removeRecursively(boardFilePath); this.storageModel.removeRecursively(boardDirectoryPath); }; //tasks createTask = (boardId, name) => { - const taskFileVersion = _TaskModel.createTaskFileVersion( + const taskFileContent = _TaskModel.createTaskFileContent( v4_default(), boardId, name ); - this.fileModel.addFileVersion(taskFileVersion); + this.fileModel.addFileContent(taskFileContent); }; listTaskIds = (boardName) => { const getTaskDirPath = this.getTaskContainerPath(boardName); @@ -624,24 +622,24 @@ this.storageModel = storageModel2; } // utility - static createBoardInfoFileVersion = (fileId, name, color) => { - const fileVersion = FileModel.createFileVersion( + static createBoardInfoFileContent = (fileId, name, color) => { + const fileContent = FileModel.createFileContent( fileId, "board-info" ); return { - ...fileVersion, + ...fileContent, name, color }; }; - static createTaskFileVersion = (fileId, name, boardId) => { - const fileVersion = FileModel.createFileVersion( + static createTaskFileContent = (fileId, name, boardId) => { + const fileContent = FileModel.createFileContent( fileId, "task" ); return { - ...fileVersion, + ...fileContent, name, boardId }; @@ -651,19 +649,19 @@ boards: "boards", boardTasks: "tasks" }; - var BoardInfoFileVersionReference = { + var BoardInfoFileContentReference = { dataVersion: DATA_VERSION, fileId: "string", - fileVersionId: "", + fileContentId: "", creationDate: "", type: "board-info", name: "", color: "" }; - var TaskFileVersionReference = { + var TaskFileContentReference = { dataVersion: DATA_VERSION, fileId: "string", - fileVersionId: "", + fileContentId: "", creationDate: "", type: "task", name: "", @@ -691,100 +689,87 @@ getFilePath = (fileId) => { return [...this.getFileContainerPath(), fileId]; }; - getFileVersionPath = (fileId, fileVersionId) => { + getFileContentPath = (fileId, fileContentId) => { const filePath = this.getFilePath(fileId); - return [...filePath, fileVersionId]; + return [...filePath, fileContentId]; }; // handler - handleStringifiedFileVersion = (stringifiedFileVersion) => { - const fileVersion = parseValidObject( - stringifiedFileVersion, - FileVersionReference + handleStringifiedFileContent = (stringifiedFileContent) => { + const fileContent = parseValidObject( + stringifiedFileContent, + FileContentReference ); - if (fileVersion == null) return; - this.handleFileVersion(fileVersion); + if (fileContent == null) return; + this.handleFileContent(fileContent); }; - handleFileVersion = (fileVersion) => { - const didStore = this.storeFileVersion(fileVersion); + handleFileContent = (fileContent) => { + const didStore = this.storeFileContent(fileContent); if (didStore == false) return; - this.taskModel.handleFileVersion(fileVersion); + this.taskModel.handleFileContent(fileContent); }; // methods - addFileVersion = (fileVersion) => { - this.handleFileVersion(fileVersion); - this.chatModel.sendMessage("", fileVersion); + addFileContent = (fileContent) => { + this.handleFileContent(fileContent); + this.chatModel.sendMessage("", fileContent); }; // storage - storeFileVersion = (fileVersion) => { - const fileVersionPath = this.getFileVersionPath( - fileVersion.fileId, - fileVersion.fileVersionId + storeFileContent = (fileContent) => { + const fileContentPath = this.getFileContentPath( + fileContent.fileId, + fileContent.fileContentId ); - const existingFileVersion = this.storageModel.read(fileVersionPath); - if (existingFileVersion != null) return false; - const stringifiedContent = stringify(fileVersion); - this.storageModel.write(fileVersionPath, stringifiedContent); + const existingFileContent = this.storageModel.read(fileContentPath); + if (existingFileContent != null) return false; + const stringifiedContent = stringify(fileContent); + this.storageModel.write(fileContentPath, stringifiedContent); return true; }; listFileIds = () => { return this.storageModel.list(this.getBasePath()); }; - listFileVersionIds = (fileId) => { + listFileContentIds = (fileId) => { const filePath = this.getFilePath(fileId); return this.storageModel.list(filePath); }; - selectLatestFileVersionId = (fileVersionIds) => { - return fileVersionIds[fileVersionIds.length - 1]; + selectLatestFileContentId = (fileContentIds) => { + return fileContentIds[fileContentIds.length - 1]; }; - getFileVersion = (fileId, fileVersionName, reference) => { - const filePath = this.getFileVersionPath(fileId, fileVersionName); - const fileVersionOrNull = this.storageModel.readStringifiable( + getFileContent = (fileId, fileContentName, reference) => { + const filePath = this.getFileContentPath(fileId, fileContentName); + const fileContentOrNull = this.storageModel.readStringifiable( filePath, reference ); - return fileVersionOrNull; + return fileContentOrNull; }; - getLatestFileVersion = (fileId, reference) => { - const fileVersionsIds = this.listFileVersionIds(fileId); - const latestFileVersionId = this.selectLatestFileVersionId(fileVersionsIds); - if (latestFileVersionId == void 0) return null; - const fileVersion = this.getFileVersion( + getLatestFileContent = (fileId, reference) => { + const fileContentsIds = this.listFileContentIds(fileId); + const latestFileContentId = this.selectLatestFileContentId(fileContentsIds); + if (latestFileContentId == void 0) return null; + const fileContent = this.getFileContent( fileId, - latestFileVersionId, + latestFileContentId, reference ); - return fileVersion; + return fileContent; }; // init constructor(chatModel, storageModel2) { this.chatModel = chatModel; this.storageModel = storageModel2; this.taskModel = new TaskModel(this.storageModel, chatModel, this); - this.taskModel.createBoard("Hello"); - const boards = this.taskModel.listBoardIds(); - console.log(boards); - const boardId = boards[0]; - const firstBoardInfo = this.taskModel.getBoardInfo(boardId); - console.log(firstBoardInfo); - const newInfo = TaskModel.createBoardInfoFileVersion( - boardId, - "renamed", - "coral" /* Coral */ - ); - this.taskModel.createOrUpdateBoard(newInfo); - setTimeout(() => this.taskModel.deleteBoard(boardId), 7e3); } // utility - static generateFileVersionId = (creationDate) => { + static generateFileContentId = (creationDate) => { return creationDate + v4_default(); }; - static createFileVersion = (fileId, type) => { + static createFileContent = (fileId, type) => { const creationDate = createTimestamp(); - const fileVersionId = _FileModel.generateFileVersionId(creationDate); + const fileContentId = _FileModel.generateFileContentId(creationDate); return { dataVersion: DATA_VERSION, fileId, - fileVersionId, + fileContentId, creationDate, type }; @@ -795,10 +780,10 @@ model: "model", taskModel: "tasks" }; - var FileVersionReference = { + var FileContentReference = { dataVersion: DATA_VERSION, fileId: "", - fileVersionId: "", + fileContentId: "", creationDate: "", type: "" }; @@ -931,7 +916,7 @@ this.storeColor(); }; // messaging - sendMessage = async (body, fileVersion) => { + sendMessage = async (body, fileContent) => { const senderName = this.settingsModel.username; if (senderName == "") return false; const allChannels = [this.info.primaryChannel]; @@ -944,7 +929,7 @@ senderName, this.info.encryptionKey, body, - fileVersion + fileContent ); this.addMessage(chatMessage); this.connectionModel.sendMessageOrStore(chatMessage); @@ -995,7 +980,7 @@ this.storageModel.writeStringifiable(messagePath, chatMessage); this.chatMessageHandler(chatMessage); } - this.fileModel.handleStringifiedFileVersion(chatMessage.stringifiedFile); + this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile); }; delete = () => { this.chatListModel.untrackChat(this); @@ -1062,7 +1047,7 @@ hasUnreadMessages: false }; }; - static createChatMessage = async (channel, sender, encryptionKey, body, fileVersion) => { + static createChatMessage = async (channel, sender, encryptionKey, body, fileContent) => { const chatMessage = { dataVersion: DATA_VERSION, id: v4_default(), @@ -1073,8 +1058,8 @@ status: "outbox" /* Outbox */, stringifiedFile: "" }; - if (fileVersion != void 0) { - const stringifiedFile = stringify(fileVersion); + if (fileContent != void 0) { + const stringifiedFile = stringify(fileContent); chatMessage.stringifiedFile = stringifiedFile; } if (encryptionKey != "") { diff --git a/src/Model/Chat/chatModel.ts b/src/Model/Chat/chatModel.ts index f2b3266d..c74c721d 100644 --- a/src/Model/Chat/chatModel.ts +++ b/src/Model/Chat/chatModel.ts @@ -1,7 +1,7 @@ // this file is responsible for managing chats. import { DATA_VERSION, ValidObject } from "../Utility/typeSafety"; -import FileModel, { FileVersion } from "../Files/fileModel"; +import FileModel, { FileContent } from "../Files/fileModel"; import StorageModel, { filePaths } from "../Global/storageModel"; import { createTimestamp, @@ -85,7 +85,7 @@ export default class ChatModel { // messaging sendMessage = async ( body: string, - fileVersion: FileVersion + fileContent: FileContent ): Promise => { const senderName = this.settingsModel.username; if (senderName == "") return false; @@ -102,7 +102,7 @@ export default class ChatModel { senderName, this.info.encryptionKey, body, - fileVersion + fileContent ); this.addMessage(chatMessage); @@ -167,7 +167,7 @@ export default class ChatModel { } // file - this.fileModel.handleStringifiedFileVersion(chatMessage.stringifiedFile); + this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile); }; delete = () => { @@ -263,7 +263,7 @@ export default class ChatModel { sender: string, encryptionKey: string, body: string, - fileVersion: FileVersion + fileContent: FileContent ): Promise => { const chatMessage: ChatMessage = { dataVersion: DATA_VERSION, @@ -278,8 +278,8 @@ export default class ChatModel { status: ChatMessageStatus.Outbox, stringifiedFile: "", }; - if (fileVersion != undefined) { - const stringifiedFile = stringify(fileVersion); + if (fileContent != undefined) { + const stringifiedFile = stringify(fileContent); chatMessage.stringifiedFile = stringifiedFile; } diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index 9af1d620..631354e0 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -41,49 +41,49 @@ export default class FileModel { return [...this.getFileContainerPath(), fileId]; }; - getFileVersionPath = (fileId: string, fileVersionId: string): string[] => { + getFileContentPath = (fileId: string, fileContentId: string): string[] => { const filePath: string[] = this.getFilePath(fileId); - return [...filePath, fileVersionId]; + return [...filePath, fileContentId]; }; // handler - handleStringifiedFileVersion = (stringifiedFileVersion: string): void => { - const fileVersion: FileVersion | null = parseValidObject( - stringifiedFileVersion, - FileVersionReference + handleStringifiedFileContent = (stringifiedFileContent: string): void => { + const fileContent: FileContent | null = parseValidObject( + stringifiedFileContent, + FileContentReference ); - if (fileVersion == null) return; + if (fileContent == null) return; - this.handleFileVersion(fileVersion); + this.handleFileContent(fileContent); }; - handleFileVersion = (fileVersion: FileVersion): void => { - const didStore: boolean = this.storeFileVersion(fileVersion); + handleFileContent = (fileContent: FileContent): void => { + const didStore: boolean = this.storeFileContent(fileContent); if (didStore == false) return; - this.taskModel.handleFileVersion(fileVersion); + this.taskModel.handleFileContent(fileContent); }; // methods - addFileVersion = (fileVersion: FileVersion): void => { - this.handleFileVersion(fileVersion); - this.chatModel.sendMessage("", fileVersion); + addFileContent = (fileContent: FileContent): void => { + this.handleFileContent(fileContent); + this.chatModel.sendMessage("", fileContent); }; // storage - storeFileVersion = (fileVersion: FileVersion): boolean => { - const fileVersionPath: string[] = this.getFileVersionPath( - fileVersion.fileId, - fileVersion.fileVersionId + storeFileContent = (fileContent: FileContent): boolean => { + const fileContentPath: string[] = this.getFileContentPath( + fileContent.fileId, + fileContent.fileContentId ); - // check if fileVersion already exists - const existingFileVersion: string | null = - this.storageModel.read(fileVersionPath); - if (existingFileVersion != null) return false; + // check if fileContent already exists + const existingFileContent: string | null = + this.storageModel.read(fileContentPath); + if (existingFileContent != null) return false; - const stringifiedContent: string = stringify(fileVersion); - this.storageModel.write(fileVersionPath, stringifiedContent); + const stringifiedContent: string = stringify(fileContent); + this.storageModel.write(fileContentPath, stringifiedContent); return true; }; @@ -91,45 +91,45 @@ export default class FileModel { return this.storageModel.list(this.getBasePath()); }; - listFileVersionIds = (fileId: string): string[] => { + listFileContentIds = (fileId: string): string[] => { const filePath: string[] = this.getFilePath(fileId); return this.storageModel.list(filePath); }; - selectLatestFileVersionId = ( - fileVersionIds: string[] + selectLatestFileContentId = ( + fileContentIds: string[] ): string | undefined => { - return fileVersionIds[fileVersionIds.length - 1]; + return fileContentIds[fileContentIds.length - 1]; }; - getFileVersion = >( + getFileContent = >( fileId: string, - fileVersionName: string, + fileContentName: string, reference: T ): T | null => { - const filePath: string[] = this.getFileVersionPath(fileId, fileVersionName); - const fileVersionOrNull: T | null = this.storageModel.readStringifiable( + const filePath: string[] = this.getFileContentPath(fileId, fileContentName); + const fileContentOrNull: T | null = this.storageModel.readStringifiable( filePath, reference ); - return fileVersionOrNull; + return fileContentOrNull; }; - getLatestFileVersion = >( + getLatestFileContent = >( fileId: string, reference: T ): T | null => { - const fileVersionsIds: string[] = this.listFileVersionIds(fileId); - const latestFileVersionId: string | undefined = - this.selectLatestFileVersionId(fileVersionsIds); - if (latestFileVersionId == undefined) return null; + const fileContentsIds: string[] = this.listFileContentIds(fileId); + const latestFileContentId: string | undefined = + this.selectLatestFileContentId(fileContentsIds); + if (latestFileContentId == undefined) return null; - const fileVersion: T | null = this.getFileVersion( + const fileContent: T | null = this.getFileContent( fileId, - latestFileVersionId, + latestFileContentId, reference ); - return fileVersion; + return fileContent; }; // init @@ -149,7 +149,7 @@ export default class FileModel { // const firstBoardInfo = this.taskModel.getBoardInfo(boardId); // console.log(firstBoardInfo); - // const newInfo = TaskModel.createBoardInfoFileVersion( + // const newInfo = TaskModel.createBoardInfoFileContent( // boardId, // "renamed", // Color.Coral @@ -160,22 +160,22 @@ export default class FileModel { } // utility - static generateFileVersionId = (creationDate): string => { + static generateFileContentId = (creationDate): string => { return creationDate + v4(); }; - static createFileVersion = ( + static createFileContent = ( fileId: string, type: T - ): FileVersion => { + ): FileContent => { const creationDate: string = createTimestamp(); - const fileVersionId: string = FileModel.generateFileVersionId(creationDate); + const fileContentId: string = FileModel.generateFileContentId(creationDate); return { dataVersion: DATA_VERSION, fileId, - fileVersionId, + fileContentId, creationDate, type, }; @@ -190,20 +190,20 @@ export const subDirectories = { }; // types -export interface FileVersion extends ValidObject { +export interface FileContent extends ValidObject { fileId: string; - fileVersionId: string; + fileContentId: string; creationDate: string; type: T; } // references -export const FileVersionReference: FileVersion = { +export const FileContentReference: FileContent = { dataVersion: DATA_VERSION, fileId: "", - fileVersionId: "", + fileContentId: "", creationDate: "", type: "", diff --git a/src/Model/Files/taskModel.ts b/src/Model/Files/taskModel.ts index a5da5ab7..776353fc 100644 --- a/src/Model/Files/taskModel.ts +++ b/src/Model/Files/taskModel.ts @@ -4,7 +4,7 @@ import { DATA_VERSION, checkMatchesObjectStructure, } from "../Utility/typeSafety"; -import FileModel, { FileVersion } from "./fileModel"; +import FileModel, { FileContent } from "./fileModel"; import ChatModel from "../Chat/chatModel"; import { Color } from "../../ViewModel/colors"; @@ -50,30 +50,30 @@ export default class TaskModel { }; // handler - handleFileVersion = (fileVersion: FileVersion): void => { + handleFileContent = (fileContent: FileContent): void => { if ( - checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) == + checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true ) { - this.handleBoard(fileVersion as BoardInfoVersion); + this.handleBoard(fileContent as BoardInfoVersion); } else if ( - checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true + checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true ) { - this.handleTask(fileVersion as TaskFileVersion); + this.handleTask(fileContent as TaskFileContent); } }; - handleBoard = (boardInfoFileVersion: BoardInfoVersion) => { - console.log("board", boardInfoFileVersion); + handleBoard = (boardInfoFileContent: BoardInfoVersion) => { + console.log("board", boardInfoFileContent); }; - handleTask = (taskFileVersion: TaskFileVersion) => {}; + handleTask = (taskFileContent: TaskFileContent) => {}; // boards createBoard = (name: string): void => { - const boardInfoFileVersion: BoardInfoVersion = - TaskModel.createBoardInfoFileVersion(v4(), name, Color.Standard); - this.createOrUpdateBoard(boardInfoFileVersion); + const boardInfoFileContent: BoardInfoVersion = + TaskModel.createBoardInfoFileContent(v4(), name, Color.Standard); + this.createOrUpdateBoard(boardInfoFileContent); }; listBoardIds = (): string[] => { @@ -83,21 +83,21 @@ export default class TaskModel { }; getBoardInfo = (fileId: string): BoardInfoVersion | null => { - const boardInfoFileVersionOrNull: BoardInfoVersion | null = - this.fileModel.getLatestFileVersion( + const boardInfoFileContentOrNull: BoardInfoVersion | null = + this.fileModel.getLatestFileContent( fileId, - BoardInfoFileVersionReference + BoardInfoFileContentReference ); - return boardInfoFileVersionOrNull; + return boardInfoFileContentOrNull; }; - createOrUpdateBoard = (boardInfoFileVersion: BoardInfoVersion): void => { + createOrUpdateBoard = (boardInfoFileContent: BoardInfoVersion): void => { // store info - this.fileModel.addFileVersion(boardInfoFileVersion); + this.fileModel.addFileContent(boardInfoFileContent); // add to list const boardDirectoryPath: string[] = this.getBoardDirectoryPath( - boardInfoFileVersion.fileId + boardInfoFileContent.fileId ); this.storageModel.write(boardDirectoryPath, ""); }; @@ -112,12 +112,12 @@ export default class TaskModel { //tasks createTask = (boardId: string, name: string): void => { - const taskFileVersion: TaskFileVersion = TaskModel.createTaskFileVersion( + const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent( v4(), boardId, name ); - this.fileModel.addFileVersion(taskFileVersion); + this.fileModel.addFileContent(taskFileContent); }; listTaskIds = (boardName: string): string[] => { @@ -148,34 +148,34 @@ export default class TaskModel { } // utility - static createBoardInfoFileVersion = ( + static createBoardInfoFileContent = ( fileId: string, name: string, color: Color ): BoardInfoVersion => { - const fileVersion: FileVersion<"board-info"> = FileModel.createFileVersion( + const fileContent: FileContent<"board-info"> = FileModel.createFileContent( fileId, "board-info" ); return { - ...fileVersion, + ...fileContent, name, color, }; }; - static createTaskFileVersion = ( + static createTaskFileContent = ( fileId: string, name: string, boardId: string - ): TaskFileVersion => { - const fileVersion: FileVersion<"task"> = FileModel.createFileVersion( + ): TaskFileContent => { + const fileContent: FileContent<"task"> = FileModel.createFileContent( fileId, "task" ); return { - ...fileVersion, + ...fileContent, name, boardId, @@ -189,12 +189,12 @@ export const subDirectories = { }; // types -export interface BoardInfoVersion extends FileVersion<"board-info"> { +export interface BoardInfoVersion extends FileContent<"board-info"> { name: string; color: Color; } -export interface TaskFileVersion extends FileVersion<"task"> { +export interface TaskFileContent extends FileContent<"task"> { name: string; boardId: string; @@ -209,11 +209,11 @@ export interface TaskFileVersion extends FileVersion<"task"> { } // reference -export const BoardInfoFileVersionReference: BoardInfoVersion = { +export const BoardInfoFileContentReference: BoardInfoVersion = { dataVersion: DATA_VERSION, fileId: "string", - fileVersionId: "", + fileContentId: "", creationDate: "", type: "board-info", @@ -222,11 +222,11 @@ export const BoardInfoFileVersionReference: BoardInfoVersion = { color: "" as Color, }; -export const TaskFileVersionReference: TaskFileVersion = { +export const TaskFileContentReference: TaskFileContent = { dataVersion: DATA_VERSION, fileId: "string", - fileVersionId: "", + fileContentId: "", creationDate: "", type: "task",