@auto-engineer/file-store 0.1.1 → 0.1.3

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.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +6 -11
  3. package/.turbo/turbo-type-check.log +1 -1
  4. package/CHANGELOG.md +12 -0
  5. package/dist/src/{LightningFileStore.d.ts → InMemoryFileStore.d.ts} +6 -10
  6. package/dist/src/InMemoryFileStore.d.ts.map +1 -0
  7. package/dist/src/InMemoryFileStore.js +60 -0
  8. package/dist/src/InMemoryFileStore.js.map +1 -0
  9. package/dist/src/index.d.ts +0 -2
  10. package/dist/src/index.d.ts.map +1 -1
  11. package/dist/src/index.js +0 -2
  12. package/dist/src/index.js.map +1 -1
  13. package/dist/src/path.d.ts +0 -2
  14. package/dist/src/path.d.ts.map +1 -1
  15. package/dist/src/path.js +0 -13
  16. package/dist/src/path.js.map +1 -1
  17. package/dist/src/types.d.ts +0 -7
  18. package/dist/src/types.d.ts.map +1 -1
  19. package/dist/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +2 -30
  21. package/src/InMemoryFileStore.ts +68 -0
  22. package/src/index.ts +0 -2
  23. package/src/path.ts +0 -14
  24. package/src/types.ts +0 -9
  25. package/tsconfig.json +1 -1
  26. package/dist/src/FileWatcher.d.ts +0 -20
  27. package/dist/src/FileWatcher.d.ts.map +0 -1
  28. package/dist/src/FileWatcher.js +0 -70
  29. package/dist/src/FileWatcher.js.map +0 -1
  30. package/dist/src/LightningFileStore.d.ts.map +0 -1
  31. package/dist/src/LightningFileStore.js +0 -105
  32. package/dist/src/LightningFileStore.js.map +0 -1
  33. package/dist/src/LightningFileStore.specs.d.ts +0 -2
  34. package/dist/src/LightningFileStore.specs.d.ts.map +0 -1
  35. package/dist/src/LightningFileStore.specs.js +0 -86
  36. package/dist/src/LightningFileStore.specs.js.map +0 -1
  37. package/dist/src/text-helpers.d.ts +0 -7
  38. package/dist/src/text-helpers.d.ts.map +0 -1
  39. package/dist/src/text-helpers.js +0 -9
  40. package/dist/src/text-helpers.js.map +0 -1
  41. package/src/FileWatcher.ts +0 -73
  42. package/src/LightningFileStore.specs.ts +0 -109
  43. package/src/LightningFileStore.ts +0 -126
  44. package/src/text-helpers.ts +0 -16
@@ -1,126 +0,0 @@
1
- import LightningFS from '@isomorphic-git/lightning-fs';
2
- import type { IFileStore } from './types';
3
- import { dirname } from './path';
4
-
5
- interface LightningFSStats {
6
- isDirectory(): boolean;
7
- size: number;
8
- }
9
-
10
- interface LightningFSPromises {
11
- writeFile(path: string, data: Uint8Array): Promise<void>;
12
- readFile(path: string): Promise<Uint8Array>;
13
- stat(path: string): Promise<LightningFSStats>;
14
- readdir(path: string): Promise<string[]>;
15
- mkdir(path: string): Promise<void>;
16
- unlink(path: string): Promise<void>;
17
- rmdir(path: string): Promise<void>;
18
- }
19
-
20
- interface LightningFSInstance {
21
- promises: LightningFSPromises;
22
- }
23
-
24
- export class LightningFileStore implements IFileStore {
25
- private fs: LightningFSInstance;
26
- private pfs: LightningFSPromises;
27
-
28
- constructor(name = 'pocfs') {
29
- this.fs = new LightningFS(name) as LightningFSInstance;
30
- this.pfs = this.fs.promises;
31
- }
32
-
33
- async write(path: string, data: Uint8Array): Promise<void> {
34
- await this.mkdirp(dirname(path));
35
- await this.pfs.writeFile(path, data);
36
- }
37
-
38
- async read(path: string): Promise<Uint8Array | null> {
39
- try {
40
- return await this.pfs.readFile(path);
41
- } catch {
42
- return null;
43
- }
44
- }
45
-
46
- async exists(path: string): Promise<boolean> {
47
- return await this.pfs
48
- .stat(path)
49
- .then(() => true)
50
- .catch(() => false);
51
- }
52
-
53
- async listTree(root: string = '/'): Promise<Array<{ path: string; type: 'file' | 'dir'; size: number }>> {
54
- const out: Array<{ path: string; type: 'file' | 'dir'; size: number }> = [];
55
- const walk = async (p: string) => {
56
- let st: LightningFSStats | null = null;
57
- try {
58
- st = await this.pfs.stat(p);
59
- } catch {
60
- return;
61
- }
62
-
63
- if (st !== null && st.isDirectory()) {
64
- out.push({ path: p, type: 'dir', size: 0 });
65
- let entries: string[] = [];
66
- try {
67
- entries = await this.pfs.readdir(p);
68
- } catch {
69
- /* ignore */
70
- }
71
- for (const name of entries) {
72
- const child = p === '/' ? `/${name}` : `${p}/${name}`;
73
- await walk(child);
74
- }
75
- } else {
76
- out.push({ path: p, type: 'file', size: st?.size ?? 0 });
77
- }
78
- };
79
- await walk(root);
80
- out.sort((a, b) => (a.type === b.type ? a.path.localeCompare(b.path) : a.type === 'dir' ? -1 : 1));
81
- return out;
82
- }
83
-
84
- async remove(path: string): Promise<void> {
85
- if (!path) return;
86
- try {
87
- const st = await this.pfs.stat(path);
88
- if (st.isDirectory()) {
89
- await this.removeDirectory(path);
90
- } else {
91
- await this.pfs.unlink(path);
92
- }
93
- } catch (err: unknown) {
94
- if (this.isFileNotFoundError(err)) return;
95
- throw err;
96
- }
97
- }
98
-
99
- private async removeDirectory(path: string): Promise<void> {
100
- const entries = await this.pfs.readdir(path).catch(() => []);
101
- for (const name of entries) {
102
- const child = path === '/' ? `/${name}` : `${path}/${name}`;
103
- await this.remove(child);
104
- }
105
- await this.pfs.rmdir(path);
106
- }
107
-
108
- private isFileNotFoundError(err: unknown): boolean {
109
- if (err instanceof Error && 'code' in err && err.code === 'ENOENT') return true;
110
- return err === null || err === undefined;
111
- }
112
-
113
- private async mkdirp(path: string): Promise<void> {
114
- if (!path || path === '/') return;
115
- const parts = path.split('/').filter(Boolean);
116
- let cur = '';
117
- for (const part of parts) {
118
- cur += '/' + part;
119
- const exists = await this.pfs
120
- .stat(cur)
121
- .then(() => true)
122
- .catch(() => false);
123
- if (!exists) await this.pfs.mkdir(cur);
124
- }
125
- }
126
- }
@@ -1,16 +0,0 @@
1
- export async function readText(
2
- fs: { read(path: string): Promise<Uint8Array | null> },
3
- path: string,
4
- ): Promise<string | null> {
5
- const buf = await fs.read(path);
6
- return buf ? new TextDecoder().decode(buf) : null;
7
- }
8
-
9
- export async function writeText(
10
- fs: { write(path: string, data: Uint8Array): Promise<void> },
11
- path: string,
12
- text: string,
13
- ): Promise<void> {
14
- const buf = new TextEncoder().encode(text);
15
- await fs.write(path, buf);
16
- }