@zenfs/core 0.16.0 → 0.16.1
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/backends/port/fs.d.ts +22 -0
- package/dist/backends/port/fs.js +12 -1
- package/dist/backends/port/rpc.d.ts +2 -0
- package/dist/backends/port/rpc.js +13 -1
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +1 -2
- package/package.json +7 -1
- package/src/backends/port/fs.ts +18 -3
- package/src/backends/port/readme.md +7 -12
- package/src/backends/port/rpc.ts +16 -1
- package/src/config.ts +1 -1
|
@@ -6,9 +6,17 @@ import type { Cred } from '../../cred.js';
|
|
|
6
6
|
import { File } from '../../file.js';
|
|
7
7
|
import { FileSystem, type FileSystemMetadata } from '../../filesystem.js';
|
|
8
8
|
import { Stats, type FileType } from '../../stats.js';
|
|
9
|
+
import type { Backend, FilesystemOf } from '../backend.js';
|
|
9
10
|
import * as RPC from './rpc.js';
|
|
11
|
+
import { type MountConfiguration } from '../../config.js';
|
|
10
12
|
type FileMethods = Omit<ExtractProperties<File, (...args: any[]) => Promise<any>>, typeof Symbol.asyncDispose>;
|
|
11
13
|
type FileMethod = keyof FileMethods;
|
|
14
|
+
interface FileRequest<TMethod extends FileMethod = FileMethod> extends RPC.Request {
|
|
15
|
+
fd: number;
|
|
16
|
+
scope: 'file';
|
|
17
|
+
method: TMethod;
|
|
18
|
+
args: Parameters<FileMethods[TMethod]>;
|
|
19
|
+
}
|
|
12
20
|
export declare class PortFile extends File {
|
|
13
21
|
readonly fs: PortFS;
|
|
14
22
|
readonly fd: number;
|
|
@@ -40,6 +48,11 @@ export declare class PortFile extends File {
|
|
|
40
48
|
}
|
|
41
49
|
type FSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<any> | FileSystemMetadata>;
|
|
42
50
|
type FSMethod = keyof FSMethods;
|
|
51
|
+
interface FSRequest<TMethod extends FSMethod = FSMethod> extends RPC.Request {
|
|
52
|
+
scope: 'fs';
|
|
53
|
+
method: TMethod;
|
|
54
|
+
args: Parameters<FSMethods[TMethod]>;
|
|
55
|
+
}
|
|
43
56
|
declare const PortFS_base: import("../../filesystem.js").Mixin<typeof FileSystem, {
|
|
44
57
|
_sync?: FileSystem | undefined;
|
|
45
58
|
queueDone(): Promise<void>;
|
|
@@ -88,6 +101,14 @@ export declare class PortFS extends PortFS_base {
|
|
|
88
101
|
exists(path: string, cred: Cred): Promise<boolean>;
|
|
89
102
|
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
|
|
90
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export type FileOrFSRequest = FSRequest | FileRequest;
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
export declare function handleRequest(port: RPC.Port, fs: FileSystem, request: FileOrFSRequest): Promise<void>;
|
|
91
112
|
export declare function attachFS(port: RPC.Port, fs: FileSystem): void;
|
|
92
113
|
export declare function detachFS(port: RPC.Port, fs: FileSystem): void;
|
|
93
114
|
export declare const Port: {
|
|
@@ -108,4 +129,5 @@ export declare const Port: {
|
|
|
108
129
|
isAvailable(): Promise<boolean>;
|
|
109
130
|
create(options: RPC.Options): PortFS;
|
|
110
131
|
};
|
|
132
|
+
export declare function resolveRemoteMount<T extends Backend>(port: RPC.Port, config: MountConfiguration<T>, _depth?: number): Promise<FilesystemOf<T>>;
|
|
111
133
|
export {};
|
package/dist/backends/port/fs.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Async, FileSystem } from '../../filesystem.js';
|
|
|
4
4
|
import { Stats } from '../../stats.js';
|
|
5
5
|
import { InMemory } from '../memory.js';
|
|
6
6
|
import * as RPC from './rpc.js';
|
|
7
|
+
import { resolveMountConfig } from '../../config.js';
|
|
7
8
|
export class PortFile extends File {
|
|
8
9
|
constructor(fs, fd, path, position) {
|
|
9
10
|
super();
|
|
@@ -159,7 +160,10 @@ export class PortFS extends Async(FileSystem) {
|
|
|
159
160
|
}
|
|
160
161
|
let nextFd = 0;
|
|
161
162
|
const descriptors = new Map();
|
|
162
|
-
|
|
163
|
+
/**
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
export async function handleRequest(port, fs, request) {
|
|
163
167
|
if (!RPC.isMessage(request)) {
|
|
164
168
|
return;
|
|
165
169
|
}
|
|
@@ -233,3 +237,10 @@ export const Port = {
|
|
|
233
237
|
return new PortFS(options);
|
|
234
238
|
},
|
|
235
239
|
};
|
|
240
|
+
export async function resolveRemoteMount(port, config, _depth = 0) {
|
|
241
|
+
const stopAndReplay = RPC.catchMessages(port);
|
|
242
|
+
const fs = await resolveMountConfig(config, _depth);
|
|
243
|
+
attachFS(port, fs);
|
|
244
|
+
stopAndReplay(fs);
|
|
245
|
+
return fs;
|
|
246
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { type ErrnoErrorJSON } from '../../error.js';
|
|
3
|
+
import type { Backend, FilesystemOf } from '../backend.js';
|
|
3
4
|
import { type PortFS } from './fs.js';
|
|
4
5
|
type _MessageEvent<T = any> = T | {
|
|
5
6
|
data: T;
|
|
@@ -62,3 +63,4 @@ export declare function request<const TRequest extends Request, TValue>(request:
|
|
|
62
63
|
export declare function handleResponse<const TResponse extends Response>(response: TResponse): void;
|
|
63
64
|
export declare function attach<T extends Message>(port: Port, handler: (message: T) => unknown): void;
|
|
64
65
|
export declare function detach<T extends Message>(port: Port, handler: (message: T) => unknown): void;
|
|
66
|
+
export declare function catchMessages<T extends Backend>(port: Port): (fs: FilesystemOf<T>) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { Errno, ErrnoError } from '../../error.js';
|
|
3
|
-
import { PortFile } from './fs.js';
|
|
3
|
+
import { handleRequest, PortFile } from './fs.js';
|
|
4
4
|
function isFileData(value) {
|
|
5
5
|
return typeof value == 'object' && value != null && 'fd' in value && 'path' in value && 'position' in value;
|
|
6
6
|
}
|
|
@@ -72,3 +72,15 @@ export function detach(port, handler) {
|
|
|
72
72
|
handler('data' in message ? message.data : message);
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
export function catchMessages(port) {
|
|
76
|
+
const events = [];
|
|
77
|
+
const handler = events.push.bind(events);
|
|
78
|
+
attach(port, handler);
|
|
79
|
+
return function (fs) {
|
|
80
|
+
detach(port, handler);
|
|
81
|
+
for (const event of events) {
|
|
82
|
+
const request = 'data' in event ? event.data : event;
|
|
83
|
+
handleRequest(port, fs, request);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|