@legit-sdk/core 0.2.4 → 0.4.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 +36 -118
- package/dist/index.js +119 -87
- package/dist/server.d.ts +12 -4
- package/dist/server.js +144 -8
- package/package.json +13 -12
- package/LICENSE +0 -131
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { IDir, TFileHandleReadResult, TData, TMode, IStats, TTime, TFileHandleWr
|
|
|
6
6
|
import { IAppendFileOptions, IStatOptions, IReadFileOptions, IWriteFileOptions, IReadableWebStreamOptions } from 'memfs/lib/node/types/options.js';
|
|
7
7
|
import { PathLike as PathLike$1 } from 'fs';
|
|
8
8
|
import { IFs } from 'memfs';
|
|
9
|
-
import { FsClient } from 'isomorphic-git';
|
|
9
|
+
import { FsClient } from '@legit-sdk/isomorphic-git';
|
|
10
10
|
|
|
11
11
|
type LegitUser = {
|
|
12
12
|
type: string;
|
|
@@ -231,16 +231,16 @@ declare class CompositeFs {
|
|
|
231
231
|
parentFs: CompositeFs | undefined;
|
|
232
232
|
name: string;
|
|
233
233
|
defaultBranch: string;
|
|
234
|
+
gitCache: any;
|
|
234
235
|
pathToFileDescriptors: Map<
|
|
235
236
|
/** path */
|
|
236
237
|
string, number[]>;
|
|
237
238
|
openFileHandles: Map<number, CompositFsFileHandle>;
|
|
238
239
|
logOperation: FsOperationLogger | undefined;
|
|
239
240
|
private getNextFileDescriptor;
|
|
240
|
-
constructor({ name,
|
|
241
|
+
constructor({ name, storageFs, gitRoot, defaultBranch, }: {
|
|
241
242
|
name: string;
|
|
242
|
-
|
|
243
|
-
storageFs: typeof nodeFs | undefined;
|
|
243
|
+
storageFs: typeof nodeFs;
|
|
244
244
|
gitRoot: string;
|
|
245
245
|
defaultBranch?: string;
|
|
246
246
|
});
|
|
@@ -262,8 +262,6 @@ declare class CompositeFs {
|
|
|
262
262
|
/**
|
|
263
263
|
* Read dir needs to check if one subfs takes control.
|
|
264
264
|
*
|
|
265
|
-
* TODO also implement the option to return stats
|
|
266
|
-
*
|
|
267
265
|
* @param dirPath
|
|
268
266
|
* @param options
|
|
269
267
|
* @returns
|
|
@@ -328,7 +326,7 @@ declare function openLegitFsWithMemoryFs(props?: Parameters<typeof openLegitFs>[
|
|
|
328
326
|
/**
|
|
329
327
|
* Creates and configures a LegitFs instance with CompositeFs, GitSubFs, HiddenFileSubFs, and EphemeralSubFs.
|
|
330
328
|
*/
|
|
331
|
-
declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, }: {
|
|
329
|
+
declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFiles, initialAuthor, serverUrl, publicKey, claudeHandler, }: {
|
|
332
330
|
storageFs: typeof nodeFs;
|
|
333
331
|
gitRoot: string;
|
|
334
332
|
anonymousBranch?: string;
|
|
@@ -336,6 +334,7 @@ declare function openLegitFs({ storageFs, gitRoot, anonymousBranch, showKeepFile
|
|
|
336
334
|
initialAuthor?: LegitUser;
|
|
337
335
|
serverUrl?: string;
|
|
338
336
|
publicKey?: string;
|
|
337
|
+
claudeHandler?: boolean;
|
|
339
338
|
}): Promise<CompositeFs & {
|
|
340
339
|
auth: LegitAuth;
|
|
341
340
|
sync: {
|
|
@@ -610,6 +609,7 @@ interface VirtualFileArgs {
|
|
|
610
609
|
cacheFs: IFs;
|
|
611
610
|
filePath: string;
|
|
612
611
|
gitRoot: string;
|
|
612
|
+
userSpaceFs: CompositeFs;
|
|
613
613
|
nodeFs?: any;
|
|
614
614
|
pathParams: any;
|
|
615
615
|
author: {
|
|
@@ -639,134 +639,52 @@ type VirtualFileDefinition = {
|
|
|
639
639
|
rmdir?: (args: VirtualFileArgs) => Promise<void>;
|
|
640
640
|
};
|
|
641
641
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
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
|
|
648
|
-
Any problems you see with this?
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
2. Write Operations on Historical Data
|
|
652
|
-
- Writing to /.legit/history/commits/... paths is conceptually problematic - commits are immutable
|
|
653
|
-
- Consider read-only for historical data, write-only for branch operations
|
|
654
|
-
|
|
655
|
-
100% with you commits should be read only folders
|
|
656
|
-
|
|
657
|
-
3. Branch Head Management
|
|
658
|
-
- Using git tags for head tracking (my-branch-name_legithead) pollutes the tag namespace
|
|
659
|
-
- Alternative: Use a dedicated ref namespace like refs/legit/heads/my-branch-name
|
|
660
|
-
|
|
661
|
-
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
|
|
662
|
-
- what speaks against this?
|
|
663
|
-
|
|
664
|
-
4. Conflict with Existing Virtual Files
|
|
665
|
-
- Current implementation has .status.gitbox, .branch.gitbox files
|
|
666
|
-
- Need strategy to migrate or maintain compatibility
|
|
667
|
-
|
|
668
|
-
Context: the hole thing is a non published poc so no need to migrate - just an implementation change needed
|
|
669
|
-
|
|
670
|
-
Architectural Challenges
|
|
671
|
-
|
|
672
|
-
1. Performance
|
|
673
|
-
- Git operations (especially history traversal) can be expensive
|
|
674
|
-
- Current memfs caching might not scale for large repos
|
|
675
|
-
- Consider lazy loading and bounded caches
|
|
676
|
-
|
|
677
|
-
Future problem - lets not premature optimation or clear doubts?
|
|
678
|
-
|
|
679
|
-
2. Consistency
|
|
680
|
-
- Multiple write paths (working copy, branches) need careful coordination
|
|
681
|
-
- Race conditions between git operations and filesystem operations
|
|
682
|
-
|
|
683
|
-
Lets postpone this for now
|
|
684
|
-
|
|
685
|
-
3. Error Handling
|
|
686
|
-
- Git operations can fail (conflicts, invalid commits)
|
|
687
|
-
- Need clear error propagation through the FS layer
|
|
688
|
-
|
|
689
|
-
Lets discuss this deeper - dont understand the problem here.
|
|
690
|
-
|
|
691
|
-
Implementation Approach
|
|
692
|
-
|
|
693
|
-
Phase 1: Read-Only Git Views
|
|
694
|
-
// Start with immutable views
|
|
695
|
-
/.legit/status // Current git status
|
|
696
|
-
/.legit/commits/{sha}/path/to/file // Historical file access
|
|
697
|
-
/.legit/branches/ // List branches
|
|
698
|
-
/.legit/refs/heads/{branch}/path // Branch file access
|
|
699
|
-
|
|
700
|
-
Phase 2: Branch Operations
|
|
701
|
-
// Add write capabilities
|
|
702
|
-
/.legit/refs/heads/{branch}/.meta/head // Track branch head
|
|
703
|
-
/.legit/refs/heads/{branch}/path // Write to branch
|
|
704
|
-
|
|
705
|
-
Phase 3: Advanced Features
|
|
706
|
-
// Commit creation, branch management
|
|
707
|
-
/.legit/stage/ // Staging area
|
|
708
|
-
/.legit/commit // Trigger commit
|
|
709
|
-
|
|
710
|
-
Plan sounds good!
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
Next Steps
|
|
714
|
-
|
|
715
|
-
1. Refine the path structure - Simplify and avoid nested .legit directories
|
|
716
|
-
- no please take my points into consideratio
|
|
717
|
-
|
|
718
|
-
2. Create a proof-of-concept - Start with read-only status and commit access
|
|
719
|
-
- sounds good
|
|
720
|
-
|
|
721
|
-
3. Build test infrastructure - Set up git fixture creation and FS testing utilities
|
|
722
|
-
- absolutly
|
|
723
|
-
|
|
724
|
-
4. Implement incrementally - Phase approach to reduce complexity
|
|
725
|
-
|
|
726
|
-
alreight
|
|
727
|
-
|
|
728
|
-
The architecture supports your vision, but consider starting simpler and evolving based on real usage patterns.
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
/.legit/status // Git status info
|
|
733
|
-
/.legit/commits/{sha(0,1)}/{sha(2..20)}/path/to/file // Historical files
|
|
734
|
-
/.legit/branches/ // List branches
|
|
735
|
-
/.legit/branches/{name}/path/to/file // Branch files (read/write)
|
|
736
|
-
/.legit/branches/{name}/.legit/head // read/write of the head commit of the branch {name}
|
|
737
|
-
/.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;
|
|
738
646
|
|
|
739
|
-
|
|
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
|
|
740
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
|
+
**/
|
|
741
668
|
declare class GitSubFs extends BaseCompositeSubFs implements CompositeSubFs {
|
|
742
669
|
private static readonly LEGIT_DIR;
|
|
743
|
-
|
|
744
|
-
* how to handle branches with slashes in them?
|
|
745
|
-
*
|
|
746
|
-
* Lets say i have a branch called my/branch/name
|
|
747
|
-
* this means i am not allowed to have a branch called my because this would conflict with
|
|
748
|
-
*/
|
|
749
|
-
private static pathRouter;
|
|
670
|
+
private pathRouter;
|
|
750
671
|
private memFs;
|
|
751
672
|
private openFh;
|
|
752
|
-
|
|
753
|
-
private legitFileNames;
|
|
754
|
-
storageFs: CompositeFs;
|
|
673
|
+
storageFs: any;
|
|
755
674
|
getAuthor(): Promise<{
|
|
756
675
|
name: string;
|
|
757
676
|
email: string;
|
|
758
677
|
date: number;
|
|
759
678
|
timezoneOffset: number;
|
|
760
679
|
}>;
|
|
761
|
-
constructor({ name, parentFs, gitStorageFs, gitRoot,
|
|
680
|
+
constructor({ name, parentFs, gitStorageFs, gitRoot, routerConfig, }: {
|
|
762
681
|
name: string;
|
|
763
682
|
parentFs: CompositeFs;
|
|
764
|
-
gitStorageFs:
|
|
683
|
+
gitStorageFs: any;
|
|
765
684
|
gitRoot: string;
|
|
766
|
-
|
|
685
|
+
routerConfig: LegitRouteFolder;
|
|
767
686
|
});
|
|
768
687
|
responsible(filePath: string): Promise<boolean>;
|
|
769
|
-
private isLegitPath;
|
|
770
688
|
private getRouteHandler;
|
|
771
689
|
/**
|
|
772
690
|
* Opens a virtual file from the Git-based virtual file system.
|