@lix-js/storage-filesystem 0.0.0 → 0.12.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/README.md CHANGED
@@ -1,4 +1,35 @@
1
- # `@lix-js/storage-filesystem`
1
+ # `lix-storage-filesystem`
2
2
 
3
- This `0.0.0` package is an inert registry bootstrap. Install a released version
4
- of `@lix-js/storage-filesystem` instead.
3
+ Filesystem-backed storage for Lix. The Rust crate and JavaScript package expose
4
+ the same adapter with independently versioned releases.
5
+
6
+ ## JavaScript
7
+
8
+ ```ts
9
+ import { openLix } from "@lix-js/sdk";
10
+ import { FilesystemStorage } from "@lix-js/storage-filesystem";
11
+
12
+ const storage = new FilesystemStorage({ path: "./repository" });
13
+ const lix = await openLix({ storage });
14
+ ```
15
+
16
+ The whole repository is synchronized by default. Pass `syncAllFiles: false`
17
+ and use `storage.importPaths(paths)` for selective synchronization.
18
+
19
+ ## Rust
20
+
21
+ ```rust
22
+ use lix::open_lix;
23
+ use lix_storage_filesystem::FilesystemStorage;
24
+
25
+ # async fn example() -> Result<(), lix::LixError> {
26
+ let storage = FilesystemStorage::new("./repository").open()?;
27
+ let lix = open_lix().with_storage(storage.clone()).await?;
28
+ storage.start_sync(&lix).await?;
29
+ # Ok(())
30
+ # }
31
+ ```
32
+
33
+ The storage owns synchronization until `storage.stop_sync().await?` or until
34
+ the final storage/repository instance is dropped. Explicitly stopping is useful
35
+ for tests and before immediately reopening the same path.
@@ -0,0 +1,38 @@
1
+ /** Options for opening filesystem-backed Lix storage. */
2
+ export type FilesystemStorageOptions = {
3
+ /** Directory synchronized with the Lix repository. */
4
+ path: string;
5
+ /** Whether every file below `path` is synchronized. Defaults to `true`. */
6
+ syncAllFiles?: boolean;
7
+ };
8
+ type FilesystemStorageConnection = {
9
+ importFilesystemPaths(paths: string[]): Promise<void>;
10
+ syncDiskToLix(): Promise<void>;
11
+ };
12
+ /**
13
+ * Filesystem-backed storage for Lix.
14
+ *
15
+ * Pass an instance to `openLix({ storage })`. The Rust
16
+ * `lix-storage-filesystem` adapter performs the actual storage and sync work.
17
+ */
18
+ export declare class FilesystemStorage {
19
+ #private;
20
+ readonly path: string;
21
+ readonly syncAllFiles: boolean;
22
+ readonly lixStorage: {
23
+ readonly version: 1;
24
+ readonly config: {
25
+ readonly kind: "filesystem";
26
+ readonly path: string;
27
+ readonly syncAllFiles: boolean;
28
+ };
29
+ connect(connection: FilesystemStorageConnection | undefined): void;
30
+ };
31
+ constructor(options: FilesystemStorageOptions);
32
+ /** Import selected filesystem paths into the open Lix repository. */
33
+ importPaths(paths: readonly string[]): Promise<void>;
34
+ /** Immediately synchronize current disk changes into Lix. */
35
+ syncDiskToLix(): Promise<void>;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../js/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,MAAM,wBAAwB,GAAG;IACtC,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IAClC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,iBAAiB;;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAG/B,QAAQ,CAAC,UAAU,EAAE;QACpB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,QAAQ,CAAC,MAAM,EAAE;YAChB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;YAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YACtB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;SAC/B,CAAC;QACF,OAAO,CAAC,UAAU,EAAE,2BAA2B,GAAG,SAAS,GAAG,IAAI,CAAC;KACnE,CAAC;gBAEU,OAAO,EAAE,wBAAwB;IA6B7C,qEAAqE;IAC/D,WAAW,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB1D,6DAA6D;IACvD,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAapC"}
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Filesystem-backed storage for Lix.
3
+ *
4
+ * Pass an instance to `openLix({ storage })`. The Rust
5
+ * `lix-storage-filesystem` adapter performs the actual storage and sync work.
6
+ */
7
+ export class FilesystemStorage {
8
+ path;
9
+ syncAllFiles;
10
+ #connection;
11
+ lixStorage;
12
+ constructor(options) {
13
+ if (!options || typeof options !== "object") {
14
+ throw new TypeError("FilesystemStorage options must be an object");
15
+ }
16
+ if (typeof options.path !== "string" || options.path.length === 0) {
17
+ throw new TypeError("FilesystemStorage requires a non-empty path");
18
+ }
19
+ if (options.syncAllFiles !== undefined &&
20
+ typeof options.syncAllFiles !== "boolean") {
21
+ throw new TypeError("FilesystemStorage syncAllFiles must be a boolean");
22
+ }
23
+ this.path = options.path;
24
+ this.syncAllFiles = options.syncAllFiles ?? true;
25
+ this.lixStorage = {
26
+ version: 1,
27
+ config: {
28
+ kind: "filesystem",
29
+ path: this.path,
30
+ syncAllFiles: this.syncAllFiles,
31
+ },
32
+ connect: (connection) => {
33
+ this.#connection = connection;
34
+ },
35
+ };
36
+ }
37
+ /** Import selected filesystem paths into the open Lix repository. */
38
+ async importPaths(paths) {
39
+ if (!Array.isArray(paths)) {
40
+ throw new TypeError("importPaths() paths must be an array");
41
+ }
42
+ for (const path of paths) {
43
+ if (typeof path !== "string" || path.length === 0) {
44
+ throw new TypeError("importPaths() paths must contain non-empty strings");
45
+ }
46
+ if (path.endsWith("/")) {
47
+ throw new TypeError("importPaths() paths must not end with a trailing slash");
48
+ }
49
+ }
50
+ await this.#requireConnection("importPaths").importFilesystemPaths([...paths]);
51
+ }
52
+ /** Immediately synchronize current disk changes into Lix. */
53
+ async syncDiskToLix() {
54
+ await this.#requireConnection("syncDiskToLix").syncDiskToLix();
55
+ }
56
+ #requireConnection(operation) {
57
+ if (this.#connection)
58
+ return this.#connection;
59
+ const error = new Error(`FilesystemStorage.${operation}() requires an open Lix using this storage`);
60
+ error.name = "LixError";
61
+ error.code = "LIX_FILESYSTEM_STORAGE_NOT_OPEN";
62
+ throw error;
63
+ }
64
+ }
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../js/index.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACpB,IAAI,CAAS;IACb,YAAY,CAAU;IAC/B,WAAW,CAA0C;IAE5C,UAAU,CAQjB;IAEF,YAAY,OAAiC;QAC5C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC7C,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnE,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;QACpE,CAAC;QACD,IACC,OAAO,CAAC,YAAY,KAAK,SAAS;YAClC,OAAO,OAAO,CAAC,YAAY,KAAK,SAAS,EACxC,CAAC;YACF,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAC;QACzE,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC;QACjD,IAAI,CAAC,UA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UAAU,CAAC;QACxB,KAAK,CAAC,IAAI,GAAG,iCAAiC,CAAC;QAC/C,MAAM,KAAK,CAAC;IACb,CAAC;CACD"}
package/package.json CHANGED
@@ -1,21 +1,35 @@
1
1
  {
2
2
  "name": "@lix-js/storage-filesystem",
3
- "version": "0.0.0",
4
- "description": "Bootstrap placeholder for the Lix filesystem storage package.",
5
- "license": "MIT",
6
3
  "type": "module",
4
+ "version": "0.12.0",
5
+ "license": "MIT",
7
6
  "repository": {
8
7
  "type": "git",
9
8
  "url": "https://github.com/opral/lix",
10
9
  "directory": "packages/storage-filesystem"
11
10
  },
12
- "exports": "./index.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
13
17
  "files": [
14
- "index.js",
18
+ "dist",
15
19
  "README.md"
16
20
  ],
17
- "publishConfig": {
18
- "access": "public",
19
- "tag": "bootstrap"
21
+ "scripts": {
22
+ "build": "npm run clean && tsc -p tsconfig.json",
23
+ "clean": "node -e \"import('node:fs/promises').then(({ rm }) => rm('dist', { recursive: true, force: true }))\"",
24
+ "test": "vitest run",
25
+ "typecheck": "tsc -p tsconfig.test.json --noEmit"
26
+ },
27
+ "peerDependencies": {
28
+ "@lix-js/sdk": "0.12.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^24.10.2",
32
+ "typescript": "^5.5.4",
33
+ "vitest": "4.1.10"
20
34
  }
21
35
  }
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- throw new Error(
2
- "@lix-js/storage-filesystem@0.0.0 is an inert registry bootstrap; install a released version instead.",
3
- );