@legit-sdk/core 0.4.5 → 0.5.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
@@ -557,6 +557,7 @@ declare class CompositeFs {
557
557
  } | BufferEncoding | null): Promise<void>;
558
558
  }
559
559
 
560
+ declare function mergeLegitRouteFolders(a: LegitRouteFolder, b: LegitRouteFolder): LegitRouteFolder;
560
561
  declare function openLegitFsWithMemoryFs(props?: Parameters<typeof openLegitFs>[0]): Promise<CompositeFs & {
561
562
  auth: LegitAuth;
562
563
  sync: {
@@ -572,11 +573,29 @@ declare function openLegitFsWithMemoryFs(props?: Parameters<typeof openLegitFs>[
572
573
  shareCurrentBranch: () => Promise<string>;
573
574
  setCurrentBranch: (branch: string) => Promise<void>;
574
575
  getCurrentBranch: () => Promise<string>;
576
+ /**
577
+ *
578
+ * This function takes a legit archive - earlier compressed with saveArchive and writes it to storage fs.
579
+ *
580
+ * Refs that can be fast forwarded should get updeted - referecences that cannot be fast forwarded create a ref named branchname-conflict-uuid.
581
+ * New Refs should be added. (TODO how do we handle deleted refs to prevent them from coming back?)
582
+ *
583
+ * The git config should get ignored for now
584
+ *
585
+ * @param legitArchieve a zlib compressed legit repo
586
+ */
587
+ loadArchive: (legitArchieve: Uint8Array) => Promise<void>;
588
+ /**
589
+ * creates a legit archieve - a compressed representation of the legit repo (the .git folder in the storage fs)
590
+ *
591
+ * @returns
592
+ */
593
+ saveArchive: () => Promise<Uint8Array>;
575
594
  }>;
576
595
  /**
577
596
  * Creates and configures a LegitFs instance with CompositeFs, GitSubFs, HiddenFileSubFs, and EphemeralSubFs.
578
597
  */
579
- declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, ephemaralGitConfig, additionalFilterLayers, }: {
598
+ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, ephemaralGitConfig, additionalFilterLayers, routeOverrides, }: {
580
599
  storageFs: typeof nodeFs;
581
600
  gitRoot: string;
582
601
  anonymousBranch?: string;
@@ -586,6 +605,7 @@ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFile
586
605
  publicKey?: string;
587
606
  ephemaralGitConfig?: boolean;
588
607
  additionalFilterLayers?: CompositeSubFs[];
608
+ routeOverrides?: LegitRouteFolder;
589
609
  }): Promise<CompositeFs & {
590
610
  auth: LegitAuth;
591
611
  sync: {
@@ -601,6 +621,24 @@ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFile
601
621
  shareCurrentBranch: () => Promise<string>;
602
622
  setCurrentBranch: (branch: string) => Promise<void>;
603
623
  getCurrentBranch: () => Promise<string>;
624
+ /**
625
+ *
626
+ * This function takes a legit archive - earlier compressed with saveArchive and writes it to storage fs.
627
+ *
628
+ * Refs that can be fast forwarded should get updeted - referecences that cannot be fast forwarded create a ref named branchname-conflict-uuid.
629
+ * New Refs should be added. (TODO how do we handle deleted refs to prevent them from coming back?)
630
+ *
631
+ * The git config should get ignored for now
632
+ *
633
+ * @param legitArchieve a zlib compressed legit repo
634
+ */
635
+ loadArchive: (legitArchieve: Uint8Array) => Promise<void>;
636
+ /**
637
+ * creates a legit archieve - a compressed representation of the legit repo (the .git folder in the storage fs)
638
+ *
639
+ * @returns
640
+ */
641
+ saveArchive: () => Promise<Uint8Array>;
604
642
  }>;
605
643
 
606
644
  type FileAccess = {
@@ -791,66 +829,6 @@ declare class CopyOnWriteSubFs extends BaseCompositeSubFs {
791
829
  writeFile(filePath: string, data: TData, options: IWriteFileOptions | string): Promise<void>;
792
830
  }
793
831
 
794
- /**
795
- * FS utilized to provide pass-through access to the underlying filesystem
796
- */
797
- declare class PassThroughSubFs extends BaseCompositeSubFs {
798
- private openFh;
799
- private memFs;
800
- private targetFs;
801
- constructor({ name, parentFs, rootPath, }: {
802
- name: string;
803
- parentFs: CompositeFs;
804
- rootPath: string;
805
- });
806
- responsible(filePath: string): Promise<boolean>;
807
- fileType(): number;
808
- open(filePath: string, flags: string, mode?: number): Promise<CompositFsFileHandle>;
809
- access(filePath: PathLike$1, mode?: number): Promise<void>;
810
- stat(path: PathLike$1, opts?: {
811
- bigint?: false;
812
- }): Promise<nodeFs.Stats>;
813
- stat(path: PathLike$1, opts: {
814
- bigint: true;
815
- }): Promise<nodeFs.BigIntStats>;
816
- stat(path: PathLike$1, opts?: {
817
- bigint?: boolean;
818
- }): Promise<nodeFs.Stats | nodeFs.BigIntStats>;
819
- lstat(path: PathLike$1, opts?: {
820
- bigint?: false;
821
- }): Promise<nodeFs.Stats>;
822
- lstat(path: PathLike$1, opts: {
823
- bigint: true;
824
- }): Promise<nodeFs.BigIntStats>;
825
- lstat(path: PathLike$1, opts?: {
826
- bigint?: boolean;
827
- }): Promise<nodeFs.Stats | nodeFs.BigIntStats>;
828
- opendir(folderPath: nodeFs.PathLike, options?: nodeFs.OpenDirOptions): Promise<CompositeFsDir>;
829
- link(existingPath: PathLike$1, newPath: PathLike$1): Promise<void>;
830
- mkdir(dirPath: PathLike$1, options?: nodeFs.MakeDirectoryOptions | nodeFs.Mode | null): Promise<void>;
831
- readdir(path: PathLike$1, ...args: any[]): Promise<any>;
832
- readlink(path: PathLike$1, ...args: any[]): Promise<any>;
833
- unlink(path: PathLike$1): Promise<void>;
834
- rename(oldPath: PathLike$1, newPath: PathLike$1): Promise<void>;
835
- rmdir(path: PathLike$1, options?: nodeFs.RmDirOptions): Promise<void>;
836
- symlink(target: PathLike$1, path: PathLike$1, type?: string | null): Promise<void>;
837
- lookup(filePath: string): Promise<number>;
838
- close(fh: CompositFsFileHandle): Promise<void>;
839
- dataSync(fh: CompositFsFileHandle): Promise<void>;
840
- read(fh: CompositFsFileHandle, buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
841
- fchmod(fh: CompositFsFileHandle, mode: TMode): Promise<void>;
842
- fchown(fh: CompositFsFileHandle, uid: number, gid: number): Promise<void>;
843
- write(fh: CompositFsFileHandle, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
844
- ftruncate(fh: CompositFsFileHandle, len?: number): Promise<void>;
845
- resolvePath(fd: number): string;
846
- fstat(fh: CompositFsFileHandle, options?: IStatOptions): Promise<IStats>;
847
- futimes(fh: CompositFsFileHandle, atime: TTime, mtime: TTime): Promise<void>;
848
- writev(fh: CompositFsFileHandle, buffers: ArrayBufferView[], position?: number | null): Promise<TFileHandleWritevResult>;
849
- readv(fh: CompositFsFileHandle, buffers: ArrayBufferView[], position?: number | null): Promise<TFileHandleReadvResult>;
850
- readFile(path: PathLike$1 | IFileHandle, options?: IReadFileOptions | string): Promise<TDataOut>;
851
- writeFile(path: string, data: TData, options: IWriteFileOptions | string): Promise<void>;
852
- }
853
-
854
832
  type VirtualFile = {
855
833
  type: 'file';
856
834
  content?: string | Buffer;
@@ -866,9 +844,7 @@ type VirtualFile = {
866
844
  interface VirtualFileArgs {
867
845
  cacheFs: IFs;
868
846
  filePath: string;
869
- gitRoot: string;
870
847
  userSpaceFs: CompositeFs;
871
- nodeFs?: any;
872
848
  pathParams: any;
873
849
  author: {
874
850
  name: string;
@@ -1021,6 +997,33 @@ declare class CompositeSubFsAdapter extends BaseCompositeSubFs implements Compos
1021
997
  fileType(): number;
1022
998
  }
1023
999
 
1000
+ /**
1001
+ * Creates a CompositeSubFsAdapter for legit virtual folder operations
1002
+ *
1003
+ * This adapter handles the .legit folder, which serves as the root
1004
+ * for all legit-related virtual files and operations.
1005
+ *
1006
+ * @example
1007
+ * ```ts
1008
+ * const adapter = createLegitVirtualFileAdapter({
1009
+ * gitStorageFs: memFs,
1010
+ * gitRoot: '/my-repo',
1011
+ * });
1012
+ *
1013
+ * // Use in CompositeFs routes
1014
+ * const compositeFs = new CompositeFs({
1015
+ * routes: {
1016
+ * '.legit': adapter,
1017
+ * },
1018
+ * });
1019
+ * ```
1020
+ */
1021
+ declare function createLegitVirtualFileAdapter({ gitStorageFs, gitRoot, rootPath, }: {
1022
+ gitStorageFs: any;
1023
+ gitRoot: string;
1024
+ rootPath?: string;
1025
+ }): CompositeSubFsAdapter;
1026
+
1024
1027
  type Operation = {
1025
1028
  oid: string;
1026
1029
  parentOids: string[];
@@ -1074,5 +1077,248 @@ type HistoryItem = {
1074
1077
  author: User;
1075
1078
  };
1076
1079
 
1077
- export { CompositeFs, CompositeSubFsAdapter, CopyOnWriteSubFs, EphemeralSubFs, HiddenFileSubFs, PassThroughSubFs, createBranchOperationsAdapter, createFsOperationFileLogger, createLegitSyncService, getLegitFsAccess, openLegitFs, openLegitFsWithMemoryFs };
1078
- export type { FsOperationLogger, HistoryItem, Operation, User };
1080
+ declare abstract class ASimpleCompositeSubfs extends BaseCompositeSubFs implements CompositeSubFs {
1081
+ private memFs;
1082
+ private openFh;
1083
+ constructor({ name, rootPath }: {
1084
+ name: string;
1085
+ rootPath: string;
1086
+ });
1087
+ /**
1088
+ * Check if write operations are supported by this adapter
1089
+ * Subclasses can override this to return false for read-only adapters
1090
+ */
1091
+ isWriteSupported(): boolean;
1092
+ responsible(_filePath: string): Promise<boolean>;
1093
+ /**
1094
+ * Get route parameters from the operation context
1095
+ * CompositeFs sets this context when routing to this adapter
1096
+ */
1097
+ private getRouteParams;
1098
+ /**
1099
+ * Get static siblings from the operation context
1100
+ * These are static entries that should appear in directory listings
1101
+ */
1102
+ private getStaticSiblings;
1103
+ /**
1104
+ * Opens a virtual file using the configured handler.
1105
+ *
1106
+ * The handler receives route parameters via context set by CompositeFs.
1107
+ */
1108
+ open(filePath: string, flags: string, mode?: number): Promise<CompositFsFileHandle>;
1109
+ abstract createDirectory(args: {
1110
+ path: string;
1111
+ recursive?: boolean;
1112
+ context: ASimpleCompositeSubfs['context'];
1113
+ }): Promise<void>;
1114
+ abstract readFileContent(args: {
1115
+ path: string;
1116
+ context: ASimpleCompositeSubfs['context'];
1117
+ }): Promise<{
1118
+ content: string | Buffer;
1119
+ oid?: string;
1120
+ } | undefined>;
1121
+ abstract writeFileContent(args: {
1122
+ path: string;
1123
+ content: Buffer | string;
1124
+ context: ASimpleCompositeSubfs['context'];
1125
+ }): Promise<void>;
1126
+ abstract readDirectory(args: {
1127
+ path: string;
1128
+ context: ASimpleCompositeSubfs['context'];
1129
+ }): Promise<nodeFs.Dirent[]>;
1130
+ abstract renamePath(args: {
1131
+ oldPath: string;
1132
+ newPath: string;
1133
+ oldContext: ASimpleCompositeSubfs['context'];
1134
+ newContext: ASimpleCompositeSubfs['context'];
1135
+ }): Promise<void>;
1136
+ abstract deleteFile(args: {
1137
+ path: string;
1138
+ context: ASimpleCompositeSubfs['context'];
1139
+ }): Promise<void>;
1140
+ abstract removeDirectory(args: {
1141
+ path: string;
1142
+ context: ASimpleCompositeSubfs['context'];
1143
+ }): Promise<void>;
1144
+ mkdir(path: PathLike, options?: nodeFs.MakeDirectoryOptions | nodeFs.Mode | null): Promise<void>;
1145
+ access(path: PathLike, _mode?: number): Promise<void>;
1146
+ futimes(fh: CompositFsFileHandle, atime: TTime, mtime: TTime): Promise<void>;
1147
+ fstat(fh: CompositFsFileHandle, options?: IStatOptions): Promise<IStats>;
1148
+ ftruncate(fh: CompositFsFileHandle, len?: number): Promise<void>;
1149
+ stat(path: PathLike, opts?: {
1150
+ bigint?: false;
1151
+ }): Promise<nodeFs.Stats>;
1152
+ stat(path: PathLike, opts: {
1153
+ bigint: true;
1154
+ }): Promise<nodeFs.BigIntStats>;
1155
+ stat(path: PathLike, opts?: {
1156
+ bigint?: boolean;
1157
+ }): Promise<nodeFs.Stats | nodeFs.BigIntStats>;
1158
+ abstract getStats(args: {
1159
+ path: string;
1160
+ context: ASimpleCompositeSubfs['context'];
1161
+ }): Promise<nodeFs.Stats>;
1162
+ lstat(path: PathLike, opts?: {
1163
+ bigint?: false;
1164
+ }): Promise<nodeFs.Stats>;
1165
+ lstat(path: PathLike, opts: {
1166
+ bigint: true;
1167
+ }): Promise<nodeFs.BigIntStats>;
1168
+ lstat(path: PathLike, opts?: {
1169
+ bigint?: boolean;
1170
+ }): Promise<nodeFs.Stats | nodeFs.BigIntStats>;
1171
+ readdir(path: PathLike, options?: (nodeFs.ObjectEncodingOptions & {
1172
+ withFileTypes?: false | undefined;
1173
+ recursive?: boolean | undefined;
1174
+ }) | BufferEncoding | null): Promise<string[]>;
1175
+ readdir(path: PathLike, options?: {
1176
+ encoding: 'buffer';
1177
+ withFileTypes?: false | undefined;
1178
+ recursive?: boolean | undefined;
1179
+ } | 'buffer' | null): Promise<Buffer[]>;
1180
+ readdir(path: PathLike, options?: (nodeFs.ObjectEncodingOptions & {
1181
+ withFileTypes?: false | undefined;
1182
+ recursive?: boolean | undefined;
1183
+ }) | BufferEncoding | null): Promise<string[] | Buffer[]>;
1184
+ readdir(path: PathLike, options: nodeFs.ObjectEncodingOptions & {
1185
+ withFileTypes: true;
1186
+ recursive?: boolean | undefined;
1187
+ }): Promise<nodeFs.Dirent[]>;
1188
+ read(fh: CompositFsFileHandle, buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
1189
+ /**
1190
+ *
1191
+ * Writes (parts) of a buffer to a specific position in the file
1192
+ *
1193
+ * - a write leads to a new commit and on flush since the point in time a flush may occur may vary a read operation may
1194
+ * not see changed done on the read lays.
1195
+ *
1196
+ *
1197
+ * @param fh
1198
+ * @param buffer
1199
+ * @param offset
1200
+ * @param length
1201
+ * @param position
1202
+ * @returns
1203
+ */
1204
+ write(fh: CompositFsFileHandle, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
1205
+ close(fh: CompositFsFileHandle): Promise<void>;
1206
+ dataSync(fh: CompositFsFileHandle): Promise<void>;
1207
+ readFile(path: PathLike | IFileHandle, options?: IReadFileOptions | string): Promise<TDataOut>;
1208
+ writeFile(path: string, data: TData, options?: IWriteFileOptions | string): Promise<void>;
1209
+ rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
1210
+ fchmod(_fh: CompositFsFileHandle, _mode: TMode): Promise<void>;
1211
+ unlink(path: PathLike): Promise<void>;
1212
+ rmdir(path: PathLike, ..._args: any[]): Promise<void>;
1213
+ fileType(): number;
1214
+ }
1215
+
1216
+ interface MemoryFile {
1217
+ type: 'file';
1218
+ content: Buffer;
1219
+ mode: number;
1220
+ createdAt: Date;
1221
+ modifiedAt: Date;
1222
+ }
1223
+ interface MemoryDirectory {
1224
+ type: 'directory';
1225
+ entries: Set<string>;
1226
+ mode: number;
1227
+ createdAt: Date;
1228
+ modifiedAt: Date;
1229
+ }
1230
+ type MemoryNode = MemoryFile | MemoryDirectory;
1231
+ type FileSystemData = string | {
1232
+ [key: string]: FileSystemData;
1233
+ };
1234
+ /**
1235
+ * SimpleMemorySubFs - A simple in-memory filesystem implementation
1236
+ *
1237
+ * This class extends ASimpleCompositeSubfs and stores all files and directories
1238
+ * in a JavaScript Map in memory. It's useful for testing, caching, or temporary
1239
+ * file storage that doesn't need to persist.
1240
+ */
1241
+ declare class SimpleMemorySubFs extends ASimpleCompositeSubfs {
1242
+ private storage;
1243
+ private nextFileType;
1244
+ /**
1245
+ * Debug method to inspect internal storage
1246
+ */
1247
+ _debugGetStorage(): Map<string, MemoryNode>;
1248
+ constructor({ name, rootPath, initialData, }: {
1249
+ name: string;
1250
+ rootPath: string;
1251
+ initialData?: FileSystemData;
1252
+ });
1253
+ /**
1254
+ * Populate the filesystem from initial data structure
1255
+ * @param data - The data structure to populate from (string = file, object = folder)
1256
+ * @param currentPath - The current path in the filesystem
1257
+ */
1258
+ private populateFromInitialData;
1259
+ fileType(): number;
1260
+ createDirectory(args: {
1261
+ path: string;
1262
+ recursive?: boolean;
1263
+ context: ASimpleCompositeSubfs['context'];
1264
+ }): Promise<void>;
1265
+ getStats(args: {
1266
+ path: string;
1267
+ context: ASimpleCompositeSubfs['context'];
1268
+ }): Promise<nodeFs.Stats>;
1269
+ readFileContent(args: {
1270
+ path: string;
1271
+ context: ASimpleCompositeSubfs['context'];
1272
+ }): Promise<{
1273
+ content: string | Buffer;
1274
+ oid?: string;
1275
+ } | undefined>;
1276
+ writeFileContent(args: {
1277
+ path: string;
1278
+ content: Buffer | string;
1279
+ context: ASimpleCompositeSubfs['context'];
1280
+ }): Promise<void>;
1281
+ readDirectory(args: {
1282
+ path: string;
1283
+ context: ASimpleCompositeSubfs['context'];
1284
+ }): Promise<nodeFs.Dirent[]>;
1285
+ renamePath(args: {
1286
+ oldPath: string;
1287
+ newPath: string;
1288
+ oldContext: ASimpleCompositeSubfs['context'];
1289
+ newContext: ASimpleCompositeSubfs['context'];
1290
+ }): Promise<void>;
1291
+ deleteFile(args: {
1292
+ path: string;
1293
+ context: ASimpleCompositeSubfs['context'];
1294
+ }): Promise<void>;
1295
+ removeDirectory(args: {
1296
+ path: string;
1297
+ context: ASimpleCompositeSubfs['context'];
1298
+ }): Promise<void>;
1299
+ /**
1300
+ * Normalize a path to ensure consistent format
1301
+ */
1302
+ private normalizePath;
1303
+ /**
1304
+ * Get the parent directory path
1305
+ */
1306
+ private getParentPath;
1307
+ /**
1308
+ * Get the base name of a path
1309
+ */
1310
+ private getBaseName;
1311
+ /**
1312
+ * Join path segments
1313
+ */
1314
+ private joinPath;
1315
+ }
1316
+
1317
+ declare function toDirEntry(args: {
1318
+ parent: string;
1319
+ name: string;
1320
+ isDir: boolean;
1321
+ }): nodeFs.Dirent;
1322
+
1323
+ export { ASimpleCompositeSubfs, CompositeFs, CompositeSubFsAdapter, CopyOnWriteSubFs, EphemeralSubFs, HiddenFileSubFs, SimpleMemorySubFs, createBranchOperationsAdapter, createFsOperationFileLogger, createLegitSyncService, createLegitVirtualFileAdapter, getLegitFsAccess, mergeLegitRouteFolders, openLegitFs, openLegitFsWithMemoryFs, toDirEntry };
1324
+ export type { FileSystemData, FsOperationLogger, HistoryItem, Operation, User };