@legit-sdk/core 0.2.3 → 0.3.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 +45 -113
- package/dist/index.js +119 -86
- package/dist/server.js +30 -7
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -198,7 +198,14 @@ declare class CompositeFs {
|
|
|
198
198
|
access: (filePath: string, mode?: number) => Promise<void>;
|
|
199
199
|
opendir: (dirPath: nodeFs.PathLike, options?: nodeFs.OpenDirOptions) => Promise<CompositeFsDir>;
|
|
200
200
|
mkdir: (dirPath: string, options?: any) => Promise<void>;
|
|
201
|
-
readdir:
|
|
201
|
+
readdir: {
|
|
202
|
+
(dirPath: nodeFs.PathLike, options?: string | {
|
|
203
|
+
withFileTypes?: false;
|
|
204
|
+
}): Promise<string[]>;
|
|
205
|
+
(dirPath: nodeFs.PathLike, options: {
|
|
206
|
+
withFileTypes: true;
|
|
207
|
+
}): Promise<nodeFs.Dirent[]>;
|
|
208
|
+
};
|
|
202
209
|
open: (filePath: string, flags: string, mode?: number) => Promise<CompositFsFileHandle>;
|
|
203
210
|
stat: (path: nodeFs.PathLike, opts?: {
|
|
204
211
|
bigint?: boolean;
|
|
@@ -224,16 +231,16 @@ declare class CompositeFs {
|
|
|
224
231
|
parentFs: CompositeFs | undefined;
|
|
225
232
|
name: string;
|
|
226
233
|
defaultBranch: string;
|
|
234
|
+
gitCache: any;
|
|
227
235
|
pathToFileDescriptors: Map<
|
|
228
236
|
/** path */
|
|
229
237
|
string, number[]>;
|
|
230
238
|
openFileHandles: Map<number, CompositFsFileHandle>;
|
|
231
239
|
logOperation: FsOperationLogger | undefined;
|
|
232
240
|
private getNextFileDescriptor;
|
|
233
|
-
constructor({ name,
|
|
241
|
+
constructor({ name, storageFs, gitRoot, defaultBranch, }: {
|
|
234
242
|
name: string;
|
|
235
|
-
|
|
236
|
-
storageFs: typeof nodeFs | undefined;
|
|
243
|
+
storageFs: typeof nodeFs;
|
|
237
244
|
gitRoot: string;
|
|
238
245
|
defaultBranch?: string;
|
|
239
246
|
});
|
|
@@ -255,8 +262,6 @@ declare class CompositeFs {
|
|
|
255
262
|
/**
|
|
256
263
|
* Read dir needs to check if one subfs takes control.
|
|
257
264
|
*
|
|
258
|
-
* TODO also implement the option to return stats
|
|
259
|
-
*
|
|
260
265
|
* @param dirPath
|
|
261
266
|
* @param options
|
|
262
267
|
* @returns
|
|
@@ -321,7 +326,7 @@ declare function openLegitFsWithMemoryFs(props?: Parameters<typeof openLegitFs>[
|
|
|
321
326
|
/**
|
|
322
327
|
* Creates and configures a LegitFs instance with CompositeFs, GitSubFs, HiddenFileSubFs, and EphemeralSubFs.
|
|
323
328
|
*/
|
|
324
|
-
declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, }: {
|
|
329
|
+
declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, claudeHandler, }: {
|
|
325
330
|
storageFs: typeof nodeFs;
|
|
326
331
|
gitRoot: string;
|
|
327
332
|
anonymousBranch?: string;
|
|
@@ -329,6 +334,7 @@ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFile
|
|
|
329
334
|
initialAuthor?: LegitUser;
|
|
330
335
|
serverUrl?: string;
|
|
331
336
|
publicKey?: string;
|
|
337
|
+
claudeHandler?: boolean;
|
|
332
338
|
}): Promise<CompositeFs & {
|
|
333
339
|
auth: LegitAuth;
|
|
334
340
|
sync: {
|
|
@@ -595,7 +601,7 @@ type VirtualFile = {
|
|
|
595
601
|
size?: number;
|
|
596
602
|
} | {
|
|
597
603
|
type: 'directory';
|
|
598
|
-
content:
|
|
604
|
+
content: nodeFs.Dirent[];
|
|
599
605
|
oid?: string | undefined;
|
|
600
606
|
mode?: number;
|
|
601
607
|
};
|
|
@@ -603,6 +609,7 @@ interface VirtualFileArgs {
|
|
|
603
609
|
cacheFs: IFs;
|
|
604
610
|
filePath: string;
|
|
605
611
|
gitRoot: string;
|
|
612
|
+
userSpaceFs: CompositeFs;
|
|
606
613
|
nodeFs?: any;
|
|
607
614
|
pathParams: any;
|
|
608
615
|
author: {
|
|
@@ -614,6 +621,7 @@ interface VirtualFileArgs {
|
|
|
614
621
|
}
|
|
615
622
|
type VirtualFileDefinition = {
|
|
616
623
|
type: string;
|
|
624
|
+
rootType: 'folder' | 'file';
|
|
617
625
|
getFile: (args: VirtualFileArgs) => Promise<VirtualFile | undefined>;
|
|
618
626
|
getStats: (args: VirtualFileArgs) => Promise<nodeFs.Stats>;
|
|
619
627
|
onFileChanged?: (args: VirtualFileArgs) => Promise<void>;
|
|
@@ -631,128 +639,52 @@ type VirtualFileDefinition = {
|
|
|
631
639
|
rmdir?: (args: VirtualFileArgs) => Promise<void>;
|
|
632
640
|
};
|
|
633
641
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
Reason for the concept: i need to distinguish .legit files from other folders, therefore i wanted to introduce .letgit as a reserved folder independent from the depth or if repeated
|
|
640
|
-
Any problems you see with this?
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
2. Write Operations on Historical Data
|
|
644
|
-
- Writing to /.legit/history/commits/... paths is conceptually problematic - commits are immutable
|
|
645
|
-
- Consider read-only for historical data, write-only for branch operations
|
|
646
|
-
|
|
647
|
-
100% with you commits should be read only folders
|
|
648
|
-
|
|
649
|
-
3. Branch Head Management
|
|
650
|
-
- Using git tags for head tracking (my-branch-name_legithead) pollutes the tag namespace
|
|
651
|
-
- Alternative: Use a dedicated ref namespace like refs/legit/heads/my-branch-name
|
|
652
|
-
|
|
653
|
-
Reason for the concept: i see the point with pollution of tag namespace BUT this will help existing tools to display the concept - i would start with tags and move refs to a later point in time
|
|
654
|
-
- what speaks against this?
|
|
655
|
-
|
|
656
|
-
4. Conflict with Existing Virtual Files
|
|
657
|
-
- Current implementation has .status.gitbox, .branch.gitbox files
|
|
658
|
-
- Need strategy to migrate or maintain compatibility
|
|
659
|
-
|
|
660
|
-
Context: the hole thing is a non published poc so no need to migrate - just an implementation change needed
|
|
661
|
-
|
|
662
|
-
Architectural Challenges
|
|
663
|
-
|
|
664
|
-
1. Performance
|
|
665
|
-
- Git operations (especially history traversal) can be expensive
|
|
666
|
-
- Current memfs caching might not scale for large repos
|
|
667
|
-
- Consider lazy loading and bounded caches
|
|
668
|
-
|
|
669
|
-
Future problem - lets not premature optimation or clear doubts?
|
|
670
|
-
|
|
671
|
-
2. Consistency
|
|
672
|
-
- Multiple write paths (working copy, branches) need careful coordination
|
|
673
|
-
- Race conditions between git operations and filesystem operations
|
|
674
|
-
|
|
675
|
-
Lets postpone this for now
|
|
676
|
-
|
|
677
|
-
3. Error Handling
|
|
678
|
-
- Git operations can fail (conflicts, invalid commits)
|
|
679
|
-
- Need clear error propagation through the FS layer
|
|
680
|
-
|
|
681
|
-
Lets discuss this deeper - dont understand the problem here.
|
|
682
|
-
|
|
683
|
-
Implementation Approach
|
|
684
|
-
|
|
685
|
-
Phase 1: Read-Only Git Views
|
|
686
|
-
// Start with immutable views
|
|
687
|
-
/.legit/status // Current git status
|
|
688
|
-
/.legit/commits/{sha}/path/to/file // Historical file access
|
|
689
|
-
/.legit/branches/ // List branches
|
|
690
|
-
/.legit/refs/heads/{branch}/path // Branch file access
|
|
691
|
-
|
|
692
|
-
Phase 2: Branch Operations
|
|
693
|
-
// Add write capabilities
|
|
694
|
-
/.legit/refs/heads/{branch}/.meta/head // Track branch head
|
|
695
|
-
/.legit/refs/heads/{branch}/path // Write to branch
|
|
696
|
-
|
|
697
|
-
Phase 3: Advanced Features
|
|
698
|
-
// Commit creation, branch management
|
|
699
|
-
/.legit/stage/ // Staging area
|
|
700
|
-
/.legit/commit // Trigger commit
|
|
701
|
-
|
|
702
|
-
Plan sounds good!
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
Next Steps
|
|
706
|
-
|
|
707
|
-
1. Refine the path structure - Simplify and avoid nested .legit directories
|
|
708
|
-
- no please take my points into consideratio
|
|
709
|
-
|
|
710
|
-
2. Create a proof-of-concept - Start with read-only status and commit access
|
|
711
|
-
- sounds good
|
|
712
|
-
|
|
713
|
-
3. Build test infrastructure - Set up git fixture creation and FS testing utilities
|
|
714
|
-
- absolutly
|
|
715
|
-
|
|
716
|
-
4. Implement incrementally - Phase approach to reduce complexity
|
|
717
|
-
|
|
718
|
-
alreight
|
|
719
|
-
|
|
720
|
-
The architecture supports your vision, but consider starting simpler and evolving based on real usage patterns.
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
/.legit/status // Git status info
|
|
725
|
-
/.legit/commits/{sha(0,1)}/{sha(2..20)}/path/to/file // Historical files
|
|
726
|
-
/.legit/branches/ // List branches
|
|
727
|
-
/.legit/branches/{name}/path/to/file // Branch files (read/write)
|
|
728
|
-
/.legit/branches/{name}/.legit/head // read/write of the head commit of the branch {name}
|
|
729
|
-
/.legit/branches/{name}/.legit/tip // read/write of the tip of the branch {name} - keeping this allows undo redo ops
|
|
642
|
+
interface LegitRouteFolder {
|
|
643
|
+
[key: string]: LegitRouteDescriptor;
|
|
644
|
+
}
|
|
645
|
+
type LegitRouteDescriptor = VirtualFileDefinition | LegitRouteFolder;
|
|
730
646
|
|
|
731
|
-
|
|
647
|
+
/**
|
|
648
|
+
* Topics to discuss:
|
|
649
|
+
* # Ref space polution
|
|
650
|
+
* - Local vs Remote (we dont push all refs all the time)
|
|
651
|
+
* - required refs (what are the miniumum refs required to keep the repo healthy)
|
|
652
|
+
* - ref branch concept (branch pointing to oids to keep refs alive withouth poluting refs)
|
|
653
|
+
*
|
|
654
|
+
* # Performance (we tackle whens appear)
|
|
655
|
+
* - Git operations (especially history traversal) can be expensive
|
|
656
|
+
* - Current memfs caching might not scale for large repos
|
|
657
|
+
* - Consider lazy loading and bounded caches
|
|
732
658
|
*/
|
|
659
|
+
/**
|
|
660
|
+
* Git-backed CompositeSubFs implementation.
|
|
661
|
+
*
|
|
662
|
+
*
|
|
663
|
+
* docx file
|
|
664
|
+
* - we unpack the docx and store xml files as blobs in git
|
|
665
|
+
* mpeg file
|
|
666
|
+
* - we chunk the file and sstsore chunks as blobs in git
|
|
667
|
+
**/
|
|
733
668
|
declare class GitSubFs extends BaseCompositeSubFs implements CompositeSubFs {
|
|
734
669
|
private static readonly LEGIT_DIR;
|
|
735
|
-
private
|
|
670
|
+
private pathRouter;
|
|
736
671
|
private memFs;
|
|
737
672
|
private openFh;
|
|
738
|
-
|
|
739
|
-
private legitFileNames;
|
|
740
|
-
storageFs: CompositeFs;
|
|
673
|
+
storageFs: any;
|
|
741
674
|
getAuthor(): Promise<{
|
|
742
675
|
name: string;
|
|
743
676
|
email: string;
|
|
744
677
|
date: number;
|
|
745
678
|
timezoneOffset: number;
|
|
746
679
|
}>;
|
|
747
|
-
constructor({ name, parentFs, gitStorageFs, gitRoot,
|
|
680
|
+
constructor({ name, parentFs, gitStorageFs, gitRoot, routerConfig, }: {
|
|
748
681
|
name: string;
|
|
749
682
|
parentFs: CompositeFs;
|
|
750
|
-
gitStorageFs:
|
|
683
|
+
gitStorageFs: any;
|
|
751
684
|
gitRoot: string;
|
|
752
|
-
|
|
685
|
+
routerConfig: LegitRouteFolder;
|
|
753
686
|
});
|
|
754
687
|
responsible(filePath: string): Promise<boolean>;
|
|
755
|
-
private isLegitPath;
|
|
756
688
|
private getRouteHandler;
|
|
757
689
|
/**
|
|
758
690
|
* Opens a virtual file from the Git-based virtual file system.
|