@rljson/fs-agent 0.0.4 → 0.0.7

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/README.public.md CHANGED
@@ -314,6 +314,37 @@ Stops all syncing and cleans up resources.
314
314
  agent.dispose();
315
315
  ```
316
316
 
317
+ ##### `static fromClient(filePath, treeKey, client, socket, options?): Promise<FsAgent>`
318
+
319
+ Factory method that creates an FsAgent wired to a `@rljson/server` Client. Returns an enhanced agent with simplified sync methods:
320
+
321
+ ```typescript
322
+ import { Client } from '@rljson/server';
323
+
324
+ const agent = await FsAgent.fromClient(
325
+ './my-project',
326
+ 'sharedTree',
327
+ client,
328
+ socket,
329
+ { ignore: ['node_modules', '.git'] },
330
+ );
331
+
332
+ // Simplified sync (no need to manage Db/Connector manually)
333
+ const stopToDb = await agent.syncToDbSimple({ notify: true });
334
+ const stopFromDb = await agent.syncFromDbSimple({ cleanTarget: true });
335
+
336
+ // Stop when done
337
+ stopToDb();
338
+ stopFromDb();
339
+ ```
340
+
341
+ **Reconnect handling:** When the Client supports `onDisconnect` / `onReconnect` (available since `@rljson/server` ≥ 0.0.10), `fromClient()` automatically:
342
+
343
+ - **Pauses** the filesystem watcher on disconnect (prevents futile sync attempts while the server is unreachable)
344
+ - **Resumes** the watcher on reconnect (the server's bootstrap message triggers a catch-up sync via the Connector)
345
+
346
+ No application code is needed — the wiring is built into `fromClient()`. Clients created with older server versions that lack these methods continue to work without interruption.
347
+
317
348
  ### FsScanner
318
349
 
319
350
  Low-level filesystem scanner (usually accessed via `agent.scanner`).
@@ -314,6 +314,37 @@ Stops all syncing and cleans up resources.
314
314
  agent.dispose();
315
315
  ```
316
316
 
317
+ ##### `static fromClient(filePath, treeKey, client, socket, options?): Promise<FsAgent>`
318
+
319
+ Factory method that creates an FsAgent wired to a `@rljson/server` Client. Returns an enhanced agent with simplified sync methods:
320
+
321
+ ```typescript
322
+ import { Client } from '@rljson/server';
323
+
324
+ const agent = await FsAgent.fromClient(
325
+ './my-project',
326
+ 'sharedTree',
327
+ client,
328
+ socket,
329
+ { ignore: ['node_modules', '.git'] },
330
+ );
331
+
332
+ // Simplified sync (no need to manage Db/Connector manually)
333
+ const stopToDb = await agent.syncToDbSimple({ notify: true });
334
+ const stopFromDb = await agent.syncFromDbSimple({ cleanTarget: true });
335
+
336
+ // Stop when done
337
+ stopToDb();
338
+ stopFromDb();
339
+ ```
340
+
341
+ **Reconnect handling:** When the Client supports `onDisconnect` / `onReconnect` (available since `@rljson/server` ≥ 0.0.10), `fromClient()` automatically:
342
+
343
+ - **Pauses** the filesystem watcher on disconnect (prevents futile sync attempts while the server is unreachable)
344
+ - **Resumes** the watcher on reconnect (the server's bootstrap message triggers a catch-up sync via the Connector)
345
+
346
+ No application code is needed — the wiring is built into `fromClient()`. Clients created with older server versions that lack these methods continue to work without interruption.
347
+
317
348
  ### FsScanner
318
349
 
319
350
  Low-level filesystem scanner (usually accessed via `agent.scanner`).
package/dist/fs-agent.js CHANGED
@@ -385,16 +385,23 @@ class FsScanner {
385
385
  });
386
386
  }
387
387
  } catch {
388
+ let rootExists = false;
388
389
  try {
389
390
  await stat(this._rootPath);
390
- await this.scan();
391
- await this._notifyChange({
392
- type: "deleted",
393
- path: relativePath
394
- });
391
+ rootExists = true;
395
392
  } catch {
396
393
  this.stopWatch();
397
394
  }
395
+ if (rootExists) {
396
+ try {
397
+ await this.scan();
398
+ await this._notifyChange({
399
+ type: "deleted",
400
+ path: relativePath
401
+ });
402
+ } catch {
403
+ }
404
+ }
398
405
  }
399
406
  }
400
407
  _findTreeByPath(relativePath) {
@@ -1116,6 +1123,16 @@ class FsAgent {
1116
1123
  enhancedAgent.syncFromDbSimple = async (restoreOpts) => {
1117
1124
  return agent.syncFromDb(db, connector, treeKey, restoreOpts);
1118
1125
  };
1126
+ if (typeof client.onDisconnect === "function") {
1127
+ client.onDisconnect(() => {
1128
+ agent.scanner.pauseWatch();
1129
+ });
1130
+ }
1131
+ if (typeof client.onReconnect === "function") {
1132
+ client.onReconnect(() => {
1133
+ agent.scanner.resumeWatch();
1134
+ });
1135
+ }
1119
1136
  return enhancedAgent;
1120
1137
  }
1121
1138
  /** Example instance for test purposes */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/fs-agent",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "Rljson fs-agent description",
5
5
  "homepage": "https://github.com/rljson/fs-agent",
6
6
  "bugs": "https://github.com/rljson/fs-agent/issues",
@@ -20,20 +20,20 @@
20
20
  ],
21
21
  "type": "module",
22
22
  "devDependencies": {
23
- "@rljson/server": "^0.0.6",
24
- "@types/node": "^25.2.3",
25
- "@typescript-eslint/eslint-plugin": "^8.56.0",
26
- "@typescript-eslint/parser": "^8.56.0",
23
+ "@rljson/server": "^0.0.10",
24
+ "@types/node": "^25.3.1",
25
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
26
+ "@typescript-eslint/parser": "^8.56.1",
27
27
  "@vitest/coverage-v8": "^4.0.18",
28
28
  "cross-env": "^10.1.0",
29
- "eslint": "~9.39.2",
30
- "eslint-plugin-jsdoc": "^62.5.5",
31
- "eslint-plugin-tsdoc": "^0.5.0",
29
+ "eslint": "~9.39.3",
30
+ "eslint-plugin-jsdoc": "^62.7.1",
31
+ "eslint-plugin-tsdoc": "^0.5.2",
32
32
  "globals": "^17.3.0",
33
33
  "jsdoc": "^4.0.5",
34
34
  "read-pkg": "^10.1.0",
35
35
  "typescript": "~5.9.3",
36
- "typescript-eslint": "^8.56.0",
36
+ "typescript-eslint": "^8.56.1",
37
37
  "vite": "^7.3.1",
38
38
  "vite-node": "^5.3.0",
39
39
  "vite-plugin-dts": "^4.5.4",
@@ -43,11 +43,11 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rljson/bs": "^0.0.21",
46
- "@rljson/db": "^0.0.14",
46
+ "@rljson/db": "^0.0.15",
47
47
  "@rljson/hash": "^0.0.18",
48
48
  "@rljson/io": "^0.0.66",
49
49
  "@rljson/json": "^0.0.23",
50
- "@rljson/rljson": "^0.0.76",
50
+ "@rljson/rljson": "^0.0.78",
51
51
  "socket.io": "^4.8.3",
52
52
  "socket.io-client": "^4.8.3"
53
53
  },