@legit-sdk/core 0.2.1 → 0.2.3

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
@@ -1,3 +1,4 @@
1
+ import { fileSave, FileWithHandle } from 'browser-fs-access';
1
2
  import * as nodeFs from 'node:fs';
2
3
  import { MakeDirectoryOptions, Mode } from 'node:fs';
3
4
  import * as memfs_lib_node_types_misc_js from 'memfs/lib/node/types/misc.js';
@@ -6,11 +7,29 @@ import { IAppendFileOptions, IStatOptions, IReadFileOptions, IWriteFileOptions,
6
7
  import { PathLike as PathLike$1 } from 'fs';
7
8
  import { IFs } from 'memfs';
8
9
  import { FsClient } from 'isomorphic-git';
9
- import { fileSave, FileWithHandle } from 'browser-fs-access';
10
+
11
+ type LegitUser = {
12
+ type: string;
13
+ id: string;
14
+ name: string;
15
+ email: string;
16
+ };
17
+ type LegitAuth = {
18
+ getUser: () => Promise<{
19
+ type: string;
20
+ id: string;
21
+ name: string;
22
+ email: string;
23
+ }>;
24
+ signInAnonymously: () => Promise<void>;
25
+ getMaxAccessTokenForBranch: (branchId: string) => Promise<string | undefined>;
26
+ addAccessToken: (token: string) => Promise<void>;
27
+ };
10
28
 
11
29
  type CompositeSubFsDir = Pick<IDir, "path" | "close" | "read" | typeof Symbol.asyncIterator>;
12
30
 
13
31
  type FileHandleDelegate = {
32
+ name: string;
14
33
  fileType: () => number;
15
34
  open: (filePath: string, flags: string, mode?: number) => Promise<CompositFsFileHandle>;
16
35
  /**
@@ -31,6 +50,7 @@ type FileHandleDelegate = {
31
50
  };
32
51
 
33
52
  type CompositeSubFs = Pick<typeof nodeFs.promises, 'access' | 'link' | 'readdir' | 'readlink' | 'unlink' | 'rename' | 'rmdir' | 'symlink'> & {
53
+ name: string;
34
54
  readFile(path: nodeFs.PathLike | IFileHandle, options?: IReadFileOptions | string): Promise<TDataOut>;
35
55
  stat(path: nodeFs.PathLike, opts?: IStatOptions & {
36
56
  bigint?: false;
@@ -125,6 +145,23 @@ declare class CompositeFsDir {
125
145
  get path(): string;
126
146
  }
127
147
 
148
+ type FsOperationLogger = (args: {
149
+ fsName: string;
150
+ fd?: CompositFsFileHandle | undefined;
151
+ path: string;
152
+ operation: string;
153
+ operationArgs: any;
154
+ }) => Promise<void>;
155
+ declare const createFsOperationFileLogger: (fs: {
156
+ writeFile: (path: string, data: string) => Promise<void>;
157
+ }) => (args: {
158
+ fsName: string;
159
+ fd?: CompositFsFileHandle | undefined;
160
+ path: string;
161
+ operation: string;
162
+ operationArgs: any;
163
+ }) => Promise<void>;
164
+
128
165
  /**
129
166
  *
130
167
  * The CompositFs handles distribution of file operations to its sub filesystems and keeps track of open file handles.
@@ -191,6 +228,7 @@ declare class CompositeFs {
191
228
  /** path */
192
229
  string, number[]>;
193
230
  openFileHandles: Map<number, CompositFsFileHandle>;
231
+ logOperation: FsOperationLogger | undefined;
194
232
  private getNextFileDescriptor;
195
233
  constructor({ name, parentFs, storageFs, gitRoot, defaultBranch, }: {
196
234
  name: string;
@@ -199,6 +237,8 @@ declare class CompositeFs {
199
237
  gitRoot: string;
200
238
  defaultBranch?: string;
201
239
  });
240
+ setLoggger(logger: FsOperationLogger | undefined): void;
241
+ logOperationOnFileDescsriptor(fd: CompositFsFileHandle, operation: string, args: any): Promise<void>;
202
242
  getFilehandle(fd: number): CompositFsFileHandle | undefined;
203
243
  setEphemeralFilesSubFs(subFs: CompositeSubFs): void;
204
244
  setHiddenFilesSubFs(subFs: CompositeSubFs): void;
@@ -263,11 +303,62 @@ declare class CompositeFs {
263
303
  } | BufferEncoding | null): Promise<void>;
264
304
  }
265
305
 
306
+ declare function openLegitFsWithMemoryFs(props?: Parameters<typeof openLegitFs>[0]): Promise<CompositeFs & {
307
+ auth: LegitAuth;
308
+ sync: {
309
+ start: () => void;
310
+ stop: () => void;
311
+ isRunning: () => boolean;
312
+ loadBranch: (branch: string) => Promise<void>;
313
+ sequentialPush: (branchesToPush: string[]) => Promise<void>;
314
+ };
315
+ setLogger(logger: FsOperationLogger | undefined): void;
316
+ push: (branches: string[]) => Promise<void>;
317
+ shareCurrentBranch: () => Promise<string>;
318
+ setCurrentBranch: (branch: string) => Promise<void>;
319
+ getCurrentBranch: () => Promise<string>;
320
+ }>;
321
+ /**
322
+ * Creates and configures a LegitFs instance with CompositeFs, GitSubFs, HiddenFileSubFs, and EphemeralSubFs.
323
+ */
324
+ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, }: {
325
+ storageFs: typeof nodeFs;
326
+ gitRoot: string;
327
+ anonymousBranch?: string;
328
+ showKeepFiles?: boolean;
329
+ initialAuthor?: LegitUser;
330
+ serverUrl?: string;
331
+ publicKey?: string;
332
+ }): Promise<CompositeFs & {
333
+ auth: LegitAuth;
334
+ sync: {
335
+ start: () => void;
336
+ stop: () => void;
337
+ isRunning: () => boolean;
338
+ loadBranch: (branch: string) => Promise<void>;
339
+ sequentialPush: (branchesToPush: string[]) => Promise<void>;
340
+ };
341
+ setLogger(logger: FsOperationLogger | undefined): void;
342
+ push: (branches: string[]) => Promise<void>;
343
+ shareCurrentBranch: () => Promise<string>;
344
+ setCurrentBranch: (branch: string) => Promise<void>;
345
+ getCurrentBranch: () => Promise<string>;
346
+ }>;
347
+
348
+ type FileAccess = {
349
+ fileSave: typeof fileSave;
350
+ };
351
+ declare function getLegitFsAccess(legitFs: Awaited<ReturnType<typeof openLegitFs>>): Promise<FileAccess & {
352
+ openFile: (filePath: string) => Promise<FileWithHandle>;
353
+ }>;
354
+
266
355
  declare abstract class BaseCompositeSubFs implements CompositeSubFs {
267
356
  protected toStr(p: any): string;
268
357
  protected compositFs: CompositeFs;
269
358
  protected gitRoot: string;
270
- constructor({ parentFs, gitRoot, }: {
359
+ name: string;
360
+ constructor({ name, parentFs, gitRoot, }: {
361
+ name: string;
271
362
  parentFs: CompositeFs;
272
363
  gitRoot: string;
273
364
  });
@@ -343,7 +434,8 @@ declare abstract class BaseCompositeSubFs implements CompositeSubFs {
343
434
  */
344
435
  declare class HiddenFileSubFs extends BaseCompositeSubFs {
345
436
  private ig;
346
- constructor({ parentFs, gitRoot, hiddenFiles, }: {
437
+ constructor({ name, parentFs, gitRoot, hiddenFiles, }: {
438
+ name: string;
347
439
  parentFs: CompositeFs;
348
440
  gitRoot: string;
349
441
  hiddenFiles: string[];
@@ -381,7 +473,8 @@ declare class EphemeralSubFs extends BaseCompositeSubFs {
381
473
  private ig;
382
474
  patterns: string[];
383
475
  private normalizePath;
384
- constructor({ parentFs, gitRoot, ephemeralPatterns, }: {
476
+ constructor({ name, parentFs, gitRoot, ephemeralPatterns, }: {
477
+ name: string;
385
478
  parentFs: CompositeFs;
386
479
  gitRoot: string;
387
480
  ephemeralPatterns: string[];
@@ -441,7 +534,8 @@ declare class PassThroughSubFs extends BaseCompositeSubFs {
441
534
  private openFh;
442
535
  private memFs;
443
536
  private targetFs;
444
- constructor({ parentFs, gitRoot, }: {
537
+ constructor({ name, parentFs, gitRoot, }: {
538
+ name: string;
445
539
  parentFs: CompositeFs;
446
540
  gitRoot: string;
447
541
  });
@@ -650,7 +744,8 @@ declare class GitSubFs extends BaseCompositeSubFs implements CompositeSubFs {
650
744
  date: number;
651
745
  timezoneOffset: number;
652
746
  }>;
653
- constructor({ parentFs, gitStorageFs, gitRoot, virtualFiles, }: {
747
+ constructor({ name, parentFs, gitStorageFs, gitRoot, virtualFiles, }: {
748
+ name: string;
654
749
  parentFs: CompositeFs;
655
750
  gitStorageFs: CompositeFs;
656
751
  gitRoot: string;
@@ -757,70 +852,13 @@ type Operation = {
757
852
  };
758
853
  declare const gitBranchOperationsVirtualFile: VirtualFileDefinition;
759
854
 
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
- }>;
792
- /**
793
- * Creates and configures a LegitFs instance with CompositeFs, GitSubFs, HiddenFileSubFs, and EphemeralSubFs.
794
- */
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
- }>;
817
-
818
- declare const createLegitSyncService: ({ fs, gitRepoPath, serverUrl, auth, anonymousBranch, }: {
855
+ declare const createLegitSyncService: ({ fs, gitRepoPath, serverUrl, auth, anonymousBranch, authHeaderPrefix, }: {
819
856
  fs: FsClient;
820
857
  gitRepoPath: string;
821
858
  serverUrl?: string;
822
859
  auth: LegitAuth;
823
860
  anonymousBranch: string;
861
+ authHeaderPrefix?: string;
824
862
  }) => {
825
863
  start: () => void;
826
864
  stop: () => void;
@@ -829,13 +867,6 @@ declare const createLegitSyncService: ({ fs, gitRepoPath, serverUrl, auth, anony
829
867
  sequentialPush: (branchesToPush: string[]) => Promise<void>;
830
868
  };
831
869
 
832
- type FileAccess = {
833
- fileSave: typeof fileSave;
834
- };
835
- declare function getLegitFsAccess(legitFs: Awaited<ReturnType<typeof openLegitFs>>): Promise<FileAccess & {
836
- openFile: (filePath: string) => Promise<FileWithHandle>;
837
- }>;
838
-
839
870
  type User = {
840
871
  name: string;
841
872
  email: string;
@@ -849,5 +880,5 @@ type HistoryItem = {
849
880
  author: User;
850
881
  };
851
882
 
852
- export { CompositeFs, EphemeralSubFs, GitSubFs, HiddenFileSubFs, PassThroughSubFs, createLegitSyncService, getLegitFsAccess, gitBranchOperationsVirtualFile, initMemFSLegitFs, openLegitFs };
853
- export type { HistoryItem, Operation, User };
883
+ export { CompositeFs, EphemeralSubFs, GitSubFs, HiddenFileSubFs, PassThroughSubFs, createFsOperationFileLogger, createLegitSyncService, getLegitFsAccess, gitBranchOperationsVirtualFile, openLegitFs, openLegitFsWithMemoryFs };
884
+ export type { FsOperationLogger, HistoryItem, Operation, User };