memfs 3.5.2 → 3.6.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/lib/process.js CHANGED
@@ -12,7 +12,7 @@ exports.createProcess = void 0;
12
12
  *
13
13
  * @return {IProcess | undefined}
14
14
  */
15
- var maybeReturnProcess = function () {
15
+ const maybeReturnProcess = () => {
16
16
  if (typeof process !== 'undefined') {
17
17
  return process;
18
18
  }
@@ -24,15 +24,15 @@ var maybeReturnProcess = function () {
24
24
  }
25
25
  };
26
26
  function createProcess() {
27
- var p = maybeReturnProcess() || {};
27
+ const p = maybeReturnProcess() || {};
28
28
  if (!p.cwd)
29
- p.cwd = function () { return '/'; };
29
+ p.cwd = () => '/';
30
30
  if (!p.nextTick)
31
31
  p.nextTick = require('./setImmediate').default;
32
32
  if (!p.emitWarning)
33
- p.emitWarning = function (message, type) {
33
+ p.emitWarning = (message, type) => {
34
34
  // tslint:disable-next-line:no-console
35
- console.warn("".concat(type).concat(type ? ': ' : '').concat(message));
35
+ console.warn(`${type}${type ? ': ' : ''}${message}`);
36
36
  };
37
37
  if (!p.env)
38
38
  p.env = {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var _setImmediate;
3
+ let _setImmediate;
4
4
  if (typeof setImmediate === 'function')
5
5
  _setImmediate = setImmediate.bind(typeof globalThis !== 'undefined' ? globalThis : global);
6
6
  else
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  * only in Node's environment it will "unref" its macro task.
6
6
  */
7
7
  function setTimeoutUnref(callback, time, args) {
8
- var ref = setTimeout.apply(typeof globalThis !== 'undefined' ? globalThis : global, arguments);
8
+ const ref = setTimeout.apply(typeof globalThis !== 'undefined' ? globalThis : global, arguments);
9
9
  if (ref && typeof ref === 'object' && typeof ref.unref === 'function')
10
10
  ref.unref();
11
11
  return ref;
@@ -1,110 +1,73 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.createVolume = exports.ObjectStore = void 0;
19
- var volume_1 = require("./volume");
20
- var node_1 = require("./node");
21
- var ObjectStore = /** @class */ (function () {
22
- function ObjectStore(obj) {
4
+ const volume_1 = require("./volume");
5
+ const node_1 = require("./node");
6
+ class ObjectStore {
7
+ constructor(obj) {
23
8
  this.obj = obj;
24
9
  }
25
- ObjectStore.prototype.setItem = function (key, json) {
10
+ setItem(key, json) {
26
11
  this.obj[key] = JSON.stringify(json);
27
- };
28
- ObjectStore.prototype.getItem = function (key) {
29
- var data = this.obj[key];
12
+ }
13
+ getItem(key) {
14
+ const data = this.obj[key];
30
15
  if (typeof data === void 0)
31
16
  return void 0;
32
17
  return JSON.parse(data);
33
- };
34
- ObjectStore.prototype.removeItem = function (key) {
18
+ }
19
+ removeItem(key) {
35
20
  delete this.obj[key];
36
- };
37
- return ObjectStore;
38
- }());
21
+ }
22
+ }
39
23
  exports.ObjectStore = ObjectStore;
40
- function createVolume(namespace, LS) {
41
- if (LS === void 0) { LS = localStorage; }
42
- var store = new ObjectStore(LS);
43
- var key = function (type, id) { return "memfs.".concat(namespace, ".").concat(type, ".").concat(id); };
44
- var NodeLocalStorage = /** @class */ (function (_super) {
45
- __extends(NodeLocalStorage, _super);
46
- function NodeLocalStorage() {
47
- return _super !== null && _super.apply(this, arguments) || this;
24
+ function createVolume(namespace, LS = localStorage) {
25
+ const store = new ObjectStore(LS);
26
+ const key = (type, id) => `memfs.${namespace}.${type}.${id}`;
27
+ class NodeLocalStorage extends node_1.Node {
28
+ get Key() {
29
+ if (!this._key)
30
+ this._key = key('ino', this.ino);
31
+ return this._key;
48
32
  }
49
- Object.defineProperty(NodeLocalStorage.prototype, "Key", {
50
- get: function () {
51
- if (!this._key)
52
- this._key = key('ino', this.ino);
53
- return this._key;
54
- },
55
- enumerable: false,
56
- configurable: true
57
- });
58
- NodeLocalStorage.prototype.sync = function () {
33
+ sync() {
59
34
  store.setItem(this.Key, this.toJSON());
60
- };
61
- NodeLocalStorage.prototype.touch = function () {
62
- _super.prototype.touch.call(this);
35
+ }
36
+ touch() {
37
+ super.touch();
63
38
  this.sync();
64
- };
65
- NodeLocalStorage.prototype.del = function () {
66
- _super.prototype.del.call(this);
39
+ }
40
+ del() {
41
+ super.del();
67
42
  store.removeItem(this.Key);
68
- };
69
- return NodeLocalStorage;
70
- }(node_1.Node));
71
- var LinkLocalStorage = /** @class */ (function (_super) {
72
- __extends(LinkLocalStorage, _super);
73
- function LinkLocalStorage() {
74
- return _super !== null && _super.apply(this, arguments) || this;
75
43
  }
76
- Object.defineProperty(LinkLocalStorage.prototype, "Key", {
77
- get: function () {
78
- if (!this._key)
79
- this._key = key('link', this.getPath());
80
- return this._key;
81
- },
82
- enumerable: false,
83
- configurable: true
84
- });
85
- LinkLocalStorage.prototype.sync = function () {
44
+ }
45
+ class LinkLocalStorage extends node_1.Link {
46
+ get Key() {
47
+ if (!this._key)
48
+ this._key = key('link', this.getPath());
49
+ return this._key;
50
+ }
51
+ sync() {
86
52
  store.setItem(this.Key, this.toJSON());
87
- };
88
- return LinkLocalStorage;
89
- }(node_1.Link));
90
- return /** @class */ (function (_super) {
91
- __extends(VolumeLocalStorage, _super);
92
- function VolumeLocalStorage() {
93
- return _super.call(this, {
53
+ }
54
+ }
55
+ return class VolumeLocalStorage extends volume_1.Volume {
56
+ constructor() {
57
+ super({
94
58
  Node: NodeLocalStorage,
95
59
  Link: LinkLocalStorage,
96
- }) || this;
60
+ });
97
61
  }
98
- VolumeLocalStorage.prototype.createLink = function (parent, name, isDirectory, perm) {
99
- var link = _super.prototype.createLink.call(this, parent, name, isDirectory, perm);
62
+ createLink(parent, name, isDirectory, perm) {
63
+ const link = super.createLink(parent, name, isDirectory, perm);
100
64
  store.setItem(key('link', link.getPath()), link.toJSON());
101
65
  return link;
102
- };
103
- VolumeLocalStorage.prototype.deleteLink = function (link) {
66
+ }
67
+ deleteLink(link) {
104
68
  store.removeItem(key('link', link.getPath()));
105
- return _super.prototype.deleteLink.call(this, link);
106
- };
107
- return VolumeLocalStorage;
108
- }(volume_1.Volume));
69
+ return super.deleteLink(link);
70
+ }
71
+ };
109
72
  }
110
73
  exports.createVolume = createVolume;
package/lib/volume.d.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
4
  /// <reference types="node" />
5
- import { PathLike, symlink } from 'fs';
6
5
  import { Node, Link, File } from './node';
7
6
  import Stats from './Stats';
8
7
  import Dirent from './Dirent';
@@ -11,11 +10,12 @@ import { Readable, Writable } from 'stream';
11
10
  import { constants } from './constants';
12
11
  import { EventEmitter } from 'events';
13
12
  import { TEncodingExtended, TDataOut } from './encoding';
13
+ import type { PathLike, symlink } from 'fs';
14
14
  export interface IError extends Error {
15
15
  code?: string;
16
16
  }
17
17
  export type TFileId = PathLike | number;
18
- export type TData = TDataOut | Uint8Array;
18
+ export type TData = TDataOut | ArrayBufferView | DataView;
19
19
  export type TFlags = string | number;
20
20
  export type TMode = string | number;
21
21
  export type TTime = number | string | Date;
@@ -89,7 +89,10 @@ export interface IMkdirOptions {
89
89
  recursive?: boolean;
90
90
  }
91
91
  export interface IRmdirOptions {
92
+ /** @deprecated */
92
93
  recursive?: boolean;
94
+ maxRetries?: number;
95
+ retryDelay?: number;
93
96
  }
94
97
  export interface IRmOptions {
95
98
  force?: boolean;
@@ -157,7 +160,7 @@ export declare class Volume {
157
160
  File: new (...args: any[]) => File;
158
161
  };
159
162
  private promisesApi;
160
- get promises(): import("./promises").IPromisesAPI;
163
+ get promises(): import("./node/types").FsPromisesApi;
161
164
  constructor(props?: {});
162
165
  createLink(): Link;
163
166
  createLink(parent: Link, name: string, isDirectory?: boolean, perm?: number): Link;
@@ -199,19 +202,19 @@ export declare class Volume {
199
202
  close(fd: number, callback: TCallback<void>): void;
200
203
  private openFileOrGetById;
201
204
  private readBase;
202
- readSync(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number): number;
203
- read(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number, callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | Uint8Array) => void): void;
205
+ readSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number): number;
206
+ read(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | ArrayBufferView | DataView) => void): void;
204
207
  private readFileBase;
205
208
  readFileSync(file: TFileId, options?: IReadFileOptions | string): TDataOut;
206
209
  readFile(id: TFileId, callback: TCallback<TDataOut>): any;
207
210
  readFile(id: TFileId, options: IReadFileOptions | string, callback: TCallback<TDataOut>): any;
208
211
  private writeBase;
209
- writeSync(fd: number, buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): number;
212
+ writeSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
210
213
  writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
211
- write(fd: number, buffer: Buffer | Uint8Array, callback: (...args: any[]) => void): any;
212
- write(fd: number, buffer: Buffer | Uint8Array, offset: number, callback: (...args: any[]) => void): any;
213
- write(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, callback: (...args: any[]) => void): any;
214
- write(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number, callback: (...args: any[]) => void): any;
214
+ write(fd: number, buffer: Buffer | ArrayBufferView | DataView, callback: (...args: any[]) => void): any;
215
+ write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, callback: (...args: any[]) => void): any;
216
+ write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, callback: (...args: any[]) => void): any;
217
+ write(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number, callback: (...args: any[]) => void): any;
215
218
  write(fd: number, str: string, callback: (...args: any[]) => void): any;
216
219
  write(fd: number, str: string, position: number, callback: (...args: any[]) => void): any;
217
220
  write(fd: number, str: string, position: number, encoding: BufferEncoding, callback: (...args: any[]) => void): any;