@poe-platform/safe-fs 0.1.727 → 0.1.729
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 +15 -8
- package/dist/safe-fs/contracts/errors.js +8 -1
- package/dist/safe-fs/contracts/filesystem.d.ts +68 -2
- package/dist/safe-fs/contracts/io.js +210 -28
- package/dist/safe-fs/contracts/virtual-path.d.ts +3 -1
- package/dist/safe-fs/contracts/virtual-path.js +20 -1
- package/dist/safe-fs/core.d.ts +1 -0
- package/dist/safe-fs/core.js +1 -0
- package/dist/safe-fs/fs/capabilities.d.ts +1 -1
- package/dist/safe-fs/fs/capabilities.js +59 -21
- package/dist/safe-fs/fs/conditional-chmod.d.ts +7 -0
- package/dist/safe-fs/fs/conditional-chmod.js +19 -0
- package/dist/safe-fs/fs/descriptor.js +51 -25
- package/dist/safe-fs/fs/devices/index.d.ts +7 -2
- package/dist/safe-fs/fs/devices/index.js +210 -29
- package/dist/safe-fs/fs/devices/path.d.ts +3 -1
- package/dist/safe-fs/fs/devices/path.js +70 -12
- package/dist/safe-fs/fs/memory/index.d.ts +70 -48
- package/dist/safe-fs/fs/memory/index.js +1595 -244
- package/dist/safe-fs/fs/memory/ledger.d.ts +8 -1
- package/dist/safe-fs/fs/memory/ledger.js +46 -6
- package/dist/safe-fs/fs/memory/missing-target.js +21 -1
- package/dist/safe-fs/fs/mount/index.d.ts +11 -3
- package/dist/safe-fs/fs/mount/index.js +326 -15
- package/dist/safe-fs/fs/object-publication/index.js +79 -3
- package/dist/safe-fs/fs/overlay/index.d.ts +2 -2
- package/dist/safe-fs/fs/overlay/index.js +27 -5
- package/dist/safe-fs/fs/overlay/memory-publication.d.ts +2 -1
- package/dist/safe-fs/fs/overlay/memory-publication.js +39 -2
- package/dist/safe-fs/fs/quota/index.js +5 -5
- package/dist/safe-fs/fs/readonly/index.d.ts +1 -0
- package/dist/safe-fs/fs/readonly/index.js +13 -0
- package/dist/safe-fs/fs/real/index.d.ts +6 -2
- package/dist/safe-fs/fs/real/index.js +78 -8
- package/dist/safe-fs/fs/s3/filesystem.d.ts +3 -0
- package/dist/safe-fs/fs/s3/filesystem.js +57 -25
- package/dist/safe-fs/fs/s3/http/transport.js +20 -3
- package/dist/safe-fs/fs/s3/mock.js +19 -2
- package/dist/safe-fs/fs/s3/namespace.js +8 -2
- package/dist/safe-fs/fs/s3/registry.js +2 -0
- package/dist/safe-fs/fs/scoped.d.ts +1 -0
- package/dist/safe-fs/fs/scoped.js +261 -74
- package/dist/safe-fs/fs/staging-ancestry.d.ts +8 -0
- package/dist/safe-fs/fs/staging-ancestry.js +115 -0
- package/dist/safe-fs/fs/staging-cleanup.d.ts +5 -0
- package/dist/safe-fs/fs/staging-cleanup.js +63 -0
- package/dist/safe-fs/fs/webdav/webdav.js +7 -5
- package/dist/safe-fs/platform/browser.d.ts +5 -0
- package/dist/safe-fs/platform/browser.js +17 -0
- package/dist/safe-fs/platform/node.d.ts +5 -0
- package/dist/safe-fs/platform/node.js +28 -0
- package/dist/safe-fs/platform/transport-budget.d.ts +7 -0
- package/dist/safe-fs/platform/transport-budget.js +4 -0
- package/dist/safe-fs/testing/object-io-metrics.d.ts +3 -0
- package/dist/safe-fs/testing/object-io-metrics.js +29 -0
- package/dist/safe-fs/testing/object-publication.d.ts +3 -1
- package/dist/safe-fs/testing/object-publication.js +2 -2
- package/package.json +1 -1
|
@@ -3,18 +3,25 @@ export declare class MemoryLedger {
|
|
|
3
3
|
readonly limits: Readonly<MemoryFileSystemLimits>;
|
|
4
4
|
private retainedBytes;
|
|
5
5
|
private metadataUnits;
|
|
6
|
+
readonly maxFileBytesSmi: number;
|
|
7
|
+
readonly maxRetainedBytesSmi: number;
|
|
8
|
+
readonly maxMetadataUnitsSmi: number;
|
|
9
|
+
readonly hasInfiniteRetained: boolean;
|
|
6
10
|
constructor(limits: Readonly<MemoryFileSystemLimits>);
|
|
7
11
|
get availableBytes(): number;
|
|
12
|
+
canPreallocate64(nameBytes: number): boolean;
|
|
8
13
|
fileSize(length: number, syscall: string, path: string): void;
|
|
9
14
|
check(bytes: number, units: number, syscall: string, path: string): void;
|
|
10
15
|
reserve(bytes: number, units: number, syscall: string, path: string): void;
|
|
11
16
|
release(bytes: number, units: number): void;
|
|
12
17
|
}
|
|
13
18
|
export declare class MemoryAllocation {
|
|
19
|
+
private references;
|
|
14
20
|
readonly data: Uint8Array;
|
|
15
21
|
private readonly ledger;
|
|
16
|
-
private references;
|
|
17
22
|
constructor(data: Uint8Array, ledger: MemoryLedger);
|
|
18
23
|
retain(): void;
|
|
19
24
|
release(): void;
|
|
25
|
+
isReleased64(): boolean;
|
|
26
|
+
reuse(): void;
|
|
20
27
|
}
|
|
@@ -1,26 +1,59 @@
|
|
|
1
1
|
import { FsError } from "../../contracts/errors.js";
|
|
2
|
+
const MAX_SMI = 1073741823;
|
|
2
3
|
export class MemoryLedger {
|
|
3
4
|
limits;
|
|
4
5
|
retainedBytes = 0;
|
|
5
6
|
metadataUnits = 0;
|
|
7
|
+
maxFileBytesSmi;
|
|
8
|
+
maxRetainedBytesSmi;
|
|
9
|
+
maxMetadataUnitsSmi;
|
|
10
|
+
hasInfiniteRetained;
|
|
6
11
|
constructor(limits) {
|
|
7
12
|
this.limits = limits;
|
|
13
|
+
this.maxFileBytesSmi = limits.maxFileBytes >= MAX_SMI ? MAX_SMI : (limits.maxFileBytes | 0);
|
|
14
|
+
this.maxRetainedBytesSmi = limits.maxRetainedBytes >= MAX_SMI ? MAX_SMI : (limits.maxRetainedBytes | 0);
|
|
15
|
+
this.maxMetadataUnitsSmi = limits.maxMetadataUnits >= MAX_SMI ? MAX_SMI : (limits.maxMetadataUnits | 0);
|
|
16
|
+
this.hasInfiniteRetained = limits.maxRetainedBytes === Infinity;
|
|
8
17
|
}
|
|
9
18
|
get availableBytes() {
|
|
10
|
-
|
|
19
|
+
const max = this.limits.maxRetainedBytes;
|
|
20
|
+
return max === Infinity ? Infinity : max - this.retainedBytes;
|
|
21
|
+
}
|
|
22
|
+
canPreallocate64(nameBytes) {
|
|
23
|
+
return this.maxFileBytesSmi >= 64 && (this.hasInfiniteRetained || this.maxRetainedBytesSmi - this.retainedBytes > 65536 + nameBytes);
|
|
11
24
|
}
|
|
12
25
|
fileSize(length, syscall, path) {
|
|
26
|
+
if ((length | 0) === length && length >= 0 && length <= this.maxFileBytesSmi)
|
|
27
|
+
return;
|
|
13
28
|
if (!Number.isSafeInteger(length) || length < 0 || length > this.limits.maxFileBytes) {
|
|
14
29
|
throw new FsError("EFBIG", { syscall, path });
|
|
15
30
|
}
|
|
16
31
|
}
|
|
17
32
|
check(bytes, units, syscall, path) {
|
|
18
|
-
if (
|
|
19
|
-
|
|
33
|
+
if ((bytes | 0) === bytes && bytes >= 0 &&
|
|
34
|
+
(units | 0) === units && units >= 0 &&
|
|
35
|
+
this.retainedBytes <= this.maxRetainedBytesSmi - bytes &&
|
|
36
|
+
this.metadataUnits <= this.maxMetadataUnitsSmi - units) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const maxRetained = this.limits.maxRetainedBytes;
|
|
40
|
+
const maxUnits = this.limits.maxMetadataUnits;
|
|
41
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0 ||
|
|
42
|
+
(maxRetained !== Infinity && bytes > maxRetained - this.retainedBytes) ||
|
|
43
|
+
!Number.isSafeInteger(units) || units < 0 ||
|
|
44
|
+
(maxUnits !== Infinity && units > maxUnits - this.metadataUnits)) {
|
|
20
45
|
throw new FsError("ENOSPC", { syscall, path });
|
|
21
46
|
}
|
|
22
47
|
}
|
|
23
48
|
reserve(bytes, units, syscall, path) {
|
|
49
|
+
if ((bytes | 0) === bytes && bytes >= 0 &&
|
|
50
|
+
(units | 0) === units && units >= 0 &&
|
|
51
|
+
this.retainedBytes <= this.maxRetainedBytesSmi - bytes &&
|
|
52
|
+
this.metadataUnits <= this.maxMetadataUnitsSmi - units) {
|
|
53
|
+
this.retainedBytes = (this.retainedBytes + bytes) | 0;
|
|
54
|
+
this.metadataUnits = (this.metadataUnits + units) | 0;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
24
57
|
this.check(bytes, units, syscall, path);
|
|
25
58
|
this.retainedBytes += bytes;
|
|
26
59
|
this.metadataUnits += units;
|
|
@@ -34,9 +67,6 @@ export class MemoryLedger {
|
|
|
34
67
|
}
|
|
35
68
|
}
|
|
36
69
|
export class MemoryAllocation {
|
|
37
|
-
data;
|
|
38
|
-
ledger;
|
|
39
|
-
references = 1;
|
|
40
70
|
constructor(data, ledger) {
|
|
41
71
|
this.data = data;
|
|
42
72
|
this.ledger = ledger;
|
|
@@ -50,4 +80,14 @@ export class MemoryAllocation {
|
|
|
50
80
|
if (--this.references === 0)
|
|
51
81
|
this.ledger.release(this.data.byteLength, 0);
|
|
52
82
|
}
|
|
83
|
+
isReleased64() {
|
|
84
|
+
return this.references === 0 && this.data.byteLength === 64;
|
|
85
|
+
}
|
|
86
|
+
reuse() {
|
|
87
|
+
this.references = 1;
|
|
88
|
+
this.data.fill(0);
|
|
89
|
+
}
|
|
53
90
|
}
|
|
91
|
+
Object.assign(MemoryAllocation.prototype, {
|
|
92
|
+
references: 1,
|
|
93
|
+
});
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { FsError } from "../../contracts/errors.js";
|
|
2
|
+
function utf8ByteLength(value) {
|
|
3
|
+
let bytes = 0;
|
|
4
|
+
for (let i = 0; i < value.length; i++) {
|
|
5
|
+
const code = value.charCodeAt(i);
|
|
6
|
+
if (code < 0x80)
|
|
7
|
+
bytes += 1;
|
|
8
|
+
else if (code < 0x800)
|
|
9
|
+
bytes += 2;
|
|
10
|
+
else if (code >= 0xd800 && code <= 0xdbff && i + 1 < value.length && value.charCodeAt(i + 1) >= 0xdc00 && value.charCodeAt(i + 1) <= 0xdfff) {
|
|
11
|
+
bytes += 4;
|
|
12
|
+
i++;
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
bytes += 3;
|
|
16
|
+
}
|
|
17
|
+
return bytes;
|
|
18
|
+
}
|
|
19
|
+
function exceedsComponentByteLimit(value) {
|
|
20
|
+
return value.length > 85 && (value.length > 255 || utf8ByteLength(value) > 255);
|
|
21
|
+
}
|
|
2
22
|
function components(path, signal) {
|
|
3
23
|
const result = [];
|
|
4
24
|
let start = 0;
|
|
@@ -56,7 +76,7 @@ export function resolveMissingTarget(root, path, signal) {
|
|
|
56
76
|
first = false;
|
|
57
77
|
continue;
|
|
58
78
|
}
|
|
59
|
-
if (
|
|
79
|
+
if (exceedsComponentByteLimit(name))
|
|
60
80
|
return fail("ENAMETOOLONG");
|
|
61
81
|
const node = current.entries.get(name);
|
|
62
82
|
if (!node) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AppendFileOptions, CapabilityQueryOptions, CopyFileOptions, DirectoryEntry, FileReadHandle, FileResizeHandle, FileResizeOperation, FileResizeOptions, FileStat, FileSystem, OpenReadFileOptions, OpenResizeFileOptions, FileSystemCapabilities, FsOptions, RenameOptions, MkdirOptions, ReadDirectoryOptions, ReadFileOptions, ReadStreamOptions, RemoveOptions, WriteFileOptions, ConditionalFilePublicationOptions, ConditionalWriteFileOptions, ConditionalRemoveFileOptions, ConditionalRemoveEntryOptions, CreateStagedFileOptions, FileStaging, PublishStagedFileOptions, PrepareDirectoryOptions, StagedFileContent } from "../../contracts/filesystem.js";
|
|
1
|
+
import type { AppendFileOptions, CapabilityQueryOptions, CopyFileOptions, DirectoryEntry, FileReadHandle, FileResizeHandle, FileResizeOperation, FileResizeOptions, FileStat, FileSystem, OpenReadFileOptions, OpenResizeFileOptions, FileSystemCapabilities, FsOptions, ChmodOptions, RenameOptions, MkdirOptions, ReadDirectoryOptions, ReadFileOptions, ReadStreamOptions, RemoveOptions, WriteFileOptions, ConditionalFilePublicationOptions, 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
3
|
import type { FileDescriptor, OpenFileOptions } from "../../contracts/descriptor.js";
|
|
4
4
|
export interface MountFileSystemOptions {
|
|
@@ -14,6 +14,11 @@ export declare class MountFileSystem implements FileSystem {
|
|
|
14
14
|
constructor(options: MountFileSystemOptions);
|
|
15
15
|
private select;
|
|
16
16
|
capabilitiesFor(path: string, options?: CapabilityQueryOptions): Promise<FileSystemCapabilities>;
|
|
17
|
+
private supportsStagingAncestry;
|
|
18
|
+
private supportsDirectoryValidation;
|
|
19
|
+
prepareDirectoryAncestry(ancestors: readonly FileStagingEntry[], options?: FsOptions): Promise<() => true>;
|
|
20
|
+
prepareStagingResolution(path: string, options?: FsOptions): Promise<FileStagingResolution>;
|
|
21
|
+
private prepareAncestry;
|
|
17
22
|
private protected;
|
|
18
23
|
openReadFile(path: string, options?: OpenReadFileOptions): Promise<FileReadHandle>;
|
|
19
24
|
resizeFile(path: string, operation: FileResizeOperation, options?: FileResizeOptions): Promise<void>;
|
|
@@ -41,7 +46,10 @@ export declare class MountFileSystem implements FileSystem {
|
|
|
41
46
|
private localStaging;
|
|
42
47
|
publishFileConditional(path: string, source: ByteSource, options: ConditionalFilePublicationOptions): Promise<FileStat>;
|
|
43
48
|
writeFileConditional(path: string, data: Uint8Array, options: ConditionalWriteFileOptions): Promise<FileStat>;
|
|
44
|
-
removeEntryConditional(path: string, options: ConditionalRemoveEntryOptions
|
|
49
|
+
removeEntryConditional(path: string, options: ConditionalRemoveEntryOptions & {
|
|
50
|
+
readonly returnRemainingStat?: false | undefined;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
removeEntryConditional(path: string, options: ConditionalRemoveEntryReceiptOptions): Promise<void | FileStat>;
|
|
45
53
|
removeFileConditional(path: string, options: ConditionalRemoveFileOptions): Promise<void>;
|
|
46
54
|
removeTreeConditional(path: string, options: ConditionalRemoveEntryOptions): Promise<void>;
|
|
47
55
|
createStagedFile(path: string, name: string, content: StagedFileContent, options: CreateStagedFileOptions): Promise<FileStaging>;
|
|
@@ -56,7 +64,7 @@ export declare class MountFileSystem implements FileSystem {
|
|
|
56
64
|
readlink(path: string, options?: FsOptions): Promise<string>;
|
|
57
65
|
symlink(target: string, path: string, options?: FsOptions): Promise<void>;
|
|
58
66
|
link(existingPath: string, newPath: string, options?: FsOptions): Promise<void>;
|
|
59
|
-
chmod(path: string, mode: number, options?:
|
|
67
|
+
chmod(path: string, mode: number, options?: ChmodOptions): Promise<void>;
|
|
60
68
|
utimes(path: string, atimeMs: number, mtimeMs: number, options?: FsOptions): Promise<void>;
|
|
61
69
|
truncate(path: string, length?: number, options?: FsOptions): Promise<void>;
|
|
62
70
|
readStream(path: string, options?: ReadStreamOptions): ByteSource;
|