-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marcos Candeia <marrcooos@gmail.com>
- Loading branch information
Showing
3 changed files
with
88 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { type Operation } from "fast-json-patch"; | ||
|
||
export interface BaseFilePatch { | ||
path: string; | ||
} | ||
export type TextFilePatchOperation = InsertAtOperation | DeleteAtOperation; | ||
|
||
export interface TextFielPatchOperationBase { | ||
at: number; | ||
} | ||
|
||
export interface InsertAtOperation extends TextFielPatchOperationBase { | ||
text: string; | ||
} | ||
|
||
export interface DeleteAtOperation extends TextFielPatchOperationBase { | ||
length: number; | ||
} | ||
export interface TextFilePatch extends BaseFilePatch { | ||
operations: TextFilePatchOperation[]; | ||
timestamp: number; | ||
} | ||
|
||
export interface TextFileSet extends BaseFilePatch { | ||
content: string | null; | ||
} | ||
|
||
export type FilePatch = JSONFilePatch | TextFilePatch | TextFileSet; | ||
|
||
export const isJSONFilePatch = (patch: FilePatch): patch is JSONFilePatch => { | ||
return (patch as JSONFilePatch).patches !== undefined; | ||
}; | ||
|
||
export const isTextFileSet = (patch: FilePatch): patch is TextFileSet => { | ||
return (patch as TextFileSet).content !== undefined; | ||
}; | ||
|
||
export interface JSONFilePatch extends BaseFilePatch { | ||
patches: Operation[]; | ||
} | ||
|
||
export interface VolumePatchRequest { | ||
messageId?: string; | ||
patches: FilePatch[]; | ||
} | ||
|
||
export interface FilePatchResult { | ||
path: string; | ||
accepted: boolean; | ||
content?: string; | ||
deleted?: boolean; | ||
} | ||
|
||
export interface VolumePatchResponse { | ||
results: FilePatchResult[]; | ||
timestamp: number; | ||
} | ||
|
||
export interface FsEvent { | ||
messageId?: string; | ||
path: string; | ||
deleted?: boolean; | ||
timestamp: number; | ||
} | ||
|
||
export type ServerEvent = FsEvent; | ||
|
||
export interface File { | ||
content: string; | ||
} | ||
|
||
export type FileSystemNode = Record<string, File>; |