@poe-platform/safe-fs 0.1.729 → 0.1.731
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 +9 -1
- package/dist/safe-fs/contracts/filesystem.d.ts +8 -0
- package/dist/safe-fs/core.d.ts +1 -1
- package/dist/safe-fs/core.js +1 -1
- package/dist/safe-fs/fs/capabilities.js +4 -2
- package/dist/safe-fs/fs/memory/index.d.ts +7 -4
- package/dist/safe-fs/fs/memory/index.js +641 -111
- package/dist/safe-fs/fs/memory/ledger.d.ts +3 -2
- package/dist/safe-fs/fs/memory/ledger.js +11 -1
- package/dist/safe-fs/fs/mount/index.js +1 -1
- package/dist/safe-fs/fs/real/index.js +28 -9
- package/dist/safe-fs/fs/scoped.d.ts +1 -0
- package/dist/safe-fs/fs/scoped.js +34 -3
- package/dist/safe-fs/node/native-seek-unavailable.d.ts +1 -0
- package/dist/safe-fs/node/native-seek-unavailable.js +5 -0
- package/dist/safe-fs/platform/browser.d.ts +8 -0
- package/dist/safe-fs/platform/browser.js +1 -0
- package/dist/safe-fs/platform/node.d.ts +8 -0
- package/dist/safe-fs/platform/node.js +1 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -25,6 +25,14 @@ console.log(await fs.readFile("note.txt", "utf8"));
|
|
|
25
25
|
|
|
26
26
|
Output: `hello`, then `hello world`. Nothing touches the host filesystem. Raw adapters exchange `Uint8Array` values; the Node bridge adds strings, encodings, `Buffer` results, and stat predicates. Its `cwd` is the relative-path base and, by default, the confinement boundary. Set an explicit `root` to use a different boundary, for example `{ cwd: "/work", root: "/" }` to address a complete provider namespace. The bridge supports `unlink` when the provider offers atomic file removal; unsupported methods fail without host fallback. `createHostFileSystem()` provides trusted, unrestricted native host access when a rooted adapter is not desired.
|
|
27
27
|
|
|
28
|
+
Under the `workerd` export condition, `@poe-platform/safe-fs/fs/real` reads the
|
|
29
|
+
native request-local filesystem, including retained `/tmp` file bytes.
|
|
30
|
+
The restricted profile refuses generic descriptors, permission/timestamp
|
|
31
|
+
changes, exact creation modes, and owned staging; it promises neither atomic
|
|
32
|
+
rename nor inode/version identity from placeholder native metadata. Retained
|
|
33
|
+
reads remain available, with native seek reporting `ENOTSUP`. Ordinary browser
|
|
34
|
+
bundles cannot import this backend. Node keeps its POSIX host profile.
|
|
35
|
+
|
|
28
36
|
For host storage, use `await createRealFileSystem({ root: "/absolute/existing/directory" })` instead. The root must already exist; virtual `/` maps to that directory. ZIP creation and updates can use this adapter's private owned staging in an isolated host tree. Unzip extraction requires atomic ancestry verification, currently supported by MemoryFileSystem; the real adapter and mount views refuse it. Its `trustedOwnedStaging` capability checks original entries before publication and cleanup, and preserves foreign staging children. It does not advertise atomic conditional mutations: keep external writers and other in-flight writes away from the tree during these operations. Read the safety boundary below before exposing it to untrusted code.
|
|
29
37
|
|
|
30
38
|
To create new outputs with Safe Bash's `dos2unix`, `unix2dos`, or compression commands, host adapters need atomic no-replace publication. Supply `createRealFileSystem({ root, renameNoReplace })` only when that callback binds a qualified native primitive such as Linux `renameat2` with `RENAME_NOREPLACE`. It receives resolved absolute host paths and an optional signal in its third argument. Existing destinations must reject `EEXIST` atomically; existence checks followed by rename and copy/delete are insufficient. Without this binding the adapter explicitly refuses those operations. See the [no-replace contract](src/contracts/filesystem.md#atomic-no-replace-rename).
|
|
@@ -108,7 +116,7 @@ See the [staging contract](src/contracts/filesystem.md#atomic-owned-staging).
|
|
|
108
116
|
| Backend or wrapper | Use it for |
|
|
109
117
|
| --- | --- |
|
|
110
118
|
| `createMemoryFileSystem()` | Isolated, nonpersistent storage with links, permissions, timestamps, and streams; each path resolution admits at most 65,536 cumulative UTF-16 code units across the input and followed symlink targets, rejecting excess with `ENAMETOOLONG` before component allocation |
|
|
111
|
-
| `createRealFileSystem({ root })` | An existing host directory, with virtual paths rooted inside it; Node
|
|
119
|
+
| `createRealFileSystem({ root })` | An existing host directory, with virtual paths rooted inside it; Node or qualified Workerd operations |
|
|
112
120
|
| `new S3FileSystem({ transport, bucket, … })` | Bucket/prefix storage through an explicitly supplied transport; Node only |
|
|
113
121
|
| `new WebDavFileSystem({ baseUrl, fetch, … })` | A WebDAV namespace through an explicitly supplied Fetch implementation |
|
|
114
122
|
| `createReadOnlyFileSystem(filesystem)` | Rejecting writes through one view of an existing filesystem |
|
|
@@ -78,6 +78,7 @@ export interface FileSystemCapabilities {
|
|
|
78
78
|
readonly atomicFileStaging?: boolean;
|
|
79
79
|
/** Creates a cleanup handle bound to owned staging entries, independent of ancestor paths. */
|
|
80
80
|
readonly retainedStagingCleanup?: boolean;
|
|
81
|
+
readonly retainedStagingWrite?: boolean;
|
|
81
82
|
/** Atomically verifies every supplied root-to-parent directory identity at publication. */
|
|
82
83
|
readonly atomicStagingAncestry?: boolean;
|
|
83
84
|
/** Prepares directory guards that validate without yielding or mutating state. */
|
|
@@ -249,6 +250,13 @@ export interface FileStaging {
|
|
|
249
250
|
readonly directory: FileStagingEntry;
|
|
250
251
|
readonly file: FileStagingEntry;
|
|
251
252
|
readonly cleanup?: FileStagingCleanup;
|
|
253
|
+
/** Available for retained regular-file staging on qualified backends. Writes
|
|
254
|
+
* append to the owned entry; finish seals it and returns its publication stat.
|
|
255
|
+
* Cleanup owns the lifetime and checks the last successfully written revision. */
|
|
256
|
+
readonly writer?: {
|
|
257
|
+
write(bytes: Uint8Array, options?: FsOptions): Promise<void>;
|
|
258
|
+
finish(options?: FsOptions): Promise<FileStat>;
|
|
259
|
+
};
|
|
252
260
|
}
|
|
253
261
|
export type StagedFileContent = {
|
|
254
262
|
readonly type: "file";
|
package/dist/safe-fs/core.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export * from "./fs/mount/index.js";
|
|
|
12
12
|
export * from "./fs/overlay/index.js";
|
|
13
13
|
export * from "./fs/quota/index.js";
|
|
14
14
|
export * from "./fs/object-publication/index.js";
|
|
15
|
-
export { scopeFileSystem, retainFileSystemCleanup } from "./fs/scoped.js";
|
|
15
|
+
export { retargetScopedFileSystem, scopeFileSystem, retainFileSystemCleanup } from "./fs/scoped.js";
|
|
16
16
|
export type { RetainedFileSystemCleanupView, RetainedFileSystemCleanupOptions } from "./fs/scoped.js";
|
|
17
17
|
export * from "./fs/webdav/index.js";
|
|
18
18
|
export * from "./bridge/index.js";
|
package/dist/safe-fs/core.js
CHANGED
|
@@ -11,7 +11,7 @@ export * from "./fs/mount/index.js";
|
|
|
11
11
|
export * from "./fs/overlay/index.js";
|
|
12
12
|
export * from "./fs/quota/index.js";
|
|
13
13
|
export * from "./fs/object-publication/index.js";
|
|
14
|
-
export { scopeFileSystem, retainFileSystemCleanup } from "./fs/scoped.js";
|
|
14
|
+
export { retargetScopedFileSystem, scopeFileSystem, retainFileSystemCleanup } from "./fs/scoped.js";
|
|
15
15
|
export * from "./fs/webdav/index.js";
|
|
16
16
|
export * from "./bridge/index.js";
|
|
17
17
|
export * from "./python/index.js";
|
|
@@ -105,7 +105,7 @@ export function readOnlyCapabilities(capabilities) {
|
|
|
105
105
|
"symlinks", "streamingRead", "open", "retainedRead", "versionedDescriptors",
|
|
106
106
|
].filter(name => capabilities[name] !== undefined).map(name => [name, capabilities[name]]));
|
|
107
107
|
return Object.freeze({
|
|
108
|
-
...inspection, retainedStagingCleanup: false, readOnly: true, write: false, append: false, exclusiveCreate: false,
|
|
108
|
+
...inspection, retainedStagingCleanup: false, retainedStagingWrite: false, readOnly: true, write: false, append: false, exclusiveCreate: false,
|
|
109
109
|
synchronousStagingResolution: false,
|
|
110
110
|
mkdir: false, recursiveMkdir: false, remove: false, removeDirectory: false, recursiveRemove: false,
|
|
111
111
|
rename: false, copy: false, exclusiveCopy: false, truncate: false, streamingAppend: false,
|
|
@@ -118,7 +118,7 @@ export function quotaCapabilities(capabilities) {
|
|
|
118
118
|
const streamingWrite = requireCapabilities(capabilities.write, capabilities.append, !capabilities.readOnly);
|
|
119
119
|
const streamingAppend = requireCapabilities(capabilities.append, !capabilities.readOnly);
|
|
120
120
|
const { streamingWrite: ignoredWrite, streamingAppend: ignoredAppend, ...rest } = capabilities;
|
|
121
|
-
return Object.freeze({ ...rest, synchronousStagingResolution: false, retainedStagingCleanup: false, atomicStagingAncestry: false, synchronousDirectoryValidation: false, guardedStagingPublication: false, atomicFilePublication: false, descriptorWriteStream: false, atomicResize: false, atomicFileMutation: false, atomicEntryRemoval: false, atomicEntryRemovalReceipt: false, atomicFileStaging: false, atomicDirectoryMetadata: false, trustedOwnedStaging: false,
|
|
121
|
+
return Object.freeze({ ...rest, synchronousStagingResolution: false, retainedStagingCleanup: false, retainedStagingWrite: false, atomicStagingAncestry: false, synchronousDirectoryValidation: false, guardedStagingPublication: false, atomicFilePublication: false, descriptorWriteStream: false, atomicResize: false, atomicFileMutation: false, atomicEntryRemoval: false, atomicEntryRemovalReceipt: false, atomicFileStaging: false, atomicDirectoryMetadata: false, trustedOwnedStaging: false,
|
|
122
122
|
...(streamingWrite === undefined ? {} : { streamingWrite }),
|
|
123
123
|
...(streamingAppend === undefined ? {} : { streamingAppend }),
|
|
124
124
|
});
|
|
@@ -143,6 +143,8 @@ export function ownedMutationCapabilities(filesystem, capabilities = filesystem.
|
|
|
143
143
|
(unavailable ??= {}).atomicFileStaging = false;
|
|
144
144
|
if (capabilities.retainedStagingCleanup === true && (capabilities.atomicFileStaging !== true || unavailable?.atomicFileStaging === false))
|
|
145
145
|
(unavailable ??= {}).retainedStagingCleanup = false;
|
|
146
|
+
if (capabilities.retainedStagingWrite === true && (capabilities.retainedStagingCleanup !== true || unavailable?.retainedStagingCleanup === false))
|
|
147
|
+
(unavailable ??= {}).retainedStagingWrite = false;
|
|
146
148
|
if (capabilities.atomicStagingAncestry === true && (capabilities.atomicFileStaging !== true || unavailable?.atomicFileStaging === false))
|
|
147
149
|
(unavailable ??= {}).atomicStagingAncestry = false;
|
|
148
150
|
if (capabilities.synchronousDirectoryValidation === true && typeof filesystem.prepareDirectoryAncestry !== "function")
|
|
@@ -69,6 +69,7 @@ export declare class MemoryFileSystem implements FileSystem {
|
|
|
69
69
|
private openWrite;
|
|
70
70
|
private writeData;
|
|
71
71
|
private writeAt;
|
|
72
|
+
private writeAtRange;
|
|
72
73
|
writeMemoryFileFast(path: string, data: Uint8Array, append: boolean, mode: number): void;
|
|
73
74
|
writeMemoryFileInDirFast(dirPrefix: string, name: string, data: Uint8Array, append: boolean, mode: number): void;
|
|
74
75
|
readFile(path: string, options?: ReadFileOptions): Promise<Uint8Array>;
|
|
@@ -118,13 +119,15 @@ export declare class MemoryFileSystem implements FileSystem {
|
|
|
118
119
|
}
|
|
119
120
|
export declare function createMemoryFileSystem(options?: MemoryFileSystemOptions | Readonly<Record<string, unknown>>): MemoryFileSystem;
|
|
120
121
|
export declare class MemoryRedirectHandle {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
fs: MemoryFileSystem;
|
|
123
|
+
path: string;
|
|
124
|
+
node: FileNode;
|
|
125
|
+
append: boolean;
|
|
125
126
|
position: number;
|
|
126
127
|
closed: boolean;
|
|
127
128
|
constructor(fs: MemoryFileSystem, path: string, node: FileNode, append: boolean);
|
|
129
|
+
reset(fs: MemoryFileSystem, path: string, node: FileNode, append: boolean): void;
|
|
130
|
+
writeRangeSync(src: Uint8Array, len: number, signal?: AbortSignal): void;
|
|
128
131
|
writeSync(chunk: Uint8Array, signal?: AbortSignal): void;
|
|
129
132
|
close(): void;
|
|
130
133
|
}
|