@poe-platform/safe-fs 0.1.731 → 0.1.733
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/dist/safe-fs/contracts/virtual-path.d.ts +1 -0
- package/dist/safe-fs/contracts/virtual-path.js +68 -8
- package/dist/safe-fs/fs/devices/index.js +11 -2
- package/dist/safe-fs/fs/memory/index.d.ts +42 -4
- package/dist/safe-fs/fs/memory/index.js +572 -75
- package/dist/safe-fs/fs/memory/ledger.d.ts +2 -0
- package/dist/safe-fs/fs/memory/ledger.js +6 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const MAX_PATH_BYTES = 65536;
|
|
2
2
|
export declare const MAX_PATH_COMPONENTS = 2048;
|
|
3
3
|
export declare function validatePath(path: string, maxComponents?: number): void;
|
|
4
|
+
export declare function resolvePath2(cwd: string, path0: string): string;
|
|
4
5
|
export declare function resolvePath(cwd: string, ...paths: string[]): string;
|
|
5
6
|
export declare function normalizePath(path: string, cwd?: string): string;
|
|
6
7
|
export declare function dirname(path: string): string;
|
|
@@ -23,14 +23,44 @@ export function validatePath(path, maxComponents = MAX_PATH_COMPONENTS) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
function isFastCleanAbsPath(path) {
|
|
27
|
+
const len = path.length;
|
|
28
|
+
if (len === 0 || path.charCodeAt(0) !== 47)
|
|
29
|
+
return false;
|
|
30
|
+
if (len === 1)
|
|
31
|
+
return true;
|
|
32
|
+
if (path.charCodeAt(len - 1) === 47)
|
|
33
|
+
return false;
|
|
34
|
+
let segStart = 1;
|
|
35
|
+
for (let i = 1; i < len; i++) {
|
|
36
|
+
const c = path.charCodeAt(i);
|
|
37
|
+
if (c === 0)
|
|
38
|
+
return false;
|
|
39
|
+
if (c === 47) {
|
|
40
|
+
const segLen = i - segStart;
|
|
41
|
+
if (segLen === 0)
|
|
42
|
+
return false;
|
|
43
|
+
if (segLen === 1 && path.charCodeAt(segStart) === 46)
|
|
44
|
+
return false;
|
|
45
|
+
if (segLen === 2 && path.charCodeAt(segStart) === 46 && path.charCodeAt(segStart + 1) === 46)
|
|
46
|
+
return false;
|
|
47
|
+
segStart = i + 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const lastLen = len - segStart;
|
|
51
|
+
if (lastLen === 1 && path.charCodeAt(segStart) === 46)
|
|
52
|
+
return false;
|
|
53
|
+
if (lastLen === 2 && path.charCodeAt(segStart) === 46 && path.charCodeAt(segStart + 1) === 46)
|
|
54
|
+
return false;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
function resolvePathSlow(cwd, paths) {
|
|
58
|
+
const argLen = paths.length + 1;
|
|
32
59
|
const components = [];
|
|
33
|
-
for (
|
|
60
|
+
for (let a = 0; a < argLen; a++) {
|
|
61
|
+
const path = a === 0 ? cwd : paths[a - 1];
|
|
62
|
+
if (a > 0)
|
|
63
|
+
validatePath(path);
|
|
34
64
|
if (path.startsWith("/"))
|
|
35
65
|
components.length = 0;
|
|
36
66
|
for (const component of path.split("/")) {
|
|
@@ -44,8 +74,38 @@ export function resolvePath(cwd, ...paths) {
|
|
|
44
74
|
}
|
|
45
75
|
return `/${components.join("/")}`;
|
|
46
76
|
}
|
|
77
|
+
export function resolvePath2(cwd, path0) {
|
|
78
|
+
validatePath(cwd);
|
|
79
|
+
if (cwd.charCodeAt(0) !== 47)
|
|
80
|
+
throw new FsError("EINVAL", { syscall: "resolve", path: cwd, message: "cwd must be absolute" });
|
|
81
|
+
validatePath(path0);
|
|
82
|
+
if (isFastCleanAbsPath(path0))
|
|
83
|
+
return path0;
|
|
84
|
+
if (isFastCleanAbsPath(cwd) && path0.length > 0 && path0.charCodeAt(0) !== 47 && !path0.includes("/")) {
|
|
85
|
+
if (path0 === ".")
|
|
86
|
+
return cwd;
|
|
87
|
+
if (path0 !== "..")
|
|
88
|
+
return cwd === "/" ? `/${path0}` : `${cwd}/${path0}`;
|
|
89
|
+
}
|
|
90
|
+
return resolvePathSlow(cwd, [path0]);
|
|
91
|
+
}
|
|
92
|
+
export function resolvePath(cwd, ...paths) {
|
|
93
|
+
validatePath(cwd);
|
|
94
|
+
if (!cwd.startsWith("/"))
|
|
95
|
+
throw new FsError("EINVAL", { syscall: "resolve", path: cwd, message: "cwd must be absolute" });
|
|
96
|
+
const argLen = paths.length + 1;
|
|
97
|
+
if (argLen === 1) {
|
|
98
|
+
if (isFastCleanAbsPath(cwd))
|
|
99
|
+
return cwd;
|
|
100
|
+
return resolvePathSlow(cwd, paths);
|
|
101
|
+
}
|
|
102
|
+
if (argLen === 2) {
|
|
103
|
+
return resolvePath2(cwd, paths[0]);
|
|
104
|
+
}
|
|
105
|
+
return resolvePathSlow(cwd, paths);
|
|
106
|
+
}
|
|
47
107
|
export function normalizePath(path, cwd = "/") {
|
|
48
|
-
return
|
|
108
|
+
return resolvePath2(cwd, path);
|
|
49
109
|
}
|
|
50
110
|
export function dirname(path) {
|
|
51
111
|
if (typeof path !== "string")
|
|
@@ -46,8 +46,17 @@ function globalCapabilities(filesystem) {
|
|
|
46
46
|
let declared = filesystem.capabilities[key];
|
|
47
47
|
if (key === "atomicEntryRemovalReceipt")
|
|
48
48
|
declared = ownedMutationCapabilities(filesystem).atomicEntryRemovalReceipt;
|
|
49
|
-
if (declared === true
|
|
50
|
-
|
|
49
|
+
if (declared === true) {
|
|
50
|
+
const req = optional[key];
|
|
51
|
+
if (req) {
|
|
52
|
+
for (let i = 0; i < req.length; i++) {
|
|
53
|
+
if (typeof filesystem[req[i]] !== "function") {
|
|
54
|
+
declared = false;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
51
60
|
if (key === "retainedResize" && filesystem.capabilities.readOnly === true)
|
|
52
61
|
declared = false;
|
|
53
62
|
if (key === "descriptorWriteStream" && filesystem.capabilities.streamingWrite === false)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AppendFileOptions, CopyFileOptions, DirectoryEntry, EntryComparison, FileReadHandle, FileResizeHandle, FileStat, FileSystem, FileSystemCapabilities, FsOptions, ChmodOptions, RenameOptions, MkdirOptions, ReadDirectoryOptions, ReadFileOptions, ReadStreamOptions, RemoveOptions, FileDescriptor, OpenFileOptions, OpenReadFileOptions, OpenResizeFileOptions, WriteFileOptions, ConditionalWriteFileOptions, ConditionalRemoveFileOptions, ConditionalRemoveEntryOptions, ConditionalRemoveEntryReceiptOptions, CreateStagedFileOptions, FileStaging, FileStagingEntry, FileStagingResolution, PublishStagedFileOptions, PrepareDirectoryOptions, StagedFileContent } from "../../contracts/filesystem.js";
|
|
2
2
|
import type { ByteSource } from "../../contracts/io.js";
|
|
3
|
-
import { MemoryAllocation } from "./ledger.js";
|
|
3
|
+
import { MemoryAllocation, MemoryLedger } from "./ledger.js";
|
|
4
4
|
import { type MemoryFileSystemOptions } from "./limits.js";
|
|
5
5
|
export { defaultMemoryFileSystemLimits, type MemoryFileSystemLimits, type MemoryFileSystemOptions } from "./limits.js";
|
|
6
6
|
interface Metadata {
|
|
@@ -16,11 +16,41 @@ interface Metadata {
|
|
|
16
16
|
}
|
|
17
17
|
interface FileNode extends Metadata {
|
|
18
18
|
type: "file";
|
|
19
|
+
sourceRef?: Uint8Array | undefined;
|
|
19
20
|
byteLength: number;
|
|
20
21
|
view: Uint8Array | undefined;
|
|
21
22
|
data: Uint8Array;
|
|
22
23
|
allocation: MemoryAllocation;
|
|
23
24
|
}
|
|
25
|
+
interface DirectoryNode extends Metadata {
|
|
26
|
+
type: "directory";
|
|
27
|
+
entries: Map<string, MemoryNode>;
|
|
28
|
+
cachedNlink?: number;
|
|
29
|
+
cachedNlinkRev?: number;
|
|
30
|
+
}
|
|
31
|
+
interface SymlinkNode extends Metadata {
|
|
32
|
+
type: "symlink";
|
|
33
|
+
target: string;
|
|
34
|
+
}
|
|
35
|
+
type MemoryNode = FileNode | DirectoryNode | SymlinkNode;
|
|
36
|
+
declare class MemoryCache {
|
|
37
|
+
readonly allocations: MemoryAllocation[];
|
|
38
|
+
readonly files: FileNode[];
|
|
39
|
+
readonly directories: DirectoryNode[];
|
|
40
|
+
readonly removedScratch: MemoryNode[];
|
|
41
|
+
lastFastDirPrefix: string;
|
|
42
|
+
lastFastDirNode: DirectoryNode | undefined;
|
|
43
|
+
lastFastFilePath: string;
|
|
44
|
+
lastFastFileName: string;
|
|
45
|
+
lastFastFileNode: FileNode | undefined;
|
|
46
|
+
clearWrites(): void;
|
|
47
|
+
}
|
|
48
|
+
type OwnedStore = {
|
|
49
|
+
root: DirectoryNode;
|
|
50
|
+
ledger: MemoryLedger;
|
|
51
|
+
capabilities: FileSystem["capabilities"];
|
|
52
|
+
intact: () => boolean;
|
|
53
|
+
};
|
|
24
54
|
export interface ConditionalMutationBinding {
|
|
25
55
|
readonly path: string;
|
|
26
56
|
readonly parent: FileStat;
|
|
@@ -34,6 +64,9 @@ export declare class MemoryFileSystem implements FileSystem {
|
|
|
34
64
|
private readonly identityScope;
|
|
35
65
|
private nextInode;
|
|
36
66
|
private readonly ledger;
|
|
67
|
+
readonly _cache: MemoryCache;
|
|
68
|
+
mutationTick: number;
|
|
69
|
+
readonly _owner: OwnedStore;
|
|
37
70
|
private readonly root;
|
|
38
71
|
private totalBytes;
|
|
39
72
|
symlinkCount: number;
|
|
@@ -71,7 +104,8 @@ export declare class MemoryFileSystem implements FileSystem {
|
|
|
71
104
|
private writeAt;
|
|
72
105
|
private writeAtRange;
|
|
73
106
|
writeMemoryFileFast(path: string, data: Uint8Array, append: boolean, mode: number): void;
|
|
74
|
-
|
|
107
|
+
writeMemoryFilesInDirBatchFast(firstFileName: string, dirPrefix: string, fileNames: readonly string[], nameHashes: Int32Array, payloads: readonly Uint8Array[], totalNameBytes: number, payloadBytesSum: number, mode: number): void;
|
|
108
|
+
writeMemoryFileInDirFast(dirPrefix: string, name: string, data: Uint8Array, append: boolean, mode: number, nameHash?: number): void;
|
|
75
109
|
readFile(path: string, options?: ReadFileOptions): Promise<Uint8Array>;
|
|
76
110
|
private expectEntry;
|
|
77
111
|
private stagingLocations;
|
|
@@ -96,6 +130,8 @@ export declare class MemoryFileSystem implements FileSystem {
|
|
|
96
130
|
stat(path: string, options?: FsOptions): Promise<FileStat>;
|
|
97
131
|
lstat(path: string, options?: FsOptions): Promise<FileStat>;
|
|
98
132
|
readdir(path: string, options?: ReadDirectoryOptions): Promise<DirectoryEntry[]>;
|
|
133
|
+
tryMkdirFastSync(path: string, recursive: boolean, mode: number | undefined): boolean;
|
|
134
|
+
tryRmFastSync(path: string, recursive: boolean, force: boolean): boolean;
|
|
99
135
|
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
100
136
|
rmdir(path: string, options?: FsOptions): Promise<void>;
|
|
101
137
|
rm(path: string, options?: RemoveOptions & Partial<ConditionalMutationBinding>): Promise<void>;
|
|
@@ -128,6 +164,7 @@ export declare class MemoryRedirectHandle {
|
|
|
128
164
|
constructor(fs: MemoryFileSystem, path: string, node: FileNode, append: boolean);
|
|
129
165
|
reset(fs: MemoryFileSystem, path: string, node: FileNode, append: boolean): void;
|
|
130
166
|
writeRangeSync(src: Uint8Array, len: number, signal?: AbortSignal): void;
|
|
167
|
+
writeImmutableSync(immutableData: Uint8Array, signal?: AbortSignal): void;
|
|
131
168
|
writeSync(chunk: Uint8Array, signal?: AbortSignal): void;
|
|
132
169
|
close(): void;
|
|
133
170
|
}
|
|
@@ -135,11 +172,12 @@ export declare function tryOpenMemoryRedirectHandleSync(filesystem: FileSystem,
|
|
|
135
172
|
export declare function utf8ByteLength(value: string): number;
|
|
136
173
|
export declare function isCleanAbsolutePath(path: string): boolean;
|
|
137
174
|
export declare function tryResolveMemoryDevicePath(filesystem: FileSystem, path: string, resizeCreate?: boolean): string | undefined;
|
|
138
|
-
export declare function
|
|
175
|
+
export declare function getLastReadMemoryFileSourceRef(view: Uint8Array): Uint8Array | undefined;
|
|
176
|
+
export declare function tryReadMemoryFileViewSync(filesystem: FileSystem, path: string, maxBytes?: number, signal?: AbortSignal, captureSourceRef?: boolean): Uint8Array | undefined;
|
|
139
177
|
export declare function tryGetMemoryDirectoryEntryNamesSync(filesystem: FileSystem, path: string): ReadonlyMap<string, {
|
|
140
178
|
readonly type: "file" | "directory" | "symlink";
|
|
141
179
|
}> | undefined;
|
|
142
180
|
export declare function tryWriteMemoryFileSync(filesystem: FileSystem, path: string, data: Uint8Array, append: boolean, mode: number, signal?: AbortSignal): boolean;
|
|
143
|
-
export declare function tryMkdirMemorySync(filesystem: FileSystem, path: string, recursive: boolean, mode: number, signal?: AbortSignal): boolean;
|
|
181
|
+
export declare function tryMkdirMemorySync(filesystem: FileSystem, path: string, recursive: boolean, mode: number, signal?: AbortSignal, dirPrefixHint?: string): boolean;
|
|
144
182
|
export declare function tryRmRfMemorySync(filesystem: FileSystem, path: string, signal?: AbortSignal): boolean;
|
|
145
183
|
export declare function tryWriteMemoryFileInDirSync(filesystem: FileSystem, dirPrefix: string, name: string, data: Uint8Array, append: boolean, mode: number, signal?: AbortSignal): boolean;
|