@zenfs/core 0.15.1 → 0.16.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/dist/backends/fetch.js +3 -0
- package/dist/backends/port/fs.d.ts +1 -1
- package/dist/backends/port/fs.js +2 -10
- package/dist/backends/port/rpc.d.ts +18 -14
- package/dist/backends/port/rpc.js +3 -2
- package/dist/backends/store/fs.d.ts +1 -1
- package/dist/backends/store/fs.js +11 -12
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +3 -3
- package/dist/emulation/promises.d.ts +1 -1
- package/dist/emulation/promises.js +3 -3
- package/dist/emulation/sync.js +2 -2
- package/dist/stats.d.ts +2 -5
- package/dist/stats.js +2 -25
- package/package.json +2 -2
- package/src/backends/fetch.ts +5 -0
- package/src/backends/port/fs.ts +13 -14
- package/src/backends/port/rpc.ts +21 -16
- package/src/backends/store/fs.ts +12 -12
- package/src/emulation/promises.ts +3 -3
- package/src/emulation/sync.ts +1 -1
- package/src/stats.ts +4 -21
package/dist/backends/fetch.js
CHANGED
|
@@ -7,7 +7,7 @@ import { File } from '../../file.js';
|
|
|
7
7
|
import { FileSystem, type FileSystemMetadata } from '../../filesystem.js';
|
|
8
8
|
import { Stats, type FileType } from '../../stats.js';
|
|
9
9
|
import * as RPC from './rpc.js';
|
|
10
|
-
type FileMethods = ExtractProperties<File, (...args: any[]) => Promise<any
|
|
10
|
+
type FileMethods = Omit<ExtractProperties<File, (...args: any[]) => Promise<any>>, typeof Symbol.asyncDispose>;
|
|
11
11
|
type FileMethod = keyof FileMethods;
|
|
12
12
|
export declare class PortFile extends File {
|
|
13
13
|
readonly fs: PortFS;
|
package/dist/backends/port/fs.js
CHANGED
|
@@ -195,18 +195,10 @@ async function handleRequest(port, fs, request) {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
catch (e) {
|
|
198
|
-
value = e;
|
|
198
|
+
value = e instanceof ErrnoError ? e.toJSON() : e.toString();
|
|
199
199
|
error = true;
|
|
200
200
|
}
|
|
201
|
-
port.postMessage({
|
|
202
|
-
_zenfs: true,
|
|
203
|
-
scope,
|
|
204
|
-
id,
|
|
205
|
-
error,
|
|
206
|
-
method,
|
|
207
|
-
stack,
|
|
208
|
-
value: value instanceof ErrnoError ? value.toJSON() : value,
|
|
209
|
-
});
|
|
201
|
+
port.postMessage({ _zenfs: true, scope, id, error, method, stack, value });
|
|
210
202
|
}
|
|
211
203
|
export function attachFS(port, fs) {
|
|
212
204
|
RPC.attach(port, request => handleRequest(port, fs, request));
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
|
|
3
|
-
import type { TransferListItem } from 'worker_threads';
|
|
2
|
+
import { type ErrnoErrorJSON } from '../../error.js';
|
|
4
3
|
import { type PortFS } from './fs.js';
|
|
5
4
|
type _MessageEvent<T = any> = T | {
|
|
6
5
|
data: T;
|
|
7
6
|
};
|
|
8
7
|
export interface Port {
|
|
9
|
-
postMessage(value: unknown
|
|
8
|
+
postMessage(value: unknown): void;
|
|
10
9
|
on?(event: 'message', listener: (value: unknown) => void): this;
|
|
11
10
|
off?(event: 'message', listener: (value: unknown) => void): this;
|
|
12
|
-
addEventListener?(type: 'message', listener: (
|
|
13
|
-
removeEventListener?(type: 'message', listener: (
|
|
11
|
+
addEventListener?(type: 'message', listener: (ev: _MessageEvent) => void): void;
|
|
12
|
+
removeEventListener?(type: 'message', listener: (ev: _MessageEvent) => void): void;
|
|
14
13
|
}
|
|
15
14
|
export interface Options {
|
|
16
15
|
/**
|
|
@@ -25,27 +24,32 @@ export interface Options {
|
|
|
25
24
|
/**
|
|
26
25
|
* An RPC message
|
|
27
26
|
*/
|
|
28
|
-
export interface Message
|
|
27
|
+
export interface Message {
|
|
29
28
|
_zenfs: true;
|
|
30
|
-
scope:
|
|
29
|
+
scope: 'fs' | 'file';
|
|
31
30
|
id: string;
|
|
32
|
-
method:
|
|
31
|
+
method: string;
|
|
33
32
|
stack: string;
|
|
34
33
|
}
|
|
35
|
-
export interface Request
|
|
36
|
-
args:
|
|
34
|
+
export interface Request extends Message {
|
|
35
|
+
args: unknown[];
|
|
36
|
+
}
|
|
37
|
+
interface _ResponseWithError extends Message {
|
|
38
|
+
error: true;
|
|
39
|
+
value: ErrnoErrorJSON | string;
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
error:
|
|
40
|
-
value: Awaited<
|
|
41
|
+
interface _ResponseWithValue<T> extends Message {
|
|
42
|
+
error: false;
|
|
43
|
+
value: Awaited<T> extends File ? FileData : Awaited<T>;
|
|
41
44
|
}
|
|
45
|
+
export type Response<T = unknown> = _ResponseWithError | _ResponseWithValue<T>;
|
|
42
46
|
export interface FileData {
|
|
43
47
|
fd: number;
|
|
44
48
|
path: string;
|
|
45
49
|
position: number;
|
|
46
50
|
}
|
|
47
51
|
export { FileData as File };
|
|
48
|
-
export declare function isMessage(arg: unknown): arg is Message
|
|
52
|
+
export declare function isMessage(arg: unknown): arg is Message;
|
|
49
53
|
type _Executor = Parameters<ConstructorParameters<typeof Promise<any>>[0]>;
|
|
50
54
|
export interface Executor {
|
|
51
55
|
resolve: _Executor[0];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { Errno, ErrnoError } from '../../error.js';
|
|
2
3
|
import { PortFile } from './fs.js';
|
|
3
4
|
function isFileData(value) {
|
|
4
5
|
return typeof value == 'object' && value != null && 'fd' in value && 'path' in value && 'position' in value;
|
|
@@ -38,7 +39,7 @@ export function handleResponse(response) {
|
|
|
38
39
|
}
|
|
39
40
|
const { resolve, reject, fs } = executors.get(id);
|
|
40
41
|
if (error) {
|
|
41
|
-
const e = ErrnoError.fromJSON(value);
|
|
42
|
+
const e = typeof value == 'string' ? new Error(value) : ErrnoError.fromJSON(value);
|
|
42
43
|
e.stack += stack;
|
|
43
44
|
reject(e);
|
|
44
45
|
executors.delete(id);
|
|
@@ -2,7 +2,7 @@ import type { Cred } from '../../cred.js';
|
|
|
2
2
|
import { PreloadFile } from '../../file.js';
|
|
3
3
|
import { FileSystem, type FileSystemMetadata } from '../../filesystem.js';
|
|
4
4
|
import { type Ino, Inode } from '../../inode.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { FileType, Stats } from '../../stats.js';
|
|
6
6
|
import type { Store, Transaction } from './store.js';
|
|
7
7
|
/**
|
|
8
8
|
* A file system which uses a key-value store.
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { R_OK, S_IFDIR, S_IFREG, W_OK } from '../../emulation/constants.js';
|
|
2
|
+
import { basename, dirname, join, resolve } from '../../emulation/path.js';
|
|
3
|
+
import { Errno, ErrnoError } from '../../error.js';
|
|
4
4
|
import { PreloadFile, flagToMode } from '../../file.js';
|
|
5
5
|
import { FileSystem } from '../../filesystem.js';
|
|
6
|
-
import { Inode,
|
|
7
|
-
import {
|
|
8
|
-
import { encodeDirListing, encode, decodeDirListing } from '../../utils.js';
|
|
6
|
+
import { Inode, randomIno, rootIno } from '../../inode.js';
|
|
7
|
+
import { decodeDirListing, encode, encodeDirListing } from '../../utils.js';
|
|
9
8
|
const maxInodeAllocTries = 5;
|
|
10
9
|
/**
|
|
11
10
|
* A file system which uses a key-value store.
|
|
@@ -199,11 +198,11 @@ export class StoreFS extends FileSystem {
|
|
|
199
198
|
}
|
|
200
199
|
async createFile(path, flag, mode, cred) {
|
|
201
200
|
const data = new Uint8Array(0);
|
|
202
|
-
const file = await this.commitNew(this.store.transaction(), path,
|
|
201
|
+
const file = await this.commitNew(this.store.transaction(), path, S_IFREG, mode, cred, data);
|
|
203
202
|
return new PreloadFile(this, path, flag, file.toStats(), data);
|
|
204
203
|
}
|
|
205
204
|
createFileSync(path, flag, mode, cred) {
|
|
206
|
-
this.commitNewSync(path,
|
|
205
|
+
this.commitNewSync(path, S_IFREG, mode, cred);
|
|
207
206
|
return this.openFileSync(path, flag, cred);
|
|
208
207
|
}
|
|
209
208
|
async openFile(path, flag, cred) {
|
|
@@ -251,10 +250,10 @@ export class StoreFS extends FileSystem {
|
|
|
251
250
|
}
|
|
252
251
|
async mkdir(path, mode, cred) {
|
|
253
252
|
const tx = this.store.transaction(), data = encode('{}');
|
|
254
|
-
await this.commitNew(tx, path,
|
|
253
|
+
await this.commitNew(tx, path, S_IFDIR, mode, cred, data);
|
|
255
254
|
}
|
|
256
255
|
mkdirSync(path, mode, cred) {
|
|
257
|
-
this.commitNewSync(path,
|
|
256
|
+
this.commitNewSync(path, S_IFDIR, mode, cred, encode('{}'));
|
|
258
257
|
}
|
|
259
258
|
async readdir(path, cred) {
|
|
260
259
|
const tx = this.store.transaction();
|
|
@@ -378,7 +377,7 @@ export class StoreFS extends FileSystem {
|
|
|
378
377
|
}
|
|
379
378
|
// Create new inode. o777, owned by root:root
|
|
380
379
|
const inode = new Inode();
|
|
381
|
-
inode.mode = 0o777 |
|
|
380
|
+
inode.mode = 0o777 | S_IFDIR;
|
|
382
381
|
// If the root doesn't exist, the first random ID shouldn't exist either.
|
|
383
382
|
await tx.set(inode.ino, encode('{}'));
|
|
384
383
|
await tx.set(rootIno, inode.data);
|
|
@@ -394,7 +393,7 @@ export class StoreFS extends FileSystem {
|
|
|
394
393
|
}
|
|
395
394
|
// Create new inode, mode o777, owned by root:root
|
|
396
395
|
const inode = new Inode();
|
|
397
|
-
inode.mode = 0o777 |
|
|
396
|
+
inode.mode = 0o777 | S_IFDIR;
|
|
398
397
|
// If the root doesn't exist, the first random ID shouldn't exist either.
|
|
399
398
|
tx.setSync(inode.ino, encode('{}'));
|
|
400
399
|
tx.setSync(rootIno, inode.data);
|