Skip to content

Commit

Permalink
style: 💄 run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 18, 2023
1 parent caf8394 commit f6c417a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 42 deletions.
18 changes: 9 additions & 9 deletions src/fsa-to-node/FsaNodeCore.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {
createError,
isFd,
pathToFilename,
} from '../node/util';
import { pathToLocation} from './util';
import { ERRSTR} from '../node/constants';
import { createError, isFd, pathToFilename } from '../node/util';
import { pathToLocation } from './util';
import { ERRSTR } from '../node/constants';
import { FsaToNodeConstants } from './constants';
import { FsaNodeFsOpenFile } from './FsaNodeFsOpenFile';
import { FLAG } from '../consts/FLAG';
import type * as fsa from '../fsa/types';
import type * as misc from '../node/types/misc';
import type {FsaNodeSyncAdapter} from './types';
import type { FsaNodeSyncAdapter } from './types';

export class FsaNodeCore {
protected static fd: number = 0x7fffffff;
Expand Down Expand Up @@ -94,7 +90,11 @@ export class FsaNodeCore {
return file;
}

protected async getFileById(id: misc.TFileId, funcName?: string, create?: boolean): Promise<fsa.IFileSystemFileHandle> {
protected async getFileById(
id: misc.TFileId,
funcName?: string,
create?: boolean,
): Promise<fsa.IFileSystemFileHandle> {
if (typeof id === 'number') return (await this.getFileByFd(id, funcName)).file;
const filename = pathToFilename(id);
const [folder, name] = pathToLocation(filename);
Expand Down
8 changes: 5 additions & 3 deletions src/fsa-to-node/FsaNodeFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ import { FsaNodeStats } from './FsaNodeStats';
import process from '../process';
import { FsSynchronousApi } from '../node/types/FsSynchronousApi';
import { FsaNodeWriteStream } from './FsaNodeWriteStream';
import { FsaNodeCore } from './FsaNodeCore';
import type { FsCallbackApi, FsPromisesApi } from '../node/types';
import type * as misc from '../node/types/misc';
import type * as opts from '../node/types/options';
import type * as fsa from '../fsa/types';
import type { FsCommonObjects } from '../node/types/FsCommonObjects';
import type { WritevCallback } from '../node/types/callback';
import {FsaNodeCore} from './FsaNodeCore';

const notSupported: (...args: any[]) => any = () => {
throw new Error('Method not supported by the File System Access API.');
Expand All @@ -60,7 +60,6 @@ const noop: (...args: any[]) => any = () => {};
* [`FileSystemDirectoryHandle` object](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle).
*/
export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchronousApi, FsCommonObjects {

// ------------------------------------------------------------ FsCallbackApi

public readonly open: FsCallbackApi['open'] = (
Expand Down Expand Up @@ -757,7 +756,10 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono

// --------------------------------------------------------- FsSynchronousApi

public readonly statSync: FsSynchronousApi['statSync'] = (path: misc.PathLike, options?: opts.IStatOptions): misc.IStats<any> => {
public readonly statSync: FsSynchronousApi['statSync'] = (
path: misc.PathLike,
options?: opts.IStatOptions,
): misc.IStats<any> => {
const { bigint = true, throwIfNoEntry = true } = getStatOptions(options);
const adapter = this.syncAdapter;
if (!adapter) throw new Error('No sync adapter');
Expand Down
24 changes: 18 additions & 6 deletions src/fsa-to-node/FsaNodeWriteStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,32 @@ export class FsaNodeWriteStream extends Writable implements IWriteStream {

_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void {
this.___write___([chunk])
.then(() => { if (callback) callback(null); })
.catch(error => { if (callback) callback(error); });
.then(() => {
if (callback) callback(null);
})
.catch(error => {
if (callback) callback(error);
});
}

_writev(chunks: Array<{ chunk: any; encoding: string }>, callback: (error?: Error | null) => void): void {
const buffers = chunks.map(({ chunk }) => chunk);
this.___write___(buffers)
.then(() => { if (callback) callback(null); })
.catch(error => { if (callback) callback(error); });
.then(() => {
if (callback) callback(null);
})
.catch(error => {
if (callback) callback(error);
});
}

_final(callback: (error?: Error | null) => void): void {
this.__close__()
.then(() => { if (callback) callback(null); })
.catch(error => { if (callback) callback(error); });
.then(() => {
if (callback) callback(null);
})
.catch(error => {
if (callback) callback(error);
});
}
}
22 changes: 12 additions & 10 deletions src/fsa-to-node/worker/FsaNodeSyncAdapterWorker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Defer} from 'thingies/es6/Defer';
import {FsaNodeWorkerMessageCode} from './constants';
import {encode, decode} from 'json-joy/es6/json-pack/msgpack/util';
import {SyncMessenger} from "./SyncMessenger";
import { Defer } from 'thingies/es6/Defer';
import { FsaNodeWorkerMessageCode } from './constants';
import { encode, decode } from 'json-joy/es6/json-pack/msgpack/util';
import { SyncMessenger } from './SyncMessenger';
import type * as fsa from '../../fsa/types';
import type {FsLocation, FsaNodeSyncAdapter, FsaNodeSyncAdapterStats} from "../types";
import type {FsaNodeWorkerMsg, FsaNodeWorkerMsgInit, FsaNodeWorkerMsgRootSet, FsaNodeWorkerMsgSetRoot} from "./types";
import type { FsLocation, FsaNodeSyncAdapter, FsaNodeSyncAdapterStats } from '../types';
import type { FsaNodeWorkerMsg, FsaNodeWorkerMsgInit, FsaNodeWorkerMsgRootSet, FsaNodeWorkerMsgSetRoot } from './types';

let rootId = 0;

Expand All @@ -14,7 +14,7 @@ export class FsaNodeSyncAdapterWorker implements FsaNodeSyncAdapter {
const future = new Defer<FsaNodeSyncAdapterWorker>();
let id = rootId++;
let messenger: SyncMessenger | undefined = undefined;
worker.onmessage = (e) => {
worker.onmessage = e => {
const data = e.data;
if (!Array.isArray(data)) return;
console.log('<', data);
Expand All @@ -40,9 +40,11 @@ export class FsaNodeSyncAdapterWorker implements FsaNodeSyncAdapter {
return await future.promise;
}

public constructor(protected readonly messenger: SyncMessenger, protected readonly id: number, protected readonly root: fsa.IFileSystemDirectoryHandle) {

}
public constructor(
protected readonly messenger: SyncMessenger,
protected readonly id: number,
protected readonly root: fsa.IFileSystemDirectoryHandle,
) {}

public call(msg: FsaNodeWorkerMsg): unknown {
const request = encode(msg);
Expand Down
14 changes: 7 additions & 7 deletions src/fsa-to-node/worker/FsaNodeSyncWorker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {AsyncCallback, SyncMessenger} from "./SyncMessenger";
import {encode, decode} from 'json-joy/es6/json-pack/msgpack/util';
import {FsaNodeWorkerMessageCode} from "./constants";
import { AsyncCallback, SyncMessenger } from './SyncMessenger';
import { encode, decode } from 'json-joy/es6/json-pack/msgpack/util';
import { FsaNodeWorkerMessageCode } from './constants';
import type * as fsa from '../../fsa/types';
import type {FsaNodeWorkerError, FsaNodeWorkerMsg, FsaNodeWorkerMsgInit, FsaNodeWorkerMsgRootSet} from "./types";
import type {FsaNodeSyncAdapterStats} from "../types";
import type { FsaNodeWorkerError, FsaNodeWorkerMsg, FsaNodeWorkerMsgInit, FsaNodeWorkerMsgRootSet } from './types';
import type { FsaNodeSyncAdapterStats } from '../types';

export class FsaNodeSyncWorker {
protected readonly sab: SharedArrayBuffer = new SharedArrayBuffer(1024 * 32);
Expand All @@ -15,7 +15,7 @@ export class FsaNodeSyncWorker {
};

public start() {
onmessage = (e) => {
onmessage = e => {
if (!Array.isArray(e.data)) return;
console.log('>', e.data);
this.onPostMessage(e.data as FsaNodeWorkerMsg);
Expand Down Expand Up @@ -48,7 +48,7 @@ export class FsaNodeSyncWorker {
return encode([FsaNodeWorkerMessageCode.Response, response]);
} catch (err) {
const message = err && typeof err === 'object' && err.message ? err.message : 'Unknown error';
const error: FsaNodeWorkerError = {message};
const error: FsaNodeWorkerError = { message };
if (err && typeof err === 'object' && err.code) error.code = err.code;
return encode([FsaNodeWorkerMessageCode.ResponseError, error]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/fsa-to-node/worker/SyncMessenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const sleepUntilSync = (condition: () => boolean) => {
* `SyncMessenger` allows to execute asynchronous code synchronously. The
* asynchronous code is executed in a Worker thread, while the main thread is
* blocked until the asynchronous code is finished.
*
*
* First, four 4-byte works is the header, where the first word is used for Atomics
* notifications. The second word is used for spin-locking the main thread until
* the asynchronous code is finished. The third word is used to specify payload
* length. The fourth word is currently unused.
*
*
* The maximum payload size is the size of the SharedArrayBuffer minus the
* header size.
*/
Expand Down
14 changes: 9 additions & 5 deletions src/fsa-to-node/worker/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type {IFileSystemDirectoryHandle} from "../../fsa/types";
import type {FsLocation} from "../types";
import type {FsaNodeWorkerMessageCode} from "./constants";
import type { IFileSystemDirectoryHandle } from '../../fsa/types';
import type { FsLocation } from '../types';
import type { FsaNodeWorkerMessageCode } from './constants';

export type FsaNodeWorkerMsgInit = [type: FsaNodeWorkerMessageCode.Init, sab: SharedArrayBuffer];
export type FsaNodeWorkerMsgSetRoot = [type: FsaNodeWorkerMessageCode.SetRoot, id: number, dir: IFileSystemDirectoryHandle];
export type FsaNodeWorkerMsgSetRoot = [
type: FsaNodeWorkerMessageCode.SetRoot,
id: number,
dir: IFileSystemDirectoryHandle,
];
export type FsaNodeWorkerMsgRootSet = [type: FsaNodeWorkerMessageCode.RootSet, id: number];
export type FsaNodeWorkerMsgResponse = [type: FsaNodeWorkerMessageCode.Response, data: unknown];
export type FsaNodeWorkerMsgResponseError = [type: FsaNodeWorkerMessageCode.ResponseError, data: unknown];
Expand All @@ -14,7 +18,7 @@ export interface FsaNodeWorkerError {
code?: string;
}

export type FsaNodeWorkerMsg =
export type FsaNodeWorkerMsg =
| FsaNodeWorkerMsgInit
| FsaNodeWorkerMsgSetRoot
| FsaNodeWorkerMsgRootSet
Expand Down

0 comments on commit f6c417a

Please sign in to comment.