@rljson/fs-agent 0.0.2
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/LICENSE +21 -0
- package/README.architecture.md +449 -0
- package/README.blog.md +11 -0
- package/README.contributors.md +32 -0
- package/README.md +24 -0
- package/README.public.md +781 -0
- package/README.trouble.md +23 -0
- package/dist/README.architecture.md +449 -0
- package/dist/README.blog.md +11 -0
- package/dist/README.contributors.md +32 -0
- package/dist/README.md +24 -0
- package/dist/README.public.md +781 -0
- package/dist/README.trouble.md +23 -0
- package/dist/client-server/client-server-setup.d.ts +17 -0
- package/dist/client-server/live-client-server.d.ts +1 -0
- package/dist/example.d.ts +1 -0
- package/dist/fs-agent.d.ts +178 -0
- package/dist/fs-agent.js +4049 -0
- package/dist/fs-blob-adapter.d.ts +92 -0
- package/dist/fs-db-adapter.d.ts +34 -0
- package/dist/fs-scanner.d.ts +104 -0
- package/dist/index.d.ts +5 -0
- package/dist/src/example.ts +101 -0
- package/package.json +59 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@license
|
|
3
|
+
Copyright (c) 2025 Rljson
|
|
4
|
+
|
|
5
|
+
Use of this source code is governed by terms that can be
|
|
6
|
+
found in the LICENSE file in the root of this package.
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# Trouble shooting
|
|
10
|
+
|
|
11
|
+
## Table of contents <!-- omit in toc -->
|
|
12
|
+
|
|
13
|
+
- [Vscode Windows: Debugging is not working](#vscode-windows-debugging-is-not-working)
|
|
14
|
+
|
|
15
|
+
## Vscode Windows: Debugging is not working
|
|
16
|
+
|
|
17
|
+
Date: 2025-03-08
|
|
18
|
+
|
|
19
|
+
⚠️ IMPORTANT: On Windows, please check out the repo on drive C. There is a bug
|
|
20
|
+
in the VS Code Vitest extension (v1.14.4), which prevents test debugging from
|
|
21
|
+
working: <https://github.com/vitest-dev/vscode/issues/548> Please check from
|
|
22
|
+
time to time if the issue has been fixed and remove this note once it is
|
|
23
|
+
resolved.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ClientServerSetupOptions {
|
|
2
|
+
baseDir?: string;
|
|
3
|
+
treeKey?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ClientServerSetupResult {
|
|
6
|
+
baseDir: string;
|
|
7
|
+
folderA: string;
|
|
8
|
+
folderB: string;
|
|
9
|
+
contentB: string;
|
|
10
|
+
cleanup: () => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One-shot client/server setup that writes a file in folder A, stores it to a
|
|
14
|
+
* shared Db, loads into folder B, and returns the synced content.
|
|
15
|
+
* @param opts - Optional overrides (baseDir, treeKey)
|
|
16
|
+
*/
|
|
17
|
+
export declare function runClientServerSetup(opts?: ClientServerSetupOptions): Promise<ClientServerSetupResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const example: () => Promise<void>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Bs } from '@rljson/bs';
|
|
2
|
+
import { FsBlobAdapter } from './fs-blob-adapter.ts';
|
|
3
|
+
import { StoreFsTreeOptions } from './fs-db-adapter.ts';
|
|
4
|
+
import { FsScanner, FsTree } from './fs-scanner.ts';
|
|
5
|
+
import { Connector, Db } from '@rljson/db';
|
|
6
|
+
/**
|
|
7
|
+
* Options for FsAgent operations
|
|
8
|
+
*/
|
|
9
|
+
export interface FsAgentOptions {
|
|
10
|
+
/** Ignore patterns for scanning */
|
|
11
|
+
ignore?: string[];
|
|
12
|
+
/** Maximum depth for directory traversal */
|
|
13
|
+
maxDepth?: number;
|
|
14
|
+
/** Follow symlinks (default: false) */
|
|
15
|
+
followSymlinks?: boolean;
|
|
16
|
+
/** Database instance for automatic syncing */
|
|
17
|
+
db?: Db;
|
|
18
|
+
/** Tree key for database storage */
|
|
19
|
+
treeKey?: string;
|
|
20
|
+
/** Storage options for database operations */
|
|
21
|
+
storageOptions?: StoreFsTreeOptions;
|
|
22
|
+
/** Enable bidirectional sync (both fs→db and db→fs) */
|
|
23
|
+
bidirectional?: boolean;
|
|
24
|
+
/** Restore options applied when syncing from DB */
|
|
25
|
+
restoreOptions?: RestoreOptions;
|
|
26
|
+
}
|
|
27
|
+
/** Restore options */
|
|
28
|
+
export interface RestoreOptions {
|
|
29
|
+
/** Remove files/dirs on target that are not present in the tree */
|
|
30
|
+
cleanTarget?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Orchestrates filesystem operations with tree structures and blob storage
|
|
34
|
+
*/
|
|
35
|
+
export declare class FsAgent {
|
|
36
|
+
private _scanner;
|
|
37
|
+
private _adapter;
|
|
38
|
+
private _rootPath;
|
|
39
|
+
private _bs;
|
|
40
|
+
private _db?;
|
|
41
|
+
private _treeKey?;
|
|
42
|
+
private _stopSync?;
|
|
43
|
+
private _stopSyncFromDb?;
|
|
44
|
+
private _lastSentRef?;
|
|
45
|
+
constructor(rootPath: string, bs?: Bs, options?: FsAgentOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Gets the root path
|
|
48
|
+
*/
|
|
49
|
+
get rootPath(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the blob storage instance
|
|
52
|
+
*/
|
|
53
|
+
get bs(): Bs;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the scanner instance
|
|
56
|
+
*/
|
|
57
|
+
get scanner(): FsScanner;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the adapter instance
|
|
60
|
+
*/
|
|
61
|
+
get adapter(): FsBlobAdapter;
|
|
62
|
+
/**
|
|
63
|
+
* Starts automatic syncing to database
|
|
64
|
+
* Note: Auto-sync requires Connector which is not available in constructor.
|
|
65
|
+
* Consider using syncToDb() directly instead of constructor options.
|
|
66
|
+
*/
|
|
67
|
+
private _startAutoSync;
|
|
68
|
+
/**
|
|
69
|
+
* Starts automatic syncing from database
|
|
70
|
+
* @param bidirectional - Whether bidirectional sync is enabled
|
|
71
|
+
* Note: Auto-sync requires Connector which is not available in constructor.
|
|
72
|
+
* Consider using syncFromDb() directly instead of constructor options.
|
|
73
|
+
*/
|
|
74
|
+
private _startAutoSyncFromDb;
|
|
75
|
+
/**
|
|
76
|
+
* Stops automatic syncing and cleans up resources
|
|
77
|
+
*/
|
|
78
|
+
dispose(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Extracts filesystem into tree structure with file content in blobs
|
|
81
|
+
* File content is stored in Bs, tree structure returned with blobIds embedded
|
|
82
|
+
* @returns Tree structure with blobIds in file metadata
|
|
83
|
+
*/
|
|
84
|
+
extract(): Promise<FsTree>;
|
|
85
|
+
/**
|
|
86
|
+
* Restores filesystem from tree structure and blob storage
|
|
87
|
+
* @param tree - Tree structure with blobIds in file metadata
|
|
88
|
+
* @param targetPath - Optional target path (defaults to rootPath)
|
|
89
|
+
* @param options - Restore options
|
|
90
|
+
*/
|
|
91
|
+
restore(tree: FsTree, targetPath?: string, options?: RestoreOptions): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Recursively restores a tree node and its children
|
|
94
|
+
* @param treeHash - Hash of the tree node to restore
|
|
95
|
+
* @param trees - Map of all tree nodes
|
|
96
|
+
* @param targetPath - Target directory path
|
|
97
|
+
*/
|
|
98
|
+
private _restoreTree;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the current tree structure
|
|
101
|
+
*/
|
|
102
|
+
getTree(): FsTree | null;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if a blob exists in storage
|
|
105
|
+
* @param blobId - Blob ID to check
|
|
106
|
+
*/
|
|
107
|
+
hasBlob(blobId: string): Promise<boolean>;
|
|
108
|
+
/**
|
|
109
|
+
* Gets file content from blob storage
|
|
110
|
+
* @param blobId - Blob ID
|
|
111
|
+
*/
|
|
112
|
+
getFileContent(blobId: string): Promise<Buffer>;
|
|
113
|
+
/**
|
|
114
|
+
* Extracts and stores filesystem tree in database
|
|
115
|
+
* Reads from filesystem, stores trees in DB and blobs in Bs
|
|
116
|
+
* @param db - Database instance
|
|
117
|
+
* @param treeKey - Tree table key
|
|
118
|
+
* @param options - Storage options
|
|
119
|
+
* @returns The root tree reference
|
|
120
|
+
*/
|
|
121
|
+
storeInDb(db: Db, treeKey: string, options?: StoreFsTreeOptions): Promise<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Recursively fetches all tree nodes starting from a root hash
|
|
124
|
+
* Trees are stored as separate rows with parent-child relationships
|
|
125
|
+
* This method follows the tree structure and fetches all related nodes
|
|
126
|
+
* @param db - Database instance
|
|
127
|
+
* @param route - Route to tree table
|
|
128
|
+
* @param treeKey - Tree table key
|
|
129
|
+
* @param rootHash - Hash of the root node to start fetching from
|
|
130
|
+
* @returns Array of all tree nodes in the tree
|
|
131
|
+
*/
|
|
132
|
+
private _fetchTreeRecursively;
|
|
133
|
+
/**
|
|
134
|
+
* Loads tree from database and restores to filesystem
|
|
135
|
+
* Writes to filesystem from DB trees and Bs blobs
|
|
136
|
+
* @param db - Database instance
|
|
137
|
+
* @param treeKey - Tree table key
|
|
138
|
+
* @param rootRef - Root tree reference (hash)
|
|
139
|
+
* @param targetPath - Optional target path (defaults to rootPath)
|
|
140
|
+
* @param options - Restore options
|
|
141
|
+
*/
|
|
142
|
+
loadFromDb(db: Db, treeKey: string, rootRef: string, targetPath?: string, options?: RestoreOptions): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Collects expected file and directory paths for cleanup
|
|
145
|
+
* @param tree - Tree structure to evaluate
|
|
146
|
+
* @param target - Filesystem root where the tree will be restored
|
|
147
|
+
*/
|
|
148
|
+
private _collectExpectedPaths;
|
|
149
|
+
/**
|
|
150
|
+
* Remove files/dirs not present in the expected sets
|
|
151
|
+
* @param currentDir - Directory currently being inspected
|
|
152
|
+
* @param expectedDirs - Allowed directory paths
|
|
153
|
+
* @param expectedFiles - Allowed file paths
|
|
154
|
+
*/
|
|
155
|
+
private _pruneExtraneous;
|
|
156
|
+
/**
|
|
157
|
+
* Watches filesystem for changes and syncs to database
|
|
158
|
+
* Uses Connector for socket-based broadcast
|
|
159
|
+
* @param db - Database instance
|
|
160
|
+
* @param connector - Connector instance for socket-based sync
|
|
161
|
+
* @param treeKey - Tree table key
|
|
162
|
+
* @param options - Storage options (e.g., notify)
|
|
163
|
+
* @returns Function to stop watching
|
|
164
|
+
*/
|
|
165
|
+
syncToDb(db: Db, connector: Connector, treeKey: string, options?: StoreFsTreeOptions): Promise<() => void>;
|
|
166
|
+
/**
|
|
167
|
+
* Watches database for tree changes and syncs to filesystem
|
|
168
|
+
* Uses Connector for socket-based notifications
|
|
169
|
+
* @param db - Database instance
|
|
170
|
+
* @param connector - Connector instance for socket-based sync
|
|
171
|
+
* @param treeKey - Tree table key
|
|
172
|
+
* @param restoreOptions - Restore options (e.g., cleanTarget)
|
|
173
|
+
* @returns Function to stop watching
|
|
174
|
+
*/
|
|
175
|
+
syncFromDb(db: Db, connector: Connector, treeKey: string, restoreOptions?: RestoreOptions): Promise<() => void>;
|
|
176
|
+
/** Example instance for test purposes */
|
|
177
|
+
static get example(): FsAgent;
|
|
178
|
+
}
|