@wocker/core 1.0.23-beta.0 → 1.0.23-beta.2

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.
Files changed (56) hide show
  1. package/lib/core/ControllerWrapper.d.ts +0 -1
  2. package/lib/core/ControllerWrapper.js +1 -14
  3. package/lib/core/InstanceWrapper.d.ts +0 -1
  4. package/lib/core/InstanceWrapper.js +0 -1
  5. package/lib/decorators/Global.d.ts +0 -1
  6. package/lib/decorators/Global.js +0 -1
  7. package/lib/decorators/Injectable.d.ts +5 -1
  8. package/lib/decorators/Injectable.js +5 -1
  9. package/lib/env.d.ts +1 -0
  10. package/lib/env.js +7 -1
  11. package/lib/exceptions/UsageException.d.ts +3 -0
  12. package/lib/exceptions/UsageException.js +10 -0
  13. package/lib/exceptions/index.d.ts +1 -0
  14. package/lib/exceptions/index.js +17 -0
  15. package/lib/index.d.ts +1 -0
  16. package/lib/index.js +1 -0
  17. package/lib/makes/AppConfig.d.ts +15 -30
  18. package/lib/makes/AppConfig.js +16 -20
  19. package/lib/makes/Config.d.ts +6 -0
  20. package/lib/makes/Config.js +4 -0
  21. package/lib/makes/ConfigCollection.d.ts +6 -0
  22. package/lib/makes/ConfigCollection.js +4 -0
  23. package/lib/makes/File.d.ts +32 -0
  24. package/lib/makes/File.js +140 -0
  25. package/lib/makes/FileSystem.d.ts +33 -13
  26. package/lib/makes/FileSystem.js +66 -51
  27. package/lib/makes/FileSystemManager.d.ts +7 -4
  28. package/lib/makes/FileSystemManager.js +20 -3
  29. package/lib/makes/Logger.d.ts +1 -1
  30. package/lib/makes/Project.d.ts +9 -3
  31. package/lib/makes/Project.js +11 -3
  32. package/lib/makes/index.d.ts +0 -2
  33. package/lib/makes/index.js +0 -2
  34. package/lib/services/AppConfigService.d.ts +6 -2
  35. package/lib/services/AppConfigService.js +16 -5
  36. package/lib/services/DockerService.d.ts +3 -1
  37. package/lib/services/ModemService.d.ts +4 -0
  38. package/lib/services/ModemService.js +16 -0
  39. package/lib/services/index.d.ts +1 -0
  40. package/lib/services/index.js +1 -0
  41. package/lib/types/FileSystemDriver.d.ts +38 -0
  42. package/lib/types/FileSystemDriver.js +2 -0
  43. package/lib/types/PluginRef.d.ts +4 -0
  44. package/lib/types/PluginRef.js +2 -0
  45. package/lib/types/PresetRef.d.ts +6 -0
  46. package/lib/types/PresetRef.js +2 -0
  47. package/lib/types/ProjectRef.d.ts +16 -0
  48. package/lib/types/ProjectRef.js +2 -0
  49. package/lib/types/Provider.d.ts +1 -1
  50. package/lib/types/index.d.ts +1 -0
  51. package/lib/types/index.js +1 -0
  52. package/package.json +8 -3
  53. package/lib/makes/FS.d.ts +0 -19
  54. package/lib/makes/FS.js +0 -170
  55. package/lib/makes/FSManager.d.ts +0 -14
  56. package/lib/makes/FSManager.js +0 -122
@@ -10,7 +10,6 @@ export declare class ControllerWrapper<TInput = any> extends InstanceWrapper {
10
10
  commands: Route[];
11
11
  completions: Route[];
12
12
  constructor(module: Module, type: Type<TInput>);
13
- getRoutes(): Route[];
14
13
  getCompletionCommands(name: string, command: string): Route[];
15
14
  run(route: Route, input: CommandInput): any;
16
15
  }
@@ -27,19 +27,6 @@ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
27
27
  }
28
28
  }
29
29
  }
30
- getRoutes() {
31
- const routes = [];
32
- if (!this.type) {
33
- return [];
34
- }
35
- for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
36
- const route = new Route_1.Route(this.type, method);
37
- if (route.isCommand || route.isCompletion) {
38
- routes.push(route);
39
- }
40
- }
41
- return routes;
42
- }
43
30
  getCompletionCommands(name, command) {
44
31
  const completions = this.completions.filter((route) => {
45
32
  return route.completions.filter((completion) => {
@@ -52,7 +39,7 @@ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
52
39
  return this.completions.filter((route) => {
53
40
  return route.completions.filter((completion) => {
54
41
  return completion.name === name && !completion.command;
55
- });
42
+ }).length > 0;
56
43
  });
57
44
  }
58
45
  run(route, input) {
@@ -1,4 +1,3 @@
1
- import "reflect-metadata";
2
1
  import { Module } from "./Module";
3
2
  import { Provider } from "../types/Provider";
4
3
  import { Type } from "../types/Type";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InstanceWrapper = void 0;
4
- require("reflect-metadata");
5
4
  const env_1 = require("../env");
6
5
  class InstanceWrapper {
7
6
  constructor(module, provider, _instance) {
@@ -1,2 +1 @@
1
- import "reflect-metadata";
2
1
  export declare const Global: () => ClassDecorator;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Global = void 0;
4
- require("reflect-metadata");
5
4
  const env_1 = require("../env");
6
5
  const Global = () => {
7
6
  return (target) => {
@@ -1 +1,5 @@
1
- export declare const Injectable: (token?: string) => ClassDecorator;
1
+ type Options = string | {
2
+ token?: string;
3
+ };
4
+ export declare const Injectable: (tokenOrOptions?: Options) => ClassDecorator;
5
+ export {};
@@ -2,9 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Injectable = void 0;
4
4
  const env_1 = require("../env");
5
- const Injectable = (token) => {
5
+ const Injectable = (tokenOrOptions) => {
6
6
  return (target) => {
7
7
  Reflect.defineMetadata(env_1.INJECTABLE_WATERMARK, true, target);
8
+ if (!tokenOrOptions) {
9
+ return;
10
+ }
11
+ const { token } = typeof tokenOrOptions === "string" ? { token: tokenOrOptions } : tokenOrOptions;
8
12
  if (token) {
9
13
  Reflect.defineMetadata(env_1.INJECT_TOKEN_METADATA, token, target);
10
14
  }
package/lib/env.d.ts CHANGED
@@ -18,3 +18,4 @@ export declare enum MODULE_METADATA {
18
18
  CONTROLLERS = "controllers",
19
19
  PROVIDERS = "providers"
20
20
  }
21
+ export declare const DATA_DIR: string;
package/lib/env.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ALIAS_METADATA = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
6
+ exports.DATA_DIR = exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ALIAS_METADATA = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_METADATA = exports.DESCRIPTION_METADATA = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
4
9
  exports.IS_GLOBAL_METADATA = "IS_GLOBAL";
5
10
  exports.IS_MODULE_METADATA = "isModule";
6
11
  exports.INJECTABLE_WATERMARK = "__injectable__";
@@ -22,3 +27,4 @@ var MODULE_METADATA;
22
27
  MODULE_METADATA["CONTROLLERS"] = "controllers";
23
28
  MODULE_METADATA["PROVIDERS"] = "providers";
24
29
  })(MODULE_METADATA || (exports.MODULE_METADATA = MODULE_METADATA = {}));
30
+ exports.DATA_DIR = process.env.WS_DIR || path_1.default.join(os_1.default.homedir(), ".workspace");
@@ -0,0 +1,3 @@
1
+ export declare class UsageException extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsageException = void 0;
4
+ class UsageException extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "UsageException";
8
+ }
9
+ }
10
+ exports.UsageException = UsageException;
@@ -0,0 +1 @@
1
+ export * from "./UsageException";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./UsageException"), exports);
package/lib/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import "reflect-metadata";
2
2
  export { Cli, CommandNotFoundError } from "@kearisp/cli";
3
3
  export * from "./core";
4
4
  export * from "./decorators";
5
+ export * from "./exceptions";
5
6
  export * from "./makes";
6
7
  export * from "./services";
7
8
  export * from "./types";
package/lib/index.js CHANGED
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "Cli", { enumerable: true, get: function () { ret
21
21
  Object.defineProperty(exports, "CommandNotFoundError", { enumerable: true, get: function () { return cli_1.CommandNotFoundError; } });
22
22
  __exportStar(require("./core"), exports);
23
23
  __exportStar(require("./decorators"), exports);
24
+ __exportStar(require("./exceptions"), exports);
24
25
  __exportStar(require("./makes"), exports);
25
26
  __exportStar(require("./services"), exports);
26
27
  __exportStar(require("./types"), exports);
@@ -1,50 +1,37 @@
1
1
  import { EnvConfig } from "../types";
2
+ import { PluginRef } from "../types/PluginRef";
3
+ import { PresetRef } from "../types/PresetRef";
4
+ import { ProjectRef, ProjectOldRef } from "../types/ProjectRef";
2
5
  import { PresetSource } from "./Preset";
3
- type ProjectData = {
4
- id: string;
5
- name?: string;
6
- path?: string;
7
- /** @deprecated */
8
- src?: string;
9
- };
10
- type PluginData = {
11
- name: string;
12
- env: "latest" | "beta";
13
- };
14
- type PresetData = {
15
- name: string;
16
- source: PresetSource;
17
- path?: string;
18
- };
19
6
  export type AppConfigProperties = {
20
7
  debug?: boolean;
21
8
  keystore?: string;
22
9
  logLevel?: "off" | "info" | "warn" | "error";
23
- plugins?: PluginData[];
24
- presets?: PresetData[];
25
- projects?: ProjectData[];
10
+ plugins?: PluginRef[];
11
+ presets?: PresetRef[];
12
+ projects?: ProjectOldRef[];
26
13
  meta?: EnvConfig;
27
14
  env?: EnvConfig;
28
15
  };
29
- export declare abstract class AppConfig {
16
+ export declare class AppConfig {
30
17
  debug?: boolean;
31
18
  keystore?: string;
32
19
  logLevel: "off" | "info" | "warn" | "error";
33
- plugins: PluginData[];
34
- presets: PresetData[];
35
- projects: ProjectData[];
20
+ plugins: PluginRef[];
21
+ presets: PresetRef[];
22
+ projects: ProjectRef[];
36
23
  meta?: EnvConfig;
37
24
  env?: EnvConfig;
38
- protected constructor(data: AppConfigProperties);
39
- addPlugin(name: string, env?: PluginData["env"]): void;
25
+ constructor(data: AppConfigProperties);
26
+ addPlugin(name: string, env?: PluginRef["env"]): void;
40
27
  removePlugin(name: string): void;
41
- getProject(id: string): ProjectData | undefined;
28
+ getProject(name: string): ProjectRef | undefined;
42
29
  addProject(id: string, name: string, path: string): void;
43
- removeProject(id: string): void;
30
+ removeProject(name: string): void;
44
31
  registerPreset(name: string, source: PresetSource, path?: string): void;
45
32
  unregisterPreset(name: string): void;
46
33
  hasMeta(name: string): boolean;
47
- getMeta(name: string): string | undefined;
34
+ getMeta(name: string, defaultValue?: string): string | undefined;
48
35
  getMeta(name: string, defaultValue: string): string;
49
36
  setMeta(name: string, value: string): void;
50
37
  unsetMeta(name: string): void;
@@ -52,7 +39,6 @@ export declare abstract class AppConfig {
52
39
  getEnv(name: string, defaultValue: string): string;
53
40
  setEnv(name: string, value: string): void;
54
41
  unsetEnv(name: string): void;
55
- abstract save(): void;
56
42
  /**
57
43
  * @deprecated
58
44
  */
@@ -61,4 +47,3 @@ export declare abstract class AppConfig {
61
47
  toJsString(): string;
62
48
  toString(): string;
63
49
  }
64
- export {};
@@ -28,7 +28,13 @@ class AppConfig {
28
28
  return plugin;
29
29
  });
30
30
  this.presets = presets;
31
- this.projects = projects;
31
+ this.projects = projects.map((ref) => {
32
+ const { id, name, path, src } = ref;
33
+ return {
34
+ name: (name || id),
35
+ path: (path || src)
36
+ };
37
+ });
32
38
  }
33
39
  addPlugin(name, env = "latest") {
34
40
  const plugin = this.plugins.find((plugin) => plugin.name === name);
@@ -48,42 +54,32 @@ class AppConfig {
48
54
  }
49
55
  this.plugins = this.plugins.filter((plugin) => plugin.name !== name);
50
56
  }
51
- getProject(id) {
57
+ getProject(name) {
52
58
  if (!this.projects) {
53
59
  return;
54
60
  }
55
61
  return this.projects.find((projectData) => {
56
- return projectData.id === id;
62
+ return projectData.name === name;
57
63
  });
58
64
  }
59
65
  addProject(id, name, path) {
60
- if (!this.projects) {
61
- this.projects = [];
62
- }
63
- let projectData = this.projects.find((projectData) => {
64
- return projectData.id === id;
65
- });
66
- if (!projectData) {
66
+ let projectRef = this.getProject(name);
67
+ if (!projectRef) {
67
68
  this.projects.push({
68
- id,
69
69
  name,
70
- path,
70
+ path
71
71
  });
72
72
  return;
73
73
  }
74
- /* istanbul ignore next */
75
- if (projectData.src) {
76
- delete projectData.src;
77
- }
78
- projectData.name = name;
79
- projectData.path = path;
74
+ projectRef.name = name;
75
+ projectRef.path = path;
80
76
  }
81
- removeProject(id) {
77
+ removeProject(name) {
82
78
  if (this.projects.length === 0) {
83
79
  return;
84
80
  }
85
81
  this.projects = this.projects.filter((projectData) => {
86
- return projectData.id !== id;
82
+ return projectData.name !== name;
87
83
  });
88
84
  }
89
85
  registerPreset(name, source, path) {
@@ -1,6 +1,12 @@
1
+ /**
2
+ * @deprecated
3
+ */
1
4
  export type ConfigProperties = {
2
5
  name: string;
3
6
  };
7
+ /**
8
+ * @deprecated
9
+ */
4
10
  export declare class Config<T extends ConfigProperties> {
5
11
  name: string;
6
12
  constructor(data: T);
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Config = void 0;
4
+ /**
5
+ * @deprecated
6
+ */
7
+ /* istanbul ignore next */
4
8
  class Config {
5
9
  constructor(data) {
6
10
  this.name = data.name;
@@ -1,7 +1,13 @@
1
1
  import { Config, ConfigProperties } from "./Config";
2
+ /**
3
+ * @deprecated
4
+ */
2
5
  interface Constructible<P extends ConfigProperties, C extends Config<P>> {
3
6
  new (props: P): C;
4
7
  }
8
+ /**
9
+ * @deprecated
10
+ */
5
11
  export declare class ConfigCollection<C extends Config<P>, P extends ConfigProperties> {
6
12
  protected ConfigClass: Constructible<P, C>;
7
13
  items: C[];
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigCollection = void 0;
4
+ /**
5
+ * @deprecated
6
+ */
7
+ /* istanbul ignore next */
4
8
  class ConfigCollection {
5
9
  constructor(ConfigClass, items) {
6
10
  this.ConfigClass = ConfigClass;
@@ -0,0 +1,32 @@
1
+ import FS from "fs";
2
+ import { Readable } from "stream";
3
+ import { FileSystemDriver } from "../types";
4
+ type ReadStreamOptions = {
5
+ start?: number;
6
+ end?: number;
7
+ encoding?: BufferEncoding;
8
+ };
9
+ type ReadlineStreamOptions = {
10
+ start?: number;
11
+ end?: number;
12
+ encoding?: ReadStreamOptions["encoding"];
13
+ };
14
+ export declare class File {
15
+ readonly path: string;
16
+ readonly flags: FS.OpenMode;
17
+ readonly mode: FS.Mode | null | undefined;
18
+ protected readonly driver: FileSystemDriver;
19
+ protected _fd: number;
20
+ protected _closed: boolean;
21
+ constructor(path: string, flags: FS.OpenMode | undefined, mode: FS.Mode | null | undefined, driver?: FileSystemDriver);
22
+ get fd(): number;
23
+ get closed(): boolean;
24
+ open(): void;
25
+ stat(): FS.Stats;
26
+ close(): void;
27
+ createReadStream(options?: ReadStreamOptions): FS.ReadStream;
28
+ createReadlineStream(options?: ReadlineStreamOptions): Readable;
29
+ readBytes(position?: number, size?: number): Buffer<ArrayBuffer>;
30
+ getLinePosition(line: number): number;
31
+ }
32
+ export {};
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.File = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const stream_1 = require("stream");
9
+ const readline_1 = require("readline");
10
+ class File {
11
+ constructor(path, flags = "r", mode, driver = fs_1.default) {
12
+ this.path = path;
13
+ this.flags = flags;
14
+ this.mode = mode;
15
+ this.driver = driver;
16
+ this._closed = true;
17
+ this.open();
18
+ }
19
+ get fd() {
20
+ return this._fd;
21
+ }
22
+ get closed() {
23
+ return this._closed;
24
+ }
25
+ open() {
26
+ if (!this.closed) {
27
+ return;
28
+ }
29
+ this._fd = this.driver.openSync(this.path, this.flags, this.mode);
30
+ this._closed = false;
31
+ }
32
+ stat() {
33
+ return this.driver.fstatSync(this.fd);
34
+ }
35
+ close() {
36
+ if (this.closed) {
37
+ return;
38
+ }
39
+ this.driver.closeSync(this.fd);
40
+ this._closed = true;
41
+ }
42
+ createReadStream(options) {
43
+ const stream = this.driver.createReadStream(this.path, Object.assign(Object.assign({}, options || {}), { fd: this.fd, autoClose: false, emitClose: false }));
44
+ stream.on("close", () => {
45
+ this._closed = true;
46
+ });
47
+ return stream;
48
+ }
49
+ createReadlineStream(options) {
50
+ let { start, end, encoding } = options || {};
51
+ const startLine = typeof start !== "undefined"
52
+ ? this.getLinePosition(start)
53
+ : undefined;
54
+ const endLine = typeof end !== "undefined"
55
+ ? this.getLinePosition(end)
56
+ : undefined;
57
+ const stream = this.createReadStream({
58
+ encoding: encoding,
59
+ start: startLine,
60
+ end: endLine
61
+ });
62
+ const outputStream = new stream_1.Readable({
63
+ objectMode: true,
64
+ read() { }
65
+ });
66
+ const readline = (0, readline_1.createInterface)({
67
+ input: stream,
68
+ crlfDelay: Infinity
69
+ });
70
+ readline.on("line", (line) => {
71
+ outputStream.push(line);
72
+ });
73
+ readline.on("close", () => {
74
+ outputStream.push(null);
75
+ });
76
+ readline.on("error", (err) => {
77
+ outputStream.emit("error", err);
78
+ });
79
+ stream.on("error", (err) => {
80
+ outputStream.emit("error", err);
81
+ });
82
+ return outputStream;
83
+ }
84
+ readBytes(position = 0, size) {
85
+ const stats = this.stat();
86
+ if (position < 0 && typeof size === "undefined") {
87
+ size = position * -1;
88
+ position = stats.size - size;
89
+ }
90
+ else if (typeof size === "undefined") {
91
+ size = stats.size - position;
92
+ }
93
+ if (size <= 0) {
94
+ return Buffer.alloc(0);
95
+ }
96
+ const buffer = Buffer.alloc(size);
97
+ this.driver.readSync(this.fd, buffer, 0, size, position);
98
+ return buffer;
99
+ }
100
+ getLinePosition(line) {
101
+ var _a, _b;
102
+ if (line === 0) {
103
+ throw new Error("Line number must be a non-zero");
104
+ }
105
+ const bufferSize = 1024, isForward = line > 0, targetLine = Math.abs(line), stats = this.stat();
106
+ let position = isForward ? 0 : stats.size, currentLine = 0, currentOffset = isForward ? 0 : stats.size + 1, stump = "";
107
+ while (isForward ? position < stats.size : position > 0) {
108
+ const readSize = isForward
109
+ ? Math.min(bufferSize, stats.size - position)
110
+ : Math.min(bufferSize, position);
111
+ if (!isForward) {
112
+ position -= readSize;
113
+ }
114
+ const chunk = this.readBytes(position, readSize).toString(), lines = (isForward ? stump + chunk : chunk + stump).split("\n");
115
+ if (isForward) {
116
+ position += readSize;
117
+ }
118
+ if (isForward ? position === stats.size : position === 0) {
119
+ stump = "";
120
+ }
121
+ else {
122
+ stump = isForward
123
+ ? (_a = lines.pop()) !== null && _a !== void 0 ? _a : ""
124
+ : (_b = lines.shift()) !== null && _b !== void 0 ? _b : "";
125
+ }
126
+ for (let i = isForward ? 0 : lines.length - 1; isForward ? i < lines.length : i >= 0; isForward ? i++ : i--) {
127
+ const lineLength = Buffer.byteLength(`${lines[i]}\n`);
128
+ currentLine++;
129
+ if (currentLine === targetLine) {
130
+ return isForward ? currentOffset : currentOffset - lineLength;
131
+ }
132
+ currentOffset += isForward ? lineLength : -lineLength;
133
+ }
134
+ }
135
+ return isForward
136
+ ? Math.min(currentOffset, stats.size)
137
+ : Math.max(currentOffset, 0);
138
+ }
139
+ }
140
+ exports.File = File;
@@ -1,24 +1,44 @@
1
- import fs, { RmOptions, Stats, WriteFileOptions, MakeDirectoryOptions } from "fs";
2
- type ReaddirOptions = fs.ObjectEncodingOptions & {
1
+ import FS from "fs";
2
+ import { Readable } from "stream";
3
+ import { FileSystemDriver, ReadStreamOptions, WriteStreamOptions } from "../types";
4
+ import { File } from "./File";
5
+ type ReaddirOptions = FS.ObjectEncodingOptions & {
3
6
  recursive?: boolean | undefined;
4
7
  };
8
+ type ReadlineOptions = {
9
+ encoding?: BufferEncoding;
10
+ start?: number;
11
+ end?: number;
12
+ };
5
13
  export declare class FileSystem {
6
14
  protected readonly source: string;
7
- constructor(source: string);
15
+ protected readonly driver: FileSystemDriver;
16
+ constructor(source: string, driver?: FileSystemDriver);
8
17
  path(...parts: string[]): string;
18
+ cd(path: string): FileSystem;
19
+ readBytes(path: string, position?: number, size?: number): Buffer<ArrayBuffer>;
20
+ open(path: string, flags: FS.OpenMode, mode?: FS.Mode | null): File;
9
21
  basename(...parts: string[]): string;
10
22
  exists(...parts: string[]): boolean;
11
- stat(...parts: string[]): Stats;
12
- mkdir(path?: string, options?: MakeDirectoryOptions): void;
13
- readdir(path: string): string[];
23
+ stat(...parts: string[]): FS.Stats;
24
+ mkdir(path?: string, options?: FS.MakeDirectoryOptions): void;
25
+ readdir(path?: string, options?: {
26
+ recursive?: boolean;
27
+ }): string[];
28
+ /**
29
+ * @deprecated
30
+ */
14
31
  readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
15
- readFile(path: string): Buffer;
32
+ readFile(path: string): string | Buffer;
16
33
  readJSON(...paths: string[]): any;
17
- writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): void;
18
- writeJSON(path: string, data: any, options?: WriteFileOptions): void;
19
- appendFile(path: string, data: string | Uint8Array, options?: WriteFileOptions): void;
20
- rm(path: string, options?: RmOptions): void;
21
- createWriteStream(path: string, options?: BufferEncoding): fs.WriteStream;
22
- createReadStream(path: string, options?: BufferEncoding): fs.ReadStream;
34
+ writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: FS.WriteFileOptions): void;
35
+ writeJSON(path: string, data: any, options?: FS.WriteFileOptions): void;
36
+ appendFile(path: string, data: string | Uint8Array, options?: FS.WriteFileOptions): void;
37
+ rm(path: string, options?: FS.RmOptions): void;
38
+ createWriteStream(path: string, options?: WriteStreamOptions): FS.WriteStream;
39
+ createReadStream(path: string, options?: ReadStreamOptions): FS.ReadStream;
40
+ createReadlineStream(path: string, options?: ReadlineOptions): Readable;
41
+ getLinePosition(path: string, line: number): number;
42
+ watch(path: string, options?: FS.WatchOptions): FS.FSWatcher;
23
43
  }
24
44
  export {};