@legit-sdk/core 0.1.11 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -16,7 +16,7 @@ type FileHandleDelegate = {
16
16
  /**
17
17
  * @returns a unique number per subfs
18
18
  */
19
- close: (fh: CompositFsFileHandle) => void;
19
+ close: (fh: CompositFsFileHandle) => Promise<void>;
20
20
  dataSync: (fh: CompositFsFileHandle) => Promise<void>;
21
21
  read: (fh: CompositFsFileHandle, buffer: Buffer | Uint8Array, offset: number, length: number, position: number) => Promise<TFileHandleReadResult>;
22
22
  appendFile: (fh: CompositFsFileHandle, data: TData, options?: IAppendFileOptions | string) => Promise<void>;
@@ -79,7 +79,8 @@ interface ICompositFsFileHandle {
79
79
  * wrap the filehandle in a SubFsFileHandle and forward all operations to there origin filesystem
80
80
  */
81
81
  declare class CompositFsFileHandle implements ICompositFsFileHandle {
82
- private delegate;
82
+ delegate: FileHandleDelegate;
83
+ private compositeFs;
83
84
  get fsType(): number;
84
85
  private _subFsFileDescriptor;
85
86
  get subFsFileDescriptor(): number;
@@ -89,6 +90,7 @@ declare class CompositFsFileHandle implements ICompositFsFileHandle {
89
90
  realize(compositeFd: number): void;
90
91
  constructor(args: {
91
92
  fs: FileHandleDelegate;
93
+ compositeFs: CompositeFs;
92
94
  subFsFileDescriptor: number;
93
95
  parentFsFileDescriptors: number[];
94
96
  });
@@ -184,16 +186,18 @@ declare class CompositeFs {
184
186
  subFilesystems: CompositeSubFs[];
185
187
  parentFs: CompositeFs | undefined;
186
188
  name: string;
189
+ defaultBranch: string;
187
190
  pathToFileDescriptors: Map<
188
191
  /** path */
189
192
  string, number[]>;
190
193
  openFileHandles: Map<number, CompositFsFileHandle>;
191
194
  private getNextFileDescriptor;
192
- constructor({ name, parentFs, storageFs, gitRoot, }: {
195
+ constructor({ name, parentFs, storageFs, gitRoot, defaultBranch, }: {
193
196
  name: string;
194
197
  parentFs: CompositeFs | undefined;
195
198
  storageFs: typeof nodeFs | undefined;
196
199
  gitRoot: string;
200
+ defaultBranch?: string;
197
201
  });
198
202
  getFilehandle(fd: number): CompositFsFileHandle | undefined;
199
203
  setEphemeralFilesSubFs(subFs: CompositeSubFs): void;
@@ -504,10 +508,15 @@ type VirtualFile = {
504
508
  interface VirtualFileArgs {
505
509
  cacheFs: IFs;
506
510
  filePath: string;
507
- fs: CompositeFs;
508
511
  gitRoot: string;
509
512
  nodeFs?: any;
510
513
  pathParams: any;
514
+ author: {
515
+ name: string;
516
+ email: string;
517
+ date: number;
518
+ timezoneOffset: number;
519
+ };
511
520
  }
512
521
  type VirtualFileDefinition = {
513
522
  type: string;
@@ -525,6 +534,7 @@ type VirtualFileDefinition = {
525
534
  mkdir: (args: VirtualFileArgs & {
526
535
  options?: nodeFs.MakeDirectoryOptions | nodeFs.Mode | null;
527
536
  }) => Promise<void>;
537
+ rmdir?: (args: VirtualFileArgs) => Promise<void>;
528
538
  };
529
539
 
530
540
  /**
@@ -633,8 +643,16 @@ declare class GitSubFs extends BaseCompositeSubFs implements CompositeSubFs {
633
643
  private openFh;
634
644
  private virtualFiles;
635
645
  private legitFileNames;
636
- constructor({ parentFs, gitRoot, virtualFiles, }: {
646
+ storageFs: CompositeFs;
647
+ getAuthor(): Promise<{
648
+ name: string;
649
+ email: string;
650
+ date: number;
651
+ timezoneOffset: number;
652
+ }>;
653
+ constructor({ parentFs, gitStorageFs, gitRoot, virtualFiles, }: {
637
654
  parentFs: CompositeFs;
655
+ gitStorageFs: CompositeFs;
638
656
  gitRoot: string;
639
657
  virtualFiles?: VirtualFileDefinition[];
640
658
  });
@@ -727,6 +745,7 @@ declare class GitSubFs extends BaseCompositeSubFs implements CompositeSubFs {
727
745
  rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
728
746
  fchmod(fh: CompositFsFileHandle, mode: TMode): Promise<void>;
729
747
  unlink(path: PathLike): Promise<void>;
748
+ rmdir(path: PathLike, ...args: any[]): Promise<void>;
730
749
  fileType(): number;
731
750
  }
732
751
 
@@ -738,30 +757,82 @@ type Operation = {
738
757
  };
739
758
  declare const gitBranchOperationsVirtualFile: VirtualFileDefinition;
740
759
 
741
- declare function initMemFSLegitFs(): Promise<CompositeFs>;
742
- declare function initLegitFs(storageFs: typeof nodeFs, gitRoot: string): Promise<CompositeFs>;
760
+ type LegitUser = {
761
+ type: string;
762
+ id: string;
763
+ name: string;
764
+ email: string;
765
+ };
766
+ type LegitAuth = {
767
+ getUser: () => Promise<{
768
+ type: string;
769
+ id: string;
770
+ name: string;
771
+ email: string;
772
+ }>;
773
+ signInAnonymously: () => Promise<void>;
774
+ getMaxAccessTokenForBranch: (branchId: string) => Promise<string | undefined>;
775
+ addAccessToken: (token: string) => Promise<void>;
776
+ };
777
+
778
+ declare function initMemFSLegitFs(): Promise<CompositeFs & {
779
+ auth: LegitAuth;
780
+ sync: {
781
+ start: () => void;
782
+ stop: () => void;
783
+ isRunning: () => boolean;
784
+ loadBranch: (branch: string) => Promise<void>;
785
+ sequentialPush: (branchesToPush: string[]) => Promise<void>;
786
+ };
787
+ push: (branches: string[]) => Promise<void>;
788
+ shareCurrentBranch: () => Promise<string>;
789
+ setCurrentBranch: (branch: string) => Promise<void>;
790
+ getCurrentBranch: () => Promise<string>;
791
+ }>;
743
792
  /**
744
793
  * Creates and configures a LegitFs instance with CompositeFs, GitSubFs, HiddenFileSubFs, and EphemeralSubFs.
745
794
  */
746
- declare function openLegitFs(storageFs: typeof nodeFs, gitRoot: string): CompositeFs;
795
+ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, }: {
796
+ storageFs: typeof nodeFs;
797
+ gitRoot: string;
798
+ anonymousBranch?: string;
799
+ showKeepFiles?: boolean;
800
+ initialAuthor?: LegitUser;
801
+ serverUrl?: string;
802
+ publicKey?: string;
803
+ }): Promise<CompositeFs & {
804
+ auth: LegitAuth;
805
+ sync: {
806
+ start: () => void;
807
+ stop: () => void;
808
+ isRunning: () => boolean;
809
+ loadBranch: (branch: string) => Promise<void>;
810
+ sequentialPush: (branchesToPush: string[]) => Promise<void>;
811
+ };
812
+ push: (branches: string[]) => Promise<void>;
813
+ shareCurrentBranch: () => Promise<string>;
814
+ setCurrentBranch: (branch: string) => Promise<void>;
815
+ getCurrentBranch: () => Promise<string>;
816
+ }>;
747
817
 
748
- declare const createGitSyncService: ({ fs, gitRepoPath, originPrefix, corsProxy, user, password, }: {
818
+ declare const createLegitSyncService: ({ fs, gitRepoPath, serverUrl, auth, anonymousBranch, }: {
749
819
  fs: FsClient;
750
820
  gitRepoPath: string;
751
- originPrefix: string;
752
- corsProxy?: string | undefined;
753
- user: string;
754
- password: string;
821
+ serverUrl?: string;
822
+ auth: LegitAuth;
823
+ anonymousBranch: string;
755
824
  }) => {
756
- clone: (url: string) => Promise<void>;
757
825
  start: () => void;
758
826
  stop: () => void;
827
+ isRunning: () => boolean;
828
+ loadBranch: (branch: string) => Promise<void>;
829
+ sequentialPush: (branchesToPush: string[]) => Promise<void>;
759
830
  };
760
831
 
761
832
  type FileAccess = {
762
833
  fileSave: typeof fileSave;
763
834
  };
764
- declare function getLegitFsAccess(legitFs: ReturnType<typeof openLegitFs>): Promise<FileAccess & {
835
+ declare function getLegitFsAccess(legitFs: Awaited<ReturnType<typeof openLegitFs>>): Promise<FileAccess & {
765
836
  openFile: (filePath: string) => Promise<FileWithHandle>;
766
837
  }>;
767
838
 
@@ -778,5 +849,5 @@ type HistoryItem = {
778
849
  author: User;
779
850
  };
780
851
 
781
- export { CompositeFs, EphemeralSubFs, GitSubFs, HiddenFileSubFs, PassThroughSubFs, createGitSyncService, getLegitFsAccess, gitBranchOperationsVirtualFile, initLegitFs, initMemFSLegitFs, openLegitFs };
852
+ export { CompositeFs, EphemeralSubFs, GitSubFs, HiddenFileSubFs, PassThroughSubFs, createLegitSyncService, getLegitFsAccess, gitBranchOperationsVirtualFile, initMemFSLegitFs, openLegitFs };
782
853
  export type { HistoryItem, Operation, User };