@molecule/app-filesystem 1.0.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/LICENSE ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Device filesystem access interface for molecule.dev.
3
+ *
4
+ * Framework-agnostic core for app-scoped file storage through a swappable
5
+ * `FilesystemProvider`: read/write/append (text or Blob), directories
6
+ * (mkdir/rmdir/readdir), stat/exists, copy/move, URIs for native viewers,
7
+ * and free-space checks — all addressed relative to well-known base
8
+ * directories (`'documents' | 'data' | 'cache' | 'external' | 'library' |
9
+ * 'temp'`). Pure path/format helpers (`joinPath`, `getExtension`,
10
+ * `getBasename`, `getDirname`, `getMimeType`, `formatFileSize`) work
11
+ * without a provider.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import {
16
+ * exists,
17
+ * hasProvider,
18
+ * joinPath,
19
+ * readFile,
20
+ * writeFile,
21
+ * } from '@molecule/app-filesystem'
22
+ *
23
+ * async function saveDraft(text: string): Promise<void> {
24
+ * if (!hasProvider()) return // no provider wired — use app-storage instead
25
+ * const path = joinPath('drafts', 'note.txt')
26
+ * await writeFile(path, text, { directory: 'data', recursive: true })
27
+ * }
28
+ *
29
+ * async function loadDraft(): Promise<string | null> {
30
+ * const path = joinPath('drafts', 'note.txt')
31
+ * if (!(await exists(path, { directory: 'data' }))) return null
32
+ * return readFile(path, { directory: 'data' })
33
+ * }
34
+ * ```
35
+ *
36
+ * @remarks
37
+ * - **Every file operation THROWS until `setProvider()` is called** — there
38
+ * is no web fallback and **no prebuilt provider package ships with
39
+ * molecule**; supply a `FilesystemProvider` from your native runtime.
40
+ * - **This is NOT general key-value persistence.** For settings/state on any
41
+ * platform use `@molecule/app-storage`; reach for app-filesystem only when
42
+ * you genuinely need files (large blobs, exports, media handed to other
43
+ * apps via `getUri`).
44
+ * - On web there is no path-addressed filesystem; a provider could be built
45
+ * on OPFS (origin-private, invisible to the user's file manager), but
46
+ * `'external'`/`'library'` semantics and `getUri` for OS viewers do not
47
+ * translate — feature-gate on `getCapabilities()`.
48
+ * - Paths are RELATIVE to the `directory` base option (default varies by
49
+ * provider — pass it explicitly). Use `joinPath`, never string-concat
50
+ * with `/`.
51
+ * - Write ops fail on missing parent directories unless
52
+ * `{ recursive: true }`.
53
+ *
54
+ * @module
55
+ */
56
+ export * from './provider.js';
57
+ export * from './types.js';
58
+ export * from './utilities.js';
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Device filesystem access interface for molecule.dev.
3
+ *
4
+ * Framework-agnostic core for app-scoped file storage through a swappable
5
+ * `FilesystemProvider`: read/write/append (text or Blob), directories
6
+ * (mkdir/rmdir/readdir), stat/exists, copy/move, URIs for native viewers,
7
+ * and free-space checks — all addressed relative to well-known base
8
+ * directories (`'documents' | 'data' | 'cache' | 'external' | 'library' |
9
+ * 'temp'`). Pure path/format helpers (`joinPath`, `getExtension`,
10
+ * `getBasename`, `getDirname`, `getMimeType`, `formatFileSize`) work
11
+ * without a provider.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import {
16
+ * exists,
17
+ * hasProvider,
18
+ * joinPath,
19
+ * readFile,
20
+ * writeFile,
21
+ * } from '@molecule/app-filesystem'
22
+ *
23
+ * async function saveDraft(text: string): Promise<void> {
24
+ * if (!hasProvider()) return // no provider wired — use app-storage instead
25
+ * const path = joinPath('drafts', 'note.txt')
26
+ * await writeFile(path, text, { directory: 'data', recursive: true })
27
+ * }
28
+ *
29
+ * async function loadDraft(): Promise<string | null> {
30
+ * const path = joinPath('drafts', 'note.txt')
31
+ * if (!(await exists(path, { directory: 'data' }))) return null
32
+ * return readFile(path, { directory: 'data' })
33
+ * }
34
+ * ```
35
+ *
36
+ * @remarks
37
+ * - **Every file operation THROWS until `setProvider()` is called** — there
38
+ * is no web fallback and **no prebuilt provider package ships with
39
+ * molecule**; supply a `FilesystemProvider` from your native runtime.
40
+ * - **This is NOT general key-value persistence.** For settings/state on any
41
+ * platform use `@molecule/app-storage`; reach for app-filesystem only when
42
+ * you genuinely need files (large blobs, exports, media handed to other
43
+ * apps via `getUri`).
44
+ * - On web there is no path-addressed filesystem; a provider could be built
45
+ * on OPFS (origin-private, invisible to the user's file manager), but
46
+ * `'external'`/`'library'` semantics and `getUri` for OS viewers do not
47
+ * translate — feature-gate on `getCapabilities()`.
48
+ * - Paths are RELATIVE to the `directory` base option (default varies by
49
+ * provider — pass it explicitly). Use `joinPath`, never string-concat
50
+ * with `/`.
51
+ * - Write ops fail on missing parent directories unless
52
+ * `{ recursive: true }`.
53
+ *
54
+ * @module
55
+ */
56
+ export * from './provider.js';
57
+ export * from './types.js';
58
+ export * from './utilities.js';
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Filesystem provider management for molecule.dev.
3
+ *
4
+ * @module
5
+ */
6
+ import type { CopyOptions, DeleteOptions, Directory, FileInfo, FilesystemCapabilities, FilesystemProvider, ListOptions, ReadOptions, StatOptions, WriteOptions } from './types.js';
7
+ /**
8
+ * Set the filesystem provider.
9
+ * @param provider - FilesystemProvider implementation to register.
10
+ */
11
+ export declare function setProvider(provider: FilesystemProvider): void;
12
+ /**
13
+ * Get the current filesystem provider.
14
+ * @throws {Error} If no provider has been set via setProvider.
15
+ * @returns The active FilesystemProvider instance.
16
+ */
17
+ export declare function getProvider(): FilesystemProvider;
18
+ /**
19
+ * Check if a filesystem provider has been registered.
20
+ * @returns Whether a FilesystemProvider has been bonded.
21
+ */
22
+ export declare function hasProvider(): boolean;
23
+ /**
24
+ * Read a file as text.
25
+ * @param path - The file path to read.
26
+ * @param options - Read options (directory, encoding).
27
+ * @returns The file contents as a string.
28
+ */
29
+ export declare function readFile(path: string, options?: ReadOptions): Promise<string>;
30
+ /**
31
+ * Read a file as binary data.
32
+ * @param path - The file path to read.
33
+ * @param options - Read options (directory).
34
+ * @returns The file contents as a Blob.
35
+ */
36
+ export declare function readFileAsBlob(path: string, options?: Omit<ReadOptions, 'encoding'>): Promise<Blob>;
37
+ /**
38
+ * Write text content to a file.
39
+ * @param path - The file path to write to.
40
+ * @param data - The text content to write.
41
+ * @param options - Write options (directory, encoding, recursive, append).
42
+ * @returns A promise that resolves when the file is written.
43
+ */
44
+ export declare function writeFile(path: string, data: string, options?: WriteOptions): Promise<void>;
45
+ /**
46
+ * Write binary data to a file.
47
+ * @param path - The file path to write to.
48
+ * @param data - The binary data to write as a Blob.
49
+ * @param options - Write options (directory, recursive).
50
+ * @returns A promise that resolves when the file is written.
51
+ */
52
+ export declare function writeFileFromBlob(path: string, data: Blob, options?: Omit<WriteOptions, 'encoding'>): Promise<void>;
53
+ /**
54
+ * Append text content to a file.
55
+ * @param path - The file path to append to.
56
+ * @param data - The text content to append.
57
+ * @param options - Write options (directory, encoding).
58
+ * @returns A promise that resolves when the data is appended.
59
+ */
60
+ export declare function appendFile(path: string, data: string, options?: WriteOptions): Promise<void>;
61
+ /**
62
+ * Delete a file.
63
+ * @param path - The file path to delete.
64
+ * @param options - Delete options (directory, recursive).
65
+ * @returns A promise that resolves when the file is deleted.
66
+ */
67
+ export declare function deleteFile(path: string, options?: DeleteOptions): Promise<void>;
68
+ /**
69
+ * Create a directory.
70
+ * @param path - The directory path to create.
71
+ * @param options - Write options (directory, recursive for parent directories).
72
+ * @returns A promise that resolves when the directory is created.
73
+ */
74
+ export declare function mkdir(path: string, options?: WriteOptions): Promise<void>;
75
+ /**
76
+ * Remove a directory.
77
+ * @param path - The directory path to remove.
78
+ * @param options - Delete options (directory, recursive for contents).
79
+ * @returns A promise that resolves when the directory is removed.
80
+ */
81
+ export declare function rmdir(path: string, options?: DeleteOptions): Promise<void>;
82
+ /**
83
+ * List directory contents.
84
+ * @param path - The directory path to list.
85
+ * @param options - List options (directory, include hidden files).
86
+ * @returns An array of FileInfo objects for each entry.
87
+ */
88
+ export declare function readdir(path: string, options?: ListOptions): Promise<FileInfo[]>;
89
+ /**
90
+ * Get file or directory metadata.
91
+ * @param path - The path to stat.
92
+ * @param options - Stat options (directory).
93
+ * @returns The FileInfo with size, dates, and type information.
94
+ */
95
+ export declare function stat(path: string, options?: StatOptions): Promise<FileInfo>;
96
+ /**
97
+ * Check if a file or directory exists.
98
+ * @param path - The path to check.
99
+ * @param options - Stat options (directory).
100
+ * @returns Whether the path exists.
101
+ */
102
+ export declare function exists(path: string, options?: StatOptions): Promise<boolean>;
103
+ /**
104
+ * Copy a file to a new location.
105
+ * @param from - The source file path.
106
+ * @param to - The destination file path.
107
+ * @param options - Copy options (source/dest directories, overwrite).
108
+ * @returns A promise that resolves when the file is copied.
109
+ */
110
+ export declare function copy(from: string, to: string, options?: CopyOptions): Promise<void>;
111
+ /**
112
+ * Move or rename a file.
113
+ * @param from - The source file path.
114
+ * @param to - The destination file path.
115
+ * @param options - Move options (source/dest directories, overwrite).
116
+ * @returns A promise that resolves when the file is moved.
117
+ */
118
+ export declare function move(from: string, to: string, options?: CopyOptions): Promise<void>;
119
+ /**
120
+ * Get the platform-specific URI for a file path.
121
+ * @param path - The file path to resolve.
122
+ * @param options - Stat options (directory).
123
+ * @returns The file's platform URI string.
124
+ */
125
+ export declare function getUri(path: string, options?: StatOptions): Promise<string>;
126
+ /**
127
+ * Get available storage space in bytes for a directory.
128
+ * @param directory - The directory type to check (defaults to app data).
129
+ * @returns The available space in bytes.
130
+ */
131
+ export declare function getAvailableSpace(directory?: Directory): Promise<number>;
132
+ /**
133
+ * Get the platform's filesystem capabilities.
134
+ * @returns The capabilities indicating available directories, picker support, and size limits.
135
+ */
136
+ export declare function getCapabilities(): Promise<FilesystemCapabilities>;
137
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,QAAQ,EACR,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAA;AAInB;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,kBAAkB,CAWhD;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAMD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAEnF;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,GACtC,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,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AAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzF;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzF;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAEjF;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAE9E;AAED;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAEvE"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Filesystem provider management for molecule.dev.
3
+ *
4
+ * @module
5
+ */
6
+ import { bond, get as bondGet, isBonded } from '@molecule/app-bond';
7
+ import { t } from '@molecule/app-i18n';
8
+ const BOND_TYPE = 'filesystem';
9
+ /**
10
+ * Set the filesystem provider.
11
+ * @param provider - FilesystemProvider implementation to register.
12
+ */
13
+ export function setProvider(provider) {
14
+ bond(BOND_TYPE, provider);
15
+ }
16
+ /**
17
+ * Get the current filesystem provider.
18
+ * @throws {Error} If no provider has been set via setProvider.
19
+ * @returns The active FilesystemProvider instance.
20
+ */
21
+ export function getProvider() {
22
+ const provider = bondGet(BOND_TYPE);
23
+ if (!provider) {
24
+ throw new Error(t('filesystem.error.noProvider', undefined, {
25
+ defaultValue: '@molecule/app-filesystem: No provider set. Call setProvider() with a FilesystemProvider implementation — no provider ships with the fleet; implement the interface on your native runtime and bond it.',
26
+ }));
27
+ }
28
+ return provider;
29
+ }
30
+ /**
31
+ * Check if a filesystem provider has been registered.
32
+ * @returns Whether a FilesystemProvider has been bonded.
33
+ */
34
+ export function hasProvider() {
35
+ return isBonded(BOND_TYPE);
36
+ }
37
+ // ============================================================================
38
+ // Convenience Functions
39
+ // ============================================================================
40
+ /**
41
+ * Read a file as text.
42
+ * @param path - The file path to read.
43
+ * @param options - Read options (directory, encoding).
44
+ * @returns The file contents as a string.
45
+ */
46
+ export async function readFile(path, options) {
47
+ return getProvider().readFile(path, options);
48
+ }
49
+ /**
50
+ * Read a file as binary data.
51
+ * @param path - The file path to read.
52
+ * @param options - Read options (directory).
53
+ * @returns The file contents as a Blob.
54
+ */
55
+ export async function readFileAsBlob(path, options) {
56
+ return getProvider().readFileAsBlob(path, options);
57
+ }
58
+ /**
59
+ * Write text content to a file.
60
+ * @param path - The file path to write to.
61
+ * @param data - The text content to write.
62
+ * @param options - Write options (directory, encoding, recursive, append).
63
+ * @returns A promise that resolves when the file is written.
64
+ */
65
+ export async function writeFile(path, data, options) {
66
+ return getProvider().writeFile(path, data, options);
67
+ }
68
+ /**
69
+ * Write binary data to a file.
70
+ * @param path - The file path to write to.
71
+ * @param data - The binary data to write as a Blob.
72
+ * @param options - Write options (directory, recursive).
73
+ * @returns A promise that resolves when the file is written.
74
+ */
75
+ export async function writeFileFromBlob(path, data, options) {
76
+ return getProvider().writeFileFromBlob(path, data, options);
77
+ }
78
+ /**
79
+ * Append text content to a file.
80
+ * @param path - The file path to append to.
81
+ * @param data - The text content to append.
82
+ * @param options - Write options (directory, encoding).
83
+ * @returns A promise that resolves when the data is appended.
84
+ */
85
+ export async function appendFile(path, data, options) {
86
+ return getProvider().appendFile(path, data, options);
87
+ }
88
+ /**
89
+ * Delete a file.
90
+ * @param path - The file path to delete.
91
+ * @param options - Delete options (directory, recursive).
92
+ * @returns A promise that resolves when the file is deleted.
93
+ */
94
+ export async function deleteFile(path, options) {
95
+ return getProvider().deleteFile(path, options);
96
+ }
97
+ /**
98
+ * Create a directory.
99
+ * @param path - The directory path to create.
100
+ * @param options - Write options (directory, recursive for parent directories).
101
+ * @returns A promise that resolves when the directory is created.
102
+ */
103
+ export async function mkdir(path, options) {
104
+ return getProvider().mkdir(path, options);
105
+ }
106
+ /**
107
+ * Remove a directory.
108
+ * @param path - The directory path to remove.
109
+ * @param options - Delete options (directory, recursive for contents).
110
+ * @returns A promise that resolves when the directory is removed.
111
+ */
112
+ export async function rmdir(path, options) {
113
+ return getProvider().rmdir(path, options);
114
+ }
115
+ /**
116
+ * List directory contents.
117
+ * @param path - The directory path to list.
118
+ * @param options - List options (directory, include hidden files).
119
+ * @returns An array of FileInfo objects for each entry.
120
+ */
121
+ export async function readdir(path, options) {
122
+ return getProvider().readdir(path, options);
123
+ }
124
+ /**
125
+ * Get file or directory metadata.
126
+ * @param path - The path to stat.
127
+ * @param options - Stat options (directory).
128
+ * @returns The FileInfo with size, dates, and type information.
129
+ */
130
+ export async function stat(path, options) {
131
+ return getProvider().stat(path, options);
132
+ }
133
+ /**
134
+ * Check if a file or directory exists.
135
+ * @param path - The path to check.
136
+ * @param options - Stat options (directory).
137
+ * @returns Whether the path exists.
138
+ */
139
+ export async function exists(path, options) {
140
+ return getProvider().exists(path, options);
141
+ }
142
+ /**
143
+ * Copy a file to a new location.
144
+ * @param from - The source file path.
145
+ * @param to - The destination file path.
146
+ * @param options - Copy options (source/dest directories, overwrite).
147
+ * @returns A promise that resolves when the file is copied.
148
+ */
149
+ export async function copy(from, to, options) {
150
+ return getProvider().copy(from, to, options);
151
+ }
152
+ /**
153
+ * Move or rename a file.
154
+ * @param from - The source file path.
155
+ * @param to - The destination file path.
156
+ * @param options - Move options (source/dest directories, overwrite).
157
+ * @returns A promise that resolves when the file is moved.
158
+ */
159
+ export async function move(from, to, options) {
160
+ return getProvider().move(from, to, options);
161
+ }
162
+ /**
163
+ * Get the platform-specific URI for a file path.
164
+ * @param path - The file path to resolve.
165
+ * @param options - Stat options (directory).
166
+ * @returns The file's platform URI string.
167
+ */
168
+ export async function getUri(path, options) {
169
+ return getProvider().getUri(path, options);
170
+ }
171
+ /**
172
+ * Get available storage space in bytes for a directory.
173
+ * @param directory - The directory type to check (defaults to app data).
174
+ * @returns The available space in bytes.
175
+ */
176
+ export async function getAvailableSpace(directory) {
177
+ return getProvider().getAvailableSpace(directory);
178
+ }
179
+ /**
180
+ * Get the platform's filesystem capabilities.
181
+ * @returns The capabilities indicating available directories, picker support, and size limits.
182
+ */
183
+ export async function getCapabilities() {
184
+ return getProvider().getCapabilities();
185
+ }
186
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAetC,MAAM,SAAS,GAAG,YAAY,CAAA;AAE9B;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAA4B;IACtD,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,QAAQ,GAAG,OAAO,CAAqB,SAAS,CAAC,CAAA;IACvD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,CAAC,CAAC,6BAA6B,EAAE,SAAS,EAAE;YAC1C,YAAY,EACV,wMAAwM;SAC3M,CAAC,CACH,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,OAAqB;IAChE,OAAO,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,EAA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O,WAAW,EAAE,CAAC,eAAe,EAAE,CAAA;AACxC,CAAC"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Filesystem types for molecule.dev.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * File system directory type
8
+ */
9
+ export type Directory = 'documents' | 'data' | 'cache' | 'external' | 'library' | 'temp';
10
+ /**
11
+ * Text encoding for file read/write operations.
12
+ */
13
+ export type Encoding = 'utf8' | 'ascii' | 'base64';
14
+ /**
15
+ * Metadata about a file or directory (name, path, size, timestamps, type).
16
+ */
17
+ export interface FileInfo {
18
+ /** File name */
19
+ name: string;
20
+ /** Full path */
21
+ path: string;
22
+ /** File URI */
23
+ uri: string;
24
+ /** File size in bytes */
25
+ size: number;
26
+ /** Creation time (ISO string) */
27
+ createdAt?: string;
28
+ /** Modification time (ISO string) */
29
+ modifiedAt?: string;
30
+ /** Whether this is a directory */
31
+ isDirectory: boolean;
32
+ /** Whether this is a file */
33
+ isFile: boolean;
34
+ /** MIME type (if available) */
35
+ mimeType?: string;
36
+ }
37
+ /**
38
+ * Options for reading a file (target directory and text encoding).
39
+ */
40
+ export interface ReadOptions {
41
+ /** Directory to read from */
42
+ directory?: Directory;
43
+ /** File encoding */
44
+ encoding?: Encoding;
45
+ }
46
+ /**
47
+ * Options for writing a file (directory, encoding, recursive creation, append mode).
48
+ */
49
+ export interface WriteOptions {
50
+ /** Directory to write to */
51
+ directory?: Directory;
52
+ /** File encoding */
53
+ encoding?: Encoding;
54
+ /** Whether to create parent directories */
55
+ recursive?: boolean;
56
+ /** Whether to append to existing file */
57
+ append?: boolean;
58
+ }
59
+ /**
60
+ * Copy/move options
61
+ */
62
+ export interface CopyOptions {
63
+ /** Source directory */
64
+ fromDirectory?: Directory;
65
+ /** Destination directory */
66
+ toDirectory?: Directory;
67
+ /** Overwrite existing file */
68
+ overwrite?: boolean;
69
+ }
70
+ /**
71
+ * Options for listing directory contents (directory type, hidden files).
72
+ */
73
+ export interface ListOptions {
74
+ /** Directory type */
75
+ directory?: Directory;
76
+ /** Whether to include hidden files */
77
+ includeHidden?: boolean;
78
+ }
79
+ /**
80
+ * Options for getting file/directory metadata (target directory type).
81
+ */
82
+ export interface StatOptions {
83
+ /** Directory type */
84
+ directory?: Directory;
85
+ }
86
+ /**
87
+ * Options for deleting a file or directory (directory type, recursive deletion).
88
+ */
89
+ export interface DeleteOptions {
90
+ /** Directory type */
91
+ directory?: Directory;
92
+ /** Delete directory contents recursively */
93
+ recursive?: boolean;
94
+ }
95
+ /**
96
+ * Filesystem capabilities
97
+ */
98
+ export interface FilesystemCapabilities {
99
+ /** Whether filesystem access is supported */
100
+ supported: boolean;
101
+ /** Available directories */
102
+ directories: Directory[];
103
+ /** Whether external storage is available */
104
+ hasExternalStorage: boolean;
105
+ /** Whether file picking is supported */
106
+ hasPicker: boolean;
107
+ /** Maximum file size (if limited) */
108
+ maxFileSize?: number;
109
+ }
110
+ /**
111
+ * Filesystem provider interface
112
+ */
113
+ export interface FilesystemProvider {
114
+ /**
115
+ * Read a file as text
116
+ * @param path - File path
117
+ * @param options - Read options
118
+ */
119
+ readFile(path: string, options?: ReadOptions): Promise<string>;
120
+ /**
121
+ * Read a file as binary data
122
+ * @param path - File path
123
+ * @param options - Read options
124
+ */
125
+ readFileAsBlob(path: string, options?: Omit<ReadOptions, 'encoding'>): Promise<Blob>;
126
+ /**
127
+ * Write text to a file
128
+ * @param path - File path
129
+ * @param data - Content to write
130
+ * @param options - Write options
131
+ */
132
+ writeFile(path: string, data: string, options?: WriteOptions): Promise<void>;
133
+ /**
134
+ * Write binary data to a file
135
+ * @param path - File path
136
+ * @param data - Binary data to write
137
+ * @param options - Write options
138
+ */
139
+ writeFileFromBlob(path: string, data: Blob, options?: Omit<WriteOptions, 'encoding'>): Promise<void>;
140
+ /**
141
+ * Append text to a file
142
+ * @param path - File path
143
+ * @param data - Content to append
144
+ * @param options - Write options
145
+ */
146
+ appendFile(path: string, data: string, options?: WriteOptions): Promise<void>;
147
+ /**
148
+ * Delete a file
149
+ * @param path - File path
150
+ * @param options - Delete options
151
+ */
152
+ deleteFile(path: string, options?: DeleteOptions): Promise<void>;
153
+ /**
154
+ * Create a directory
155
+ * @param path - Directory path
156
+ * @param options - Options
157
+ */
158
+ mkdir(path: string, options?: WriteOptions): Promise<void>;
159
+ /**
160
+ * Remove a directory
161
+ * @param path - Directory path
162
+ * @param options - Delete options
163
+ */
164
+ rmdir(path: string, options?: DeleteOptions): Promise<void>;
165
+ /**
166
+ * List directory contents
167
+ * @param path - Directory path
168
+ * @param options - List options
169
+ */
170
+ readdir(path: string, options?: ListOptions): Promise<FileInfo[]>;
171
+ /**
172
+ * Get file/directory info
173
+ * @param path - Path
174
+ * @param options - Stat options
175
+ */
176
+ stat(path: string, options?: StatOptions): Promise<FileInfo>;
177
+ /**
178
+ * Check if file/directory exists
179
+ * @param path - Path
180
+ * @param options - Options
181
+ */
182
+ exists(path: string, options?: StatOptions): Promise<boolean>;
183
+ /**
184
+ * Copy a file
185
+ * @param from - Source path
186
+ * @param to - Destination path
187
+ * @param options - Copy options
188
+ */
189
+ copy(from: string, to: string, options?: CopyOptions): Promise<void>;
190
+ /**
191
+ * Move/rename a file
192
+ * @param from - Source path
193
+ * @param to - Destination path
194
+ * @param options - Copy options
195
+ */
196
+ move(from: string, to: string, options?: CopyOptions): Promise<void>;
197
+ /**
198
+ * Get the platform URI for a file path.
199
+ * @param path - The file path to resolve.
200
+ * @param options - Options including directory type.
201
+ * @returns The file's platform-specific URI string.
202
+ */
203
+ getUri(path: string, options?: StatOptions): Promise<string>;
204
+ /**
205
+ * Get available storage space in bytes.
206
+ * @param directory - The directory type to check (defaults to app data).
207
+ * @returns The available space in bytes.
208
+ */
209
+ getAvailableSpace(directory?: Directory): Promise<number>;
210
+ /**
211
+ * Get the platform's filesystem capabilities.
212
+ * @returns The capabilities indicating available directories, picker support, and size limits.
213
+ */
214
+ getCapabilities(): Promise<FilesystemCapabilities>;
215
+ }
216
+ //# sourceMappingURL=types.d.ts.map
@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AAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpE;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE5D;;;;OAIG;IACH,iBAAiB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEzD;;;OAGG;IACH,eAAe,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAA;CACnD"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Filesystem types for molecule.dev.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Filesystem utility functions for molecule.dev.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Format a byte count as a human-readable file size string (e.g., '1.5 MB').
8
+ * @param bytes - The size in bytes.
9
+ * @returns A formatted string with the appropriate unit (B, KB, MB, GB, TB).
10
+ */
11
+ export declare function formatFileSize(bytes: number): string;
12
+ /**
13
+ * Extract the file extension from a path, without the leading dot.
14
+ * @param path - The file path or filename.
15
+ * @returns The lowercase extension (e.g., 'txt'), or empty string if none.
16
+ */
17
+ export declare function getExtension(path: string): string;
18
+ /**
19
+ * Get the filename without its extension from a path.
20
+ * @param path - The file path.
21
+ * @returns The base filename without extension (e.g., 'readme' from '/docs/readme.md').
22
+ */
23
+ export declare function getBasename(path: string): string;
24
+ /**
25
+ * Get the directory portion of a file path.
26
+ * @param path - The file path.
27
+ * @returns The parent directory path (e.g., '/docs' from '/docs/readme.md').
28
+ */
29
+ export declare function getDirname(path: string): string;
30
+ /**
31
+ * Join multiple path segments into a single normalized path.
32
+ * Collapses duplicate slashes and removes trailing slashes.
33
+ * @param segments - The path segments to join.
34
+ * @returns The joined and normalized path.
35
+ */
36
+ export declare function joinPath(...segments: string[]): string;
37
+ /**
38
+ * Infer a MIME type from a file extension. Supports common image, document,
39
+ * text, media, and archive formats. Falls back to 'application/octet-stream'.
40
+ * @param path - The file path or extension to look up.
41
+ * @returns The inferred MIME type string.
42
+ */
43
+ export declare function getMimeType(path: string): string;
44
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWpD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwChD"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Filesystem utility functions for molecule.dev.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Format a byte count as a human-readable file size string (e.g., '1.5 MB').
8
+ * @param bytes - The size in bytes.
9
+ * @returns A formatted string with the appropriate unit (B, KB, MB, GB, TB).
10
+ */
11
+ export function formatFileSize(bytes) {
12
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
13
+ let unitIndex = 0;
14
+ let size = bytes;
15
+ while (size >= 1024 && unitIndex < units.length - 1) {
16
+ size /= 1024;
17
+ unitIndex++;
18
+ }
19
+ return `${size.toFixed(unitIndex > 0 ? 1 : 0)} ${units[unitIndex]}`;
20
+ }
21
+ /**
22
+ * Extract the file extension from a path, without the leading dot.
23
+ * @param path - The file path or filename.
24
+ * @returns The lowercase extension (e.g., 'txt'), or empty string if none.
25
+ */
26
+ export function getExtension(path) {
27
+ const parts = path.split('.');
28
+ return parts.length > 1 ? parts.pop().toLowerCase() : '';
29
+ }
30
+ /**
31
+ * Get the filename without its extension from a path.
32
+ * @param path - The file path.
33
+ * @returns The base filename without extension (e.g., 'readme' from '/docs/readme.md').
34
+ */
35
+ export function getBasename(path) {
36
+ const name = path.split('/').pop() || '';
37
+ const dotIndex = name.lastIndexOf('.');
38
+ return dotIndex > 0 ? name.slice(0, dotIndex) : name;
39
+ }
40
+ /**
41
+ * Get the directory portion of a file path.
42
+ * @param path - The file path.
43
+ * @returns The parent directory path (e.g., '/docs' from '/docs/readme.md').
44
+ */
45
+ export function getDirname(path) {
46
+ const parts = path.split('/');
47
+ parts.pop();
48
+ return parts.join('/') || '/';
49
+ }
50
+ /**
51
+ * Join multiple path segments into a single normalized path.
52
+ * Collapses duplicate slashes and removes trailing slashes.
53
+ * @param segments - The path segments to join.
54
+ * @returns The joined and normalized path.
55
+ */
56
+ export function joinPath(...segments) {
57
+ return segments.join('/').replace(/\/+/g, '/').replace(/\/$/, '') || '/';
58
+ }
59
+ /**
60
+ * Infer a MIME type from a file extension. Supports common image, document,
61
+ * text, media, and archive formats. Falls back to 'application/octet-stream'.
62
+ * @param path - The file path or extension to look up.
63
+ * @returns The inferred MIME type string.
64
+ */
65
+ export function getMimeType(path) {
66
+ const ext = getExtension(path);
67
+ const mimeTypes = {
68
+ // Images
69
+ jpg: 'image/jpeg',
70
+ jpeg: 'image/jpeg',
71
+ png: 'image/png',
72
+ gif: 'image/gif',
73
+ webp: 'image/webp',
74
+ svg: 'image/svg+xml',
75
+ // Documents
76
+ pdf: 'application/pdf',
77
+ doc: 'application/msword',
78
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
79
+ xls: 'application/vnd.ms-excel',
80
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
81
+ ppt: 'application/vnd.ms-powerpoint',
82
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
83
+ // Text
84
+ txt: 'text/plain',
85
+ csv: 'text/csv',
86
+ json: 'application/json',
87
+ xml: 'application/xml',
88
+ html: 'text/html',
89
+ css: 'text/css',
90
+ js: 'application/javascript',
91
+ ts: 'text/typescript',
92
+ // Media
93
+ mp3: 'audio/mpeg',
94
+ wav: 'audio/wav',
95
+ ogg: 'audio/ogg',
96
+ mp4: 'video/mp4',
97
+ webm: 'video/webm',
98
+ mov: 'video/quicktime',
99
+ // Archives
100
+ zip: 'application/zip',
101
+ tar: 'application/x-tar',
102
+ gz: 'application/gzip',
103
+ };
104
+ return mimeTypes[ext] || 'application/octet-stream';
105
+ }
106
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAC3C,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,IAAI,IAAI,GAAG,KAAK,CAAA;IAEhB,OAAO,IAAI,IAAI,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,IAAI,IAAI,IAAI,CAAA;QACZ,SAAS,EAAE,CAAA;IACb,CAAC;IAED,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,CAA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xC,SAAS;QACT,GAAG,EAAE,YAAY;QACjB,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,WAAW;QAChB,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,eAAe;QACpB,YAAY;QACZ,GAAG,EAAE,iBAAiB;QACtB,GAAG,EAAE,oBAAoB;QACzB,IAAI,EAAE,yEAAyE;QAC/E,GAAG,EAAE,0BAA0B;QAC/B,IAAI,EAAE,mEAAmE;QACzE,GAAG,EAAE,+BAA+B;QACpC,IAAI,EAAE,2EAA2E;QACjF,OAAO;QACP,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,UAAU;QACf,IAAI,EAAE,kBAAkB;QACxB,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,WAAW;QACjB,GAAG,EAAE,UAAU;QACf,EAAE,EAAE,wBAAwB;QAC5B,EAAE,EAAE,iBAAiB;QACrB,QAAQ;QACR,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,WAAW;QAChB,IAAI,EAAE,YAAY;QAClB,GAAG,EAAE,iBAAiB;QACtB,WAAW;QACX,GAAG,EAAE,iBAAiB;QACtB,GAAG,EAAE,mBAAmB;QACxB,EAAE,EAAE,kBAAkB;KACvB,CAAA;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,0BAA0B,CAAA;AACrD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@molecule/app-filesystem",
3
+ "version": "1.0.0",
4
+ "description": "Device filesystem access interface for molecule.dev",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "filesystem",
25
+ "files",
26
+ "storage",
27
+ "native"
28
+ ],
29
+ "license": "Apache-2.0",
30
+ "peerDependencies": {
31
+ "@molecule/app-bond": "^1.0.0",
32
+ "@molecule/app-i18n": "^1.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@molecule/app-bond": "1.0.0",
36
+ "@types/node": "26.1.2",
37
+ "typescript": "6.0.3",
38
+ "vitest": "4.1.10"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/molecule-dev/molecule.git",
43
+ "directory": "packages/app/native/filesystem"
44
+ },
45
+ "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/native/filesystem",
46
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }