@catmint-fs/core 0.0.0-prealpha.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 +339 -0
- package/README.md +146 -0
- package/dist/index.d.ts +297 -0
- package/dist/index.js +1835 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
interface FsAdapter {
|
|
2
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
3
|
+
createReadStream(path: string): ReadableStream<Uint8Array>;
|
|
4
|
+
readdir(path: string): Promise<DirentEntry[]>;
|
|
5
|
+
stat(path: string): Promise<StatResult>;
|
|
6
|
+
lstat(path: string): Promise<StatResult>;
|
|
7
|
+
readlink(path: string): Promise<string>;
|
|
8
|
+
exists(path: string): Promise<boolean>;
|
|
9
|
+
writeFile(path: string, data: Uint8Array, options?: WriteOptions): Promise<void>;
|
|
10
|
+
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
11
|
+
rm(path: string, options?: RmOptions): Promise<void>;
|
|
12
|
+
rmdir(path: string): Promise<void>;
|
|
13
|
+
rename(from: string, to: string): Promise<void>;
|
|
14
|
+
symlink(target: string, path: string): Promise<void>;
|
|
15
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
16
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
17
|
+
lchown(path: string, uid: number, gid: number): Promise<void>;
|
|
18
|
+
checkPermission(path: string, op: PermissionOp): Promise<void>;
|
|
19
|
+
initialize?(root: string): Promise<void>;
|
|
20
|
+
capabilities(): AdapterCapabilities;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface WriteOptions {
|
|
24
|
+
mode?: number;
|
|
25
|
+
uid?: number;
|
|
26
|
+
gid?: number;
|
|
27
|
+
}
|
|
28
|
+
interface MkdirOptions {
|
|
29
|
+
recursive?: boolean;
|
|
30
|
+
mode?: number;
|
|
31
|
+
uid?: number;
|
|
32
|
+
gid?: number;
|
|
33
|
+
}
|
|
34
|
+
interface RmOptions {
|
|
35
|
+
recursive?: boolean;
|
|
36
|
+
force?: boolean;
|
|
37
|
+
}
|
|
38
|
+
type PermissionOp = "read" | "write" | "execute";
|
|
39
|
+
interface DirentEntry {
|
|
40
|
+
name: string;
|
|
41
|
+
isFile(): boolean;
|
|
42
|
+
isDirectory(): boolean;
|
|
43
|
+
isSymbolicLink(): boolean;
|
|
44
|
+
}
|
|
45
|
+
interface StatResult {
|
|
46
|
+
mode: number;
|
|
47
|
+
uid: number;
|
|
48
|
+
gid: number;
|
|
49
|
+
size: number;
|
|
50
|
+
atimeMs: number;
|
|
51
|
+
mtimeMs: number;
|
|
52
|
+
ctimeMs: number;
|
|
53
|
+
birthtimeMs: number;
|
|
54
|
+
isFile(): boolean;
|
|
55
|
+
isDirectory(): boolean;
|
|
56
|
+
isSymbolicLink(): boolean;
|
|
57
|
+
}
|
|
58
|
+
type EntryType = "file" | "directory" | "symlink";
|
|
59
|
+
type ChangeEntry = {
|
|
60
|
+
type: "create";
|
|
61
|
+
entryType: "file" | "directory";
|
|
62
|
+
path: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: "update";
|
|
65
|
+
path: string;
|
|
66
|
+
} | {
|
|
67
|
+
type: "delete";
|
|
68
|
+
entryType: EntryType;
|
|
69
|
+
path: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: "rename";
|
|
72
|
+
from: string;
|
|
73
|
+
to: string;
|
|
74
|
+
} | {
|
|
75
|
+
type: "chmod";
|
|
76
|
+
path: string;
|
|
77
|
+
mode: number;
|
|
78
|
+
} | {
|
|
79
|
+
type: "chown";
|
|
80
|
+
path: string;
|
|
81
|
+
uid: number;
|
|
82
|
+
gid: number;
|
|
83
|
+
} | {
|
|
84
|
+
type: "symlink";
|
|
85
|
+
path: string;
|
|
86
|
+
target: string;
|
|
87
|
+
};
|
|
88
|
+
type ChangeDetail = {
|
|
89
|
+
type: "create";
|
|
90
|
+
entryType: "file";
|
|
91
|
+
path: string;
|
|
92
|
+
content: Uint8Array;
|
|
93
|
+
mode: number;
|
|
94
|
+
uid: number;
|
|
95
|
+
gid: number;
|
|
96
|
+
} | {
|
|
97
|
+
type: "create";
|
|
98
|
+
entryType: "directory";
|
|
99
|
+
path: string;
|
|
100
|
+
mode: number;
|
|
101
|
+
uid: number;
|
|
102
|
+
gid: number;
|
|
103
|
+
} | {
|
|
104
|
+
type: "update";
|
|
105
|
+
path: string;
|
|
106
|
+
content: Uint8Array;
|
|
107
|
+
mode: number;
|
|
108
|
+
uid: number;
|
|
109
|
+
gid: number;
|
|
110
|
+
} | {
|
|
111
|
+
type: "delete";
|
|
112
|
+
entryType: EntryType;
|
|
113
|
+
path: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: "rename";
|
|
116
|
+
from: string;
|
|
117
|
+
to: string;
|
|
118
|
+
} | {
|
|
119
|
+
type: "chmod";
|
|
120
|
+
path: string;
|
|
121
|
+
mode: number;
|
|
122
|
+
} | {
|
|
123
|
+
type: "chown";
|
|
124
|
+
path: string;
|
|
125
|
+
uid: number;
|
|
126
|
+
gid: number;
|
|
127
|
+
} | {
|
|
128
|
+
type: "symlink";
|
|
129
|
+
path: string;
|
|
130
|
+
target: string;
|
|
131
|
+
};
|
|
132
|
+
interface ApplyError {
|
|
133
|
+
change: ChangeEntry;
|
|
134
|
+
error: Error;
|
|
135
|
+
}
|
|
136
|
+
interface ApplyResult {
|
|
137
|
+
applied: number;
|
|
138
|
+
errors: ApplyError[];
|
|
139
|
+
}
|
|
140
|
+
declare class TransactionError extends Error {
|
|
141
|
+
readonly rootCause: ChangeEntry;
|
|
142
|
+
readonly sourceError: Error;
|
|
143
|
+
readonly rollbackErrors: Array<{
|
|
144
|
+
change: ChangeEntry;
|
|
145
|
+
error: Error;
|
|
146
|
+
}>;
|
|
147
|
+
constructor(message: string, rootCause: ChangeEntry, sourceError: Error, rollbackErrors: Array<{
|
|
148
|
+
change: ChangeEntry;
|
|
149
|
+
error: Error;
|
|
150
|
+
}>);
|
|
151
|
+
}
|
|
152
|
+
interface AdapterCapabilities {
|
|
153
|
+
permissions: boolean;
|
|
154
|
+
symlinks: boolean;
|
|
155
|
+
caseSensitive: boolean;
|
|
156
|
+
}
|
|
157
|
+
interface ApplyOptions {
|
|
158
|
+
transaction?: boolean;
|
|
159
|
+
}
|
|
160
|
+
interface CreateLayerOptions {
|
|
161
|
+
root: string;
|
|
162
|
+
adapter?: FsAdapter;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type FsErrorCode = "ENOENT" | "EACCES" | "EPERM" | "EEXIST" | "ENOTDIR" | "EISDIR" | "ELOOP" | "EINVAL" | "ENOTEMPTY" | "DISPOSED" | "ENOSYS" | "TRANSACTION_FAILED";
|
|
166
|
+
declare class FsError extends Error {
|
|
167
|
+
readonly code: FsErrorCode;
|
|
168
|
+
constructor(code: FsErrorCode, message: string);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare class Layer {
|
|
172
|
+
private adapter;
|
|
173
|
+
private ledger;
|
|
174
|
+
private capabilities;
|
|
175
|
+
private root;
|
|
176
|
+
private disposed;
|
|
177
|
+
constructor(root: string, adapter: FsAdapter, capabilities: AdapterCapabilities);
|
|
178
|
+
private assertNotDisposed;
|
|
179
|
+
/**
|
|
180
|
+
* Enforce ENOSYS for operations that require symlink support.
|
|
181
|
+
*/
|
|
182
|
+
private assertSymlinksSupported;
|
|
183
|
+
private resolvePath;
|
|
184
|
+
/**
|
|
185
|
+
* Follow symlinks to resolve the final path. Used by operations that
|
|
186
|
+
* follow symlinks (readFile, stat, writeFile, chmod, chown, exists).
|
|
187
|
+
*/
|
|
188
|
+
private resolveSymlinks;
|
|
189
|
+
private resolveRelativeTarget;
|
|
190
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
191
|
+
createReadStream(path: string): ReadableStream<Uint8Array>;
|
|
192
|
+
readdir(path: string): Promise<DirentEntry[]>;
|
|
193
|
+
private getChangePath;
|
|
194
|
+
stat(path: string): Promise<StatResult>;
|
|
195
|
+
lstat(path: string): Promise<StatResult>;
|
|
196
|
+
private statResolved;
|
|
197
|
+
readlink(path: string): Promise<string>;
|
|
198
|
+
exists(path: string): Promise<boolean>;
|
|
199
|
+
writeFile(path: string, data: string | Uint8Array, options?: WriteOptions): Promise<void>;
|
|
200
|
+
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
201
|
+
rm(path: string, options?: RmOptions): Promise<void>;
|
|
202
|
+
rmdir(path: string): Promise<void>;
|
|
203
|
+
rename(from: string, to: string): Promise<void>;
|
|
204
|
+
symlink(target: string, path: string): Promise<void>;
|
|
205
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
206
|
+
chown(path: string, uid: number, gid: number): Promise<void>;
|
|
207
|
+
lchown(path: string, uid: number, gid: number): Promise<void>;
|
|
208
|
+
getOwner(path: string): Promise<{
|
|
209
|
+
uid: number;
|
|
210
|
+
gid: number;
|
|
211
|
+
}>;
|
|
212
|
+
getChanges(): ChangeEntry[];
|
|
213
|
+
getChangeDetail(path: string): Promise<ChangeDetail | null>;
|
|
214
|
+
apply(options?: ApplyOptions): Promise<ApplyResult>;
|
|
215
|
+
private applyBestEffort;
|
|
216
|
+
private applyTransaction;
|
|
217
|
+
/**
|
|
218
|
+
* Convert a flat ChangeDetail back to a ChangeEntry for error reporting.
|
|
219
|
+
*/
|
|
220
|
+
private detailToChangeEntry;
|
|
221
|
+
/**
|
|
222
|
+
* Get the primary path from a ChangeDetail.
|
|
223
|
+
*/
|
|
224
|
+
private getDetailPath;
|
|
225
|
+
private rollbackOne;
|
|
226
|
+
private applyOne;
|
|
227
|
+
dispose(): void;
|
|
228
|
+
reset(): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare class Ledger {
|
|
232
|
+
private records;
|
|
233
|
+
private chmodChownPairs;
|
|
234
|
+
private nextOrder;
|
|
235
|
+
private caseSensitive;
|
|
236
|
+
constructor(caseSensitive?: boolean);
|
|
237
|
+
private normalizePath;
|
|
238
|
+
has(path: string): boolean;
|
|
239
|
+
get(path: string): ChangeEntry | undefined;
|
|
240
|
+
getDetail(path: string): ChangeDetail | null;
|
|
241
|
+
private recordToDetail;
|
|
242
|
+
getAll(): ChangeEntry[];
|
|
243
|
+
getAllDetails(): ChangeDetail[];
|
|
244
|
+
recordCreate(path: string, entryType: "file" | "directory", content?: Uint8Array, mode?: number, uid?: number, gid?: number): void;
|
|
245
|
+
recordUpdate(path: string, content?: Uint8Array, mode?: number, uid?: number, gid?: number): void;
|
|
246
|
+
recordDelete(path: string, entryType?: EntryType): void;
|
|
247
|
+
recordRename(from: string, to: string): void;
|
|
248
|
+
recordChmod(path: string, mode: number): void;
|
|
249
|
+
recordChown(path: string, uid: number, gid: number): void;
|
|
250
|
+
recordSymlink(path: string, target: string): void;
|
|
251
|
+
/**
|
|
252
|
+
* Returns the virtual mode for a path if it has been chmod'd (or created
|
|
253
|
+
* with a mode) in this ledger.
|
|
254
|
+
*/
|
|
255
|
+
getVirtualMode(path: string): number | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* Returns virtual ownership for a path if it has been chown'd (or created
|
|
258
|
+
* with ownership) in this ledger.
|
|
259
|
+
*/
|
|
260
|
+
getVirtualOwnership(path: string): {
|
|
261
|
+
uid: number;
|
|
262
|
+
gid: number;
|
|
263
|
+
} | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* Returns the content stored for a path, if any.
|
|
266
|
+
*/
|
|
267
|
+
getContent(path: string): Uint8Array | undefined;
|
|
268
|
+
clear(): void;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
declare class LocalAdapter implements FsAdapter {
|
|
272
|
+
private _capabilities;
|
|
273
|
+
initialize(root: string): Promise<void>;
|
|
274
|
+
capabilities(): AdapterCapabilities;
|
|
275
|
+
readFile(filePath: string): Promise<Uint8Array>;
|
|
276
|
+
createReadStream(filePath: string): ReadableStream<Uint8Array>;
|
|
277
|
+
readdir(dirPath: string): Promise<DirentEntry[]>;
|
|
278
|
+
stat(filePath: string): Promise<StatResult>;
|
|
279
|
+
lstat(filePath: string): Promise<StatResult>;
|
|
280
|
+
readlink(filePath: string): Promise<string>;
|
|
281
|
+
exists(filePath: string): Promise<boolean>;
|
|
282
|
+
writeFile(filePath: string, data: Uint8Array, options?: WriteOptions): Promise<void>;
|
|
283
|
+
mkdir(dirPath: string, options?: MkdirOptions): Promise<void>;
|
|
284
|
+
rm(filePath: string, options?: RmOptions): Promise<void>;
|
|
285
|
+
rmdir(dirPath: string): Promise<void>;
|
|
286
|
+
rename(from: string, to: string): Promise<void>;
|
|
287
|
+
symlink(target: string, linkPath: string): Promise<void>;
|
|
288
|
+
chmod(filePath: string, mode: number): Promise<void>;
|
|
289
|
+
chown(filePath: string, uid: number, gid: number): Promise<void>;
|
|
290
|
+
lchown(filePath: string, uid: number, gid: number): Promise<void>;
|
|
291
|
+
checkPermission(filePath: string, op: PermissionOp): Promise<void>;
|
|
292
|
+
private mapError;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
declare function createLayer(options: CreateLayerOptions): Promise<Layer>;
|
|
296
|
+
|
|
297
|
+
export { type AdapterCapabilities, type ApplyError, type ApplyOptions, type ApplyResult, type ChangeDetail, type ChangeEntry, type CreateLayerOptions, type DirentEntry, type EntryType, type FsAdapter, FsError, type FsErrorCode, Layer, Ledger, LocalAdapter, type MkdirOptions, type PermissionOp, type RmOptions, type StatResult, TransactionError, type WriteOptions, createLayer };
|