superlib 1.0.21 → 1.2.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/basic/BaseError.d.ts +4 -0
- package/dist/basic/BaseError.d.ts.map +1 -0
- package/dist/basic/BaseError.js +6 -0
- package/dist/basic/Result.d.ts +29 -0
- package/dist/basic/Result.d.ts.map +1 -0
- package/dist/basic/Result.js +55 -0
- package/dist/basic/ResultAsync.d.ts +9 -0
- package/dist/basic/ResultAsync.d.ts.map +1 -0
- package/dist/basic/ResultAsync.js +41 -0
- package/dist/basic/assert.d.ts +8 -0
- package/dist/basic/assert.d.ts.map +1 -0
- package/dist/basic/assert.js +25 -0
- package/dist/basic/index.d.ts +5 -0
- package/dist/basic/index.d.ts.map +1 -0
- package/dist/basic/index.js +4 -0
- package/dist/decorators/Retry.d.ts +3 -0
- package/dist/decorators/Retry.d.ts.map +1 -0
- package/dist/decorators/Retry.js +9 -0
- package/dist/decorators/Timeout.d.ts +3 -0
- package/dist/decorators/Timeout.d.ts.map +1 -0
- package/dist/decorators/Timeout.js +9 -0
- package/dist/decorators/common.d.ts +2 -0
- package/dist/decorators/common.d.ts.map +1 -0
- package/dist/decorators/common.js +17 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/platform/JsonHttpClient/JsonHttpClient.d.ts +18 -0
- package/dist/platform/JsonHttpClient/JsonHttpClient.d.ts.map +1 -0
- package/dist/platform/JsonHttpClient/JsonHttpClient.js +48 -0
- package/dist/platform/JsonHttpClient/index.d.ts +2 -0
- package/dist/platform/JsonHttpClient/index.d.ts.map +1 -0
- package/dist/platform/JsonHttpClient/index.js +1 -0
- package/dist/platform/ProcessContext/EnvReader.d.ts +12 -0
- package/dist/platform/ProcessContext/EnvReader.d.ts.map +1 -0
- package/dist/platform/ProcessContext/EnvReader.js +56 -0
- package/dist/platform/ProcessContext/ProcessContext.d.ts +40 -0
- package/dist/platform/ProcessContext/ProcessContext.d.ts.map +1 -0
- package/dist/platform/ProcessContext/ProcessContext.js +57 -0
- package/dist/platform/ProcessContext/index.d.ts +3 -0
- package/dist/platform/ProcessContext/index.d.ts.map +1 -0
- package/dist/platform/ProcessContext/index.js +2 -0
- package/dist/platform/filesystem/AbsolutePath.d.ts +18 -0
- package/dist/platform/filesystem/AbsolutePath.d.ts.map +1 -0
- package/dist/platform/filesystem/AbsolutePath.js +28 -0
- package/dist/platform/filesystem/FileSystem.d.ts +19 -0
- package/dist/platform/filesystem/FileSystem.d.ts.map +1 -0
- package/dist/platform/filesystem/FileSystem.js +92 -0
- package/dist/platform/filesystem/IFileSystem.d.ts +46 -0
- package/dist/platform/filesystem/IFileSystem.d.ts.map +1 -0
- package/dist/platform/filesystem/IFileSystem.js +1 -0
- package/dist/platform/filesystem/MemoryFileSystem.d.ts +29 -0
- package/dist/platform/filesystem/MemoryFileSystem.d.ts.map +1 -0
- package/dist/platform/filesystem/MemoryFileSystem.js +126 -0
- package/dist/platform/filesystem/index.d.ts +5 -0
- package/dist/platform/filesystem/index.d.ts.map +1 -0
- package/dist/platform/filesystem/index.js +4 -0
- package/dist/platform/get-port/checkPort.d.ts +2 -0
- package/dist/platform/get-port/checkPort.d.ts.map +1 -0
- package/dist/platform/get-port/checkPort.js +20 -0
- package/dist/platform/get-port/getPort.d.ts +8 -0
- package/dist/platform/get-port/getPort.d.ts.map +1 -0
- package/dist/platform/get-port/getPort.js +13 -0
- package/dist/platform/safeFetch/index.d.ts +2 -0
- package/dist/platform/safeFetch/index.d.ts.map +1 -0
- package/dist/platform/safeFetch/index.js +1 -0
- package/dist/platform/safeFetch/makeSafeFetch.d.ts +23 -0
- package/dist/platform/safeFetch/makeSafeFetch.d.ts.map +1 -0
- package/dist/platform/safeFetch/makeSafeFetch.js +19 -0
- package/dist/random/FixedRandom.d.ts +12 -0
- package/dist/random/FixedRandom.d.ts.map +1 -0
- package/dist/random/FixedRandom.js +43 -0
- package/dist/random/Random.d.ts +18 -0
- package/dist/random/Random.d.ts.map +1 -0
- package/dist/random/Random.js +24 -0
- package/dist/random/RealRandom.d.ts +5 -0
- package/dist/random/RealRandom.d.ts.map +1 -0
- package/dist/random/RealRandom.js +6 -0
- package/dist/random/SeededRandom.d.ts +10 -0
- package/dist/random/SeededRandom.d.ts.map +1 -0
- package/dist/random/SeededRandom.js +15 -0
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/index.js +4 -0
- package/dist/schema/StandardSchema.d.ts +60 -0
- package/dist/schema/StandardSchema.d.ts.map +1 -0
- package/dist/schema/StandardSchema.js +1 -0
- package/dist/schema/validateSchema.d.ts +9 -0
- package/dist/schema/validateSchema.d.ts.map +1 -0
- package/dist/schema/validateSchema.js +9 -0
- package/dist/task/all.d.ts +14 -0
- package/dist/task/all.d.ts.map +1 -0
- package/dist/task/all.js +61 -0
- package/dist/task/index.d.ts +15 -0
- package/dist/task/index.d.ts.map +1 -0
- package/dist/task/index.js +11 -0
- package/dist/task/pipe.d.ts +8 -0
- package/dist/task/pipe.d.ts.map +1 -0
- package/dist/task/pipe.js +11 -0
- package/dist/task/retry.d.ts +27 -0
- package/dist/task/retry.d.ts.map +1 -0
- package/dist/task/retry.js +61 -0
- package/dist/task/timeout.d.ts +21 -0
- package/dist/task/timeout.d.ts.map +1 -0
- package/dist/task/timeout.js +39 -0
- package/dist/task/types.d.ts +3 -0
- package/dist/task/types.d.ts.map +1 -0
- package/dist/task/types.js +1 -0
- package/dist/time/Clock.d.ts +18 -0
- package/dist/time/Clock.d.ts.map +1 -0
- package/dist/time/Clock.js +26 -0
- package/dist/time/index.d.ts +4 -0
- package/dist/time/index.d.ts.map +1 -0
- package/dist/time/index.js +3 -0
- package/dist/time/sleep.d.ts +3 -0
- package/dist/time/sleep.d.ts.map +1 -0
- package/dist/time/sleep.js +5 -0
- package/dist/time/temporal.d.ts +5 -0
- package/dist/time/temporal.d.ts.map +1 -0
- package/dist/time/temporal.js +20 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +57 -17
- package/README.md +0 -46
- package/elm-projects.js +0 -62
- package/index.js +0 -3
- package/lib.js +0 -117
- package/libm.js +0 -52
- package/projects.js +0 -145
- package/providers/github.js +0 -22
- package/providers/lib/connection.js +0 -19
- package/providers/npmjs.js +0 -22
- package/tests/providers.js +0 -13
- package/tests/utilities.js +0 -13
- package/utilities.js +0 -116
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import * as pathModule from "node:path";
|
|
3
|
+
class AbsolutePathClazz {
|
|
4
|
+
path;
|
|
5
|
+
constructor(path) {
|
|
6
|
+
assert(pathModule.isAbsolute(path), `Path is not absolute, was: ${path}`);
|
|
7
|
+
const normalizedPath = pathModule.resolve(path);
|
|
8
|
+
this.path = normalizedPath;
|
|
9
|
+
}
|
|
10
|
+
join(...paths) {
|
|
11
|
+
return AbsolutePath(pathModule.join(this.path, ...paths));
|
|
12
|
+
}
|
|
13
|
+
dirname() {
|
|
14
|
+
return AbsolutePath(pathModule.dirname(this.path));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Note: this returns string representing relative path
|
|
18
|
+
*/
|
|
19
|
+
relativeFrom(root) {
|
|
20
|
+
return pathModule.relative(root.path, this.path);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function AbsolutePathClass(absolutePath) {
|
|
24
|
+
return new AbsolutePathClazz(absolutePath);
|
|
25
|
+
}
|
|
26
|
+
Object.setPrototypeOf(AbsolutePathClass, AbsolutePathClazz);
|
|
27
|
+
AbsolutePathClass.prototype = AbsolutePathClazz.prototype;
|
|
28
|
+
export const AbsolutePath = Object.assign(AbsolutePathClass, AbsolutePathClazz);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DirRemoveError, FileAccessError, FileWriteError, IFileSystem } from "./IFileSystem";
|
|
2
|
+
import { Result } from "../../basic/Result";
|
|
3
|
+
import { AbsolutePath } from "./AbsolutePath";
|
|
4
|
+
export declare class FileSystem implements IFileSystem {
|
|
5
|
+
readFile(path: AbsolutePath): Promise<Result<string, FileAccessError>>;
|
|
6
|
+
writeFile(path: AbsolutePath, contents: string): Promise<Result<void, FileWriteError>>;
|
|
7
|
+
exists(path: AbsolutePath): Promise<boolean>;
|
|
8
|
+
createDirectory(path: AbsolutePath, options: {
|
|
9
|
+
recursive: boolean;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
removeDirectory(path: AbsolutePath, options: {
|
|
12
|
+
recursive: boolean;
|
|
13
|
+
force: boolean;
|
|
14
|
+
}): Promise<Result<void, DirRemoveError>>;
|
|
15
|
+
createTempDir(prefix: string): Promise<AsyncDisposable & {
|
|
16
|
+
path: AbsolutePath;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=FileSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/platform/filesystem/FileSystem.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEjG,OAAO,EAAM,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,qBAAa,UAAW,YAAW,WAAW;IACtC,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAkBtE,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAgBtF,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAS5C,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAInF,eAAe,CACnB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IA6ClC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG;QAAE,IAAI,EAAE,YAAY,CAAA;KAAE,CAAC;CAWvF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { access, mkdir, mkdtemp, readFile, rm, rmdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import * as pathModule from "node:path";
|
|
4
|
+
import { Ok, Result } from "../../basic/Result.js";
|
|
5
|
+
import { ResultAsync } from "../../basic/ResultAsync.js";
|
|
6
|
+
import { AbsolutePath } from "./AbsolutePath.js";
|
|
7
|
+
export class FileSystem {
|
|
8
|
+
async readFile(path) {
|
|
9
|
+
return ResultAsync.try(() => readFile(path.path, "utf8"), (error) => {
|
|
10
|
+
if (error instanceof Error && "code" in error) {
|
|
11
|
+
switch (error.code) {
|
|
12
|
+
case "ENOENT":
|
|
13
|
+
return { type: "fs/file-not-found", path };
|
|
14
|
+
case "EISDIR":
|
|
15
|
+
return { type: "fs/file-is-a-dir", path };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { type: "fs/other", cause: error };
|
|
19
|
+
}).toPromise();
|
|
20
|
+
}
|
|
21
|
+
async writeFile(path, contents) {
|
|
22
|
+
return ResultAsync.try(() => writeFile(path.path, contents, "utf8"), (error) => {
|
|
23
|
+
if (error instanceof Error && "code" in error) {
|
|
24
|
+
switch (error.code) {
|
|
25
|
+
case "EISDIR":
|
|
26
|
+
return { type: "fs/file-is-a-dir", path };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { type: "fs/other", cause: error };
|
|
30
|
+
}).toPromise();
|
|
31
|
+
}
|
|
32
|
+
async exists(path) {
|
|
33
|
+
try {
|
|
34
|
+
await access(path.path);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async createDirectory(path, options) {
|
|
42
|
+
await mkdir(path.path, { recursive: options.recursive });
|
|
43
|
+
}
|
|
44
|
+
async removeDirectory(path, options) {
|
|
45
|
+
// @todo it might be possible to simplify this
|
|
46
|
+
if (options.recursive) {
|
|
47
|
+
return ResultAsync.try(() => rm(path.path, { recursive: true, force: options.force }), (error) => {
|
|
48
|
+
if (error instanceof Error && "code" in error) {
|
|
49
|
+
switch (error.code) {
|
|
50
|
+
case "ENOENT":
|
|
51
|
+
return { type: "fs/dir-not-found", path };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
type: "fs/other",
|
|
56
|
+
cause: error,
|
|
57
|
+
};
|
|
58
|
+
}).toPromise();
|
|
59
|
+
}
|
|
60
|
+
return ResultAsync.try(() => rmdir(path.path), (error) => {
|
|
61
|
+
if (error instanceof Error && "code" in error) {
|
|
62
|
+
switch (error.code) {
|
|
63
|
+
case "EEXIST":
|
|
64
|
+
case "ENOTEMPTY":
|
|
65
|
+
return { type: "fs/dir-not-empty", path };
|
|
66
|
+
case "ENOENT": {
|
|
67
|
+
if (options.force) {
|
|
68
|
+
return Ok();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return { type: "fs/dir-not-found", path };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
type: "fs/other",
|
|
78
|
+
cause: error,
|
|
79
|
+
};
|
|
80
|
+
}).toPromise();
|
|
81
|
+
}
|
|
82
|
+
async createTempDir(prefix) {
|
|
83
|
+
const tempDirPath = await mkdtemp(pathModule.join(tmpdir(), prefix));
|
|
84
|
+
const tempPath = AbsolutePath(tempDirPath);
|
|
85
|
+
return {
|
|
86
|
+
path: tempPath,
|
|
87
|
+
async [Symbol.asyncDispose]() {
|
|
88
|
+
await rm(tempPath.path, { recursive: true, force: true });
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Result } from "../../basic/Result";
|
|
2
|
+
import type { AbsolutePath } from "./AbsolutePath";
|
|
3
|
+
export interface IFileSystem {
|
|
4
|
+
readFile(path: AbsolutePath): Promise<Result<string, FileAccessError>>;
|
|
5
|
+
writeFile(path: AbsolutePath, contents: string): Promise<Result<void, FileWriteError>>;
|
|
6
|
+
exists(path: AbsolutePath): Promise<boolean>;
|
|
7
|
+
createDirectory(path: AbsolutePath, options: {
|
|
8
|
+
recursive: boolean;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
removeDirectory(path: AbsolutePath, options: {
|
|
11
|
+
recursive: boolean;
|
|
12
|
+
force: boolean;
|
|
13
|
+
}): Promise<Result<void, DirRemoveError>>;
|
|
14
|
+
createTempDir(prefix: string): Promise<AsyncDisposable & {
|
|
15
|
+
path: AbsolutePath;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export type FileAccessError = {
|
|
19
|
+
type: "fs/file-not-found";
|
|
20
|
+
path: AbsolutePath;
|
|
21
|
+
} | {
|
|
22
|
+
type: "fs/file-is-a-dir";
|
|
23
|
+
path: AbsolutePath;
|
|
24
|
+
} | {
|
|
25
|
+
type: "fs/other";
|
|
26
|
+
cause: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type FileWriteError = {
|
|
29
|
+
type: "fs/file-is-a-dir";
|
|
30
|
+
path: AbsolutePath;
|
|
31
|
+
} | {
|
|
32
|
+
type: "fs/other";
|
|
33
|
+
cause: unknown;
|
|
34
|
+
};
|
|
35
|
+
export type DirAccessError = {
|
|
36
|
+
type: "fs/dir-not-found";
|
|
37
|
+
path: AbsolutePath;
|
|
38
|
+
} | {
|
|
39
|
+
type: "fs/other";
|
|
40
|
+
cause: unknown;
|
|
41
|
+
};
|
|
42
|
+
export type DirRemoveError = DirAccessError | {
|
|
43
|
+
type: "fs/dir-not-empty";
|
|
44
|
+
path: AbsolutePath;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=IFileSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFileSystem.d.ts","sourceRoot":"","sources":["../../../src/platform/filesystem/IFileSystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGlD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAA;IACtE,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;IACtF,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5C,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnF,eAAe,CACb,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;IAExC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG;QAAE,IAAI,EAAE,YAAY,CAAA;KAAE,CAAC,CAAA;CACjF;AAED,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,mBAAmB,CAAA;IACzB,IAAI,EAAE,YAAY,CAAA;CACnB,GACD;IACE,IAAI,EAAE,kBAAkB,CAAA;IACxB,IAAI,EAAE,YAAY,CAAA;CACnB,GACD;IACE,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAEL,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,kBAAkB,CAAA;IACxB,IAAI,EAAE,YAAY,CAAA;CACnB,GACD;IACE,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAEL,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,kBAAkB,CAAA;IACxB,IAAI,EAAE,YAAY,CAAA;CACnB,GACD;IACE,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAEL,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DirRemoveError, FileAccessError, FileWriteError, IFileSystem } from "./IFileSystem";
|
|
2
|
+
import { type Result } from "../../basic/Result";
|
|
3
|
+
import { AbsolutePath } from "./AbsolutePath";
|
|
4
|
+
type TempDirHandle = AsyncDisposable & {
|
|
5
|
+
path: AbsolutePath;
|
|
6
|
+
};
|
|
7
|
+
export declare class MemoryFileSystem implements IFileSystem {
|
|
8
|
+
private readonly files;
|
|
9
|
+
private readonly directories;
|
|
10
|
+
private readonly root;
|
|
11
|
+
private tempDirCounter;
|
|
12
|
+
constructor();
|
|
13
|
+
readFile(path: AbsolutePath): Promise<Result<string, FileAccessError>>;
|
|
14
|
+
writeFile(path: AbsolutePath, contents: string): Promise<Result<void, FileWriteError>>;
|
|
15
|
+
exists(path: AbsolutePath): Promise<boolean>;
|
|
16
|
+
createDirectory(dirPath: AbsolutePath, options: {
|
|
17
|
+
recursive: boolean;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
removeDirectory(dirPath: AbsolutePath, options: {
|
|
20
|
+
recursive: boolean;
|
|
21
|
+
force: boolean;
|
|
22
|
+
}): Promise<Result<void, DirRemoveError>>;
|
|
23
|
+
createTempDir(prefix: string): Promise<TempDirHandle>;
|
|
24
|
+
private removeDirectoryRecursive;
|
|
25
|
+
private isWithinDir;
|
|
26
|
+
private hasEntriesWithin;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=MemoryFileSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryFileSystem.d.ts","sourceRoot":"","sources":["../../../src/platform/filesystem/MemoryFileSystem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEjG,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,KAAK,aAAa,GAAG,eAAe,GAAG;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAA;AAE7D,qBAAa,gBAAiB,YAAW,WAAW;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4B;IAClD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IAEzC,OAAO,CAAC,cAAc,CAAI;;IAMpB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAatE,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAUtF,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BtF,eAAe,CACnB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAC9C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAsBlC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAiB3D,OAAO,CAAC,wBAAwB;IAgBhC,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,gBAAgB;CAezB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as pathModule from "node:path";
|
|
2
|
+
import { Err, Ok } from "../../basic/Result.js";
|
|
3
|
+
import { AbsolutePath } from "./AbsolutePath.js";
|
|
4
|
+
export class MemoryFileSystem {
|
|
5
|
+
files = new Map();
|
|
6
|
+
directories = new Set();
|
|
7
|
+
root = AbsolutePath("/");
|
|
8
|
+
tempDirCounter = 0; // used for numbering of temp dirs
|
|
9
|
+
constructor() {
|
|
10
|
+
this.directories.add(this.root.path);
|
|
11
|
+
}
|
|
12
|
+
async readFile(path) {
|
|
13
|
+
if (this.directories.has(path.path)) {
|
|
14
|
+
return Err({ type: "fs/file-is-a-dir", path });
|
|
15
|
+
}
|
|
16
|
+
const contents = this.files.get(path.path);
|
|
17
|
+
if (contents === undefined) {
|
|
18
|
+
return Err({ type: "fs/file-not-found", path });
|
|
19
|
+
}
|
|
20
|
+
return Ok(contents);
|
|
21
|
+
}
|
|
22
|
+
async writeFile(path, contents) {
|
|
23
|
+
await this.createDirectory(path.dirname(), { recursive: true });
|
|
24
|
+
if (this.directories.has(path.path)) {
|
|
25
|
+
return Err({ type: "fs/file-is-a-dir", path });
|
|
26
|
+
}
|
|
27
|
+
this.files.set(path.path, contents);
|
|
28
|
+
return Ok();
|
|
29
|
+
}
|
|
30
|
+
async exists(path) {
|
|
31
|
+
return this.files.has(path.path) || this.directories.has(path.path);
|
|
32
|
+
}
|
|
33
|
+
async createDirectory(dirPath, options) {
|
|
34
|
+
if (this.directories.has(dirPath.path)) {
|
|
35
|
+
if (!options.recursive) {
|
|
36
|
+
throw new Error(`Directory already exists: ${dirPath.path}`);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const parentPath = dirPath.dirname();
|
|
41
|
+
if (!options.recursive && !this.directories.has(parentPath.path)) {
|
|
42
|
+
throw new Error(`Parent directory does not exist: ${parentPath.path}`);
|
|
43
|
+
}
|
|
44
|
+
if (options.recursive) {
|
|
45
|
+
let current = dirPath.path;
|
|
46
|
+
while (!this.directories.has(current)) {
|
|
47
|
+
this.directories.add(current);
|
|
48
|
+
const parentPath = pathModule.dirname(current);
|
|
49
|
+
if (parentPath === current) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
current = parentPath;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.directories.add(dirPath.path);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async removeDirectory(dirPath, options) {
|
|
60
|
+
if (!this.directories.has(dirPath.path)) {
|
|
61
|
+
if (options.force) {
|
|
62
|
+
return Ok();
|
|
63
|
+
}
|
|
64
|
+
return Err({ type: "fs/dir-not-found", path: dirPath });
|
|
65
|
+
}
|
|
66
|
+
const hasChildren = this.hasEntriesWithin(dirPath.path);
|
|
67
|
+
if (hasChildren && !options.recursive) {
|
|
68
|
+
return Err({ type: "fs/dir-not-empty", path: dirPath });
|
|
69
|
+
}
|
|
70
|
+
if (options.recursive) {
|
|
71
|
+
this.removeDirectoryRecursive(dirPath.path);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.directories.delete(dirPath.path);
|
|
75
|
+
}
|
|
76
|
+
return Ok();
|
|
77
|
+
}
|
|
78
|
+
async createTempDir(prefix) {
|
|
79
|
+
const tempDirPath = this.root.join("tmp", `${prefix}${this.tempDirCounter++}`);
|
|
80
|
+
await this.createDirectory(tempDirPath, { recursive: true });
|
|
81
|
+
const removeTempDir = () => {
|
|
82
|
+
this.removeDirectoryRecursive(tempDirPath.path);
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
path: tempDirPath,
|
|
86
|
+
async [Symbol.asyncDispose]() {
|
|
87
|
+
removeTempDir();
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
removeDirectoryRecursive(dirPath) {
|
|
92
|
+
for (const filePath of this.files.keys()) {
|
|
93
|
+
if (this.isWithinDir(filePath, dirPath)) {
|
|
94
|
+
this.files.delete(filePath);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const directoryPath of Array.from(this.directories)) {
|
|
98
|
+
if (this.isWithinDir(directoryPath, dirPath)) {
|
|
99
|
+
this.directories.delete(directoryPath);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
this.directories.add(this.root.path);
|
|
103
|
+
}
|
|
104
|
+
isWithinDir(targetPath, dirPath) {
|
|
105
|
+
const relative = pathModule.relative(dirPath, targetPath);
|
|
106
|
+
if (relative === "") {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return (!relative.startsWith(`..${pathModule.sep}`) &&
|
|
110
|
+
relative !== ".." &&
|
|
111
|
+
!pathModule.isAbsolute(relative));
|
|
112
|
+
}
|
|
113
|
+
hasEntriesWithin(dirPath) {
|
|
114
|
+
for (const filePath of this.files.keys()) {
|
|
115
|
+
if (this.isWithinDir(filePath, dirPath) && filePath !== dirPath) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const directoryPath of this.directories) {
|
|
120
|
+
if (this.isWithinDir(directoryPath, dirPath) && directoryPath !== dirPath) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/platform/filesystem/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkPort.d.ts","sourceRoot":"","sources":["../../../src/platform/get-port/checkPort.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBxD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createServer } from "node:net";
|
|
2
|
+
export function checkPort(port) {
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
try {
|
|
5
|
+
const server = createServer();
|
|
6
|
+
server.unref();
|
|
7
|
+
server.on("error", () => {
|
|
8
|
+
resolve(false);
|
|
9
|
+
});
|
|
10
|
+
server.listen(port, "localhost", () => {
|
|
11
|
+
server.close(() => {
|
|
12
|
+
resolve(true);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
resolve(false);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type IRandom } from "../../random";
|
|
2
|
+
interface GetPortDependencies {
|
|
3
|
+
random: IRandom;
|
|
4
|
+
checkPort: (port: number) => Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
export declare function getPort(dependencies?: GetPortDependencies): Promise<number>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=getPort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPort.d.ts","sourceRoot":"","sources":["../../../src/platform/get-port/getPort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAGvD,UAAU,mBAAmB;IAC3B,MAAM,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAE9C;AAED,wBAAsB,OAAO,CAC3B,YAAY,GAAE,mBAA6D,GAC1E,OAAO,CAAC,MAAM,CAAC,CAUjB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RealRandom } from "../../random/index.js";
|
|
2
|
+
import { checkPort } from "./checkPort.js";
|
|
3
|
+
export async function getPort(dependencies = { random: new RealRandom(), checkPort }) {
|
|
4
|
+
while (true) {
|
|
5
|
+
const port = dependencies.random.nextInteger(LOW_PORT, HIGH_PORT);
|
|
6
|
+
const isAvailable = await dependencies.checkPort(port);
|
|
7
|
+
if (isAvailable) {
|
|
8
|
+
return port;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const LOW_PORT = 49152;
|
|
13
|
+
const HIGH_PORT = 65535;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/platform/safeFetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./makeSafeFetch.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TimeoutErr } from "../../task/timeout";
|
|
2
|
+
import type { DurationLike } from "../../time";
|
|
3
|
+
import { type Result } from "../../basic";
|
|
4
|
+
import { type RetryOptions } from "../../task/retry";
|
|
5
|
+
export interface SafeFetchOptions {
|
|
6
|
+
retry?: RetryOptions<SafeFetchResult> & {
|
|
7
|
+
untilStatus?: UntilStatusFn;
|
|
8
|
+
};
|
|
9
|
+
timeout?: DurationLike;
|
|
10
|
+
}
|
|
11
|
+
type UntilStatusFn = (status: number) => boolean;
|
|
12
|
+
export type SafeFetchError = {
|
|
13
|
+
type: "fetch/network";
|
|
14
|
+
cause: unknown;
|
|
15
|
+
} | {
|
|
16
|
+
type: "fetch/http";
|
|
17
|
+
status: number;
|
|
18
|
+
} | TimeoutErr;
|
|
19
|
+
export type SafeFetchResult = Result<Response, SafeFetchError>;
|
|
20
|
+
export type SafeFetch = (...args: Parameters<typeof fetch>) => Promise<SafeFetchResult>;
|
|
21
|
+
export declare function makeSafeFetch(options: SafeFetchOptions): SafeFetch;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=makeSafeFetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeSafeFetch.d.ts","sourceRoot":"","sources":["../../../src/platform/safeFetch/makeSafeFetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,OAAO,EAAwB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAA;AAE/D,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG;QAAE,WAAW,CAAC,EAAE,aAAa,CAAA;KAAE,CAAA;IACvE,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,KAAK,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAA;AAEhD,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtC,UAAU,CAAA;AAEd,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;AAE9D,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;AAEvF,wBAAgB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA0BlE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Err, Ok, ResultAsync } from "../../basic/index.js";
|
|
2
|
+
import { Task } from "../../task/index.js";
|
|
3
|
+
import {} from "../../task/retry.js";
|
|
4
|
+
export function makeSafeFetch(options) {
|
|
5
|
+
const untilStatus = options.retry?.untilStatus ?? ((status) => status >= 200 && status < 300);
|
|
6
|
+
return async (url, requestInit = {}) => {
|
|
7
|
+
const fetchTask = async () => {
|
|
8
|
+
return ResultAsync.try(() => fetch(url, requestInit), (error) => ({ type: "fetch/network", cause: error }))
|
|
9
|
+
.andThen((response) => {
|
|
10
|
+
if (!untilStatus(response.status)) {
|
|
11
|
+
return Err({ type: "fetch/http", status: response.status });
|
|
12
|
+
}
|
|
13
|
+
return Ok(response);
|
|
14
|
+
})
|
|
15
|
+
.toPromise();
|
|
16
|
+
};
|
|
17
|
+
return Task.pipe(fetchTask, options.timeout && Task.timeout({ timeout: options.timeout, useResult: true }), options.retry && Task.retry(options.retry));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IRandom } from "./Random";
|
|
2
|
+
export declare class FixedRandom implements IRandom {
|
|
3
|
+
private readonly sequence;
|
|
4
|
+
private index;
|
|
5
|
+
constructor(sequence: any[]);
|
|
6
|
+
private takeValue;
|
|
7
|
+
next(): number;
|
|
8
|
+
nextInteger(min: number, max: number): number;
|
|
9
|
+
nextNumber(min: number, max: number): number;
|
|
10
|
+
nextBoolean(): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=FixedRandom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FixedRandom.d.ts","sourceRoot":"","sources":["../../src/random/FixedRandom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAIvC,qBAAa,WAAY,YAAW,OAAO;IAE7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IADrC,OAAO,CAAC,KAAK,CAAI;gBACY,QAAQ,EAAE,GAAG,EAAE;IAE5C,OAAO,CAAC,SAAS;IAOjB,IAAI,IAAI,MAAM;IAUd,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAoB7C,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAc5C,WAAW,IAAI,OAAO;CAKvB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { assert } from "../basic/index.js";
|
|
2
|
+
export class FixedRandom {
|
|
3
|
+
sequence;
|
|
4
|
+
index = 0;
|
|
5
|
+
constructor(sequence) {
|
|
6
|
+
this.sequence = sequence;
|
|
7
|
+
}
|
|
8
|
+
takeValue(methodName) {
|
|
9
|
+
assert(this.index < this.sequence.length, `FixedRandom.${methodName} sequence is exhausted`);
|
|
10
|
+
const value = this.sequence[this.index];
|
|
11
|
+
this.index += 1;
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
next() {
|
|
15
|
+
const value = this.takeValue("next");
|
|
16
|
+
assert(Number.isFinite(value), `FixedRandom.next expected number, got: ${value}`);
|
|
17
|
+
assert(value >= 0 && value < 1, `FixedRandom.next expected number in range <0;1), got: ${value}`);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
nextInteger(min, max) {
|
|
21
|
+
assert(Number.isInteger(min) && !Number.isNaN(min), `min is expected to be an integer, was: ${min}`);
|
|
22
|
+
assert(Number.isInteger(max) && !Number.isNaN(max), `max is expected to be an integer, was: ${max}`);
|
|
23
|
+
assert(min < max, `expected min to be less than max, min=${min} max=${max}`);
|
|
24
|
+
const value = this.takeValue("nextInteger");
|
|
25
|
+
assert(Number.isInteger(value), `FixedRandom.nextInteger expected integer, got: ${value}`);
|
|
26
|
+
assert(value >= min && value <= max, `FixedRandom.nextInteger expected integer in range <${min};${max}>, got: ${value}`);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
nextNumber(min, max) {
|
|
30
|
+
assert(Number.isFinite(min), `min is expected to be a number, was: ${min}`);
|
|
31
|
+
assert(Number.isFinite(max), `max is expected to be a number, was: ${max}`);
|
|
32
|
+
assert(min < max, `expected min to be less than max, min=${min} max=${max}`);
|
|
33
|
+
const value = this.takeValue("nextNumber");
|
|
34
|
+
assert(Number.isFinite(value), `FixedRandom.nextNumber expected number, got: ${value}`);
|
|
35
|
+
assert(value >= min && value < max, `FixedRandom.nextNumber expected number in range <${min};${max}), got: ${value}`);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
nextBoolean() {
|
|
39
|
+
const value = this.takeValue("nextBoolean");
|
|
40
|
+
assert(typeof value === "boolean", `FixedRandom.nextBoolean expected boolean, got: ${value}`);
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PublicInterface } from "../types";
|
|
2
|
+
export type IRandom = PublicInterface<AbstractRandom>;
|
|
3
|
+
export declare abstract class AbstractRandom {
|
|
4
|
+
/**
|
|
5
|
+
* Returns next random number in range of <0;1)
|
|
6
|
+
*/
|
|
7
|
+
abstract next(): number;
|
|
8
|
+
/**
|
|
9
|
+
* Returns next random integer in range of <min;max>
|
|
10
|
+
*/
|
|
11
|
+
nextInteger(min: number, max: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Returns next random number in range of <min, max)
|
|
14
|
+
*/
|
|
15
|
+
nextNumber(min: number, max: number): number;
|
|
16
|
+
nextBoolean(): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Random.d.ts","sourceRoot":"","sources":["../../src/random/Random.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAI/C,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC,cAAc,CAAC,CAAA;AAErD,8BAAsB,cAAc;IAClC;;OAEG;IACH,QAAQ,CAAC,IAAI,IAAI,MAAM;IAEvB;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAc7C;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ5C,WAAW,IAAI,OAAO;CAGvB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { assert } from "../basic/assert.js";
|
|
2
|
+
export class AbstractRandom {
|
|
3
|
+
/**
|
|
4
|
+
* Returns next random integer in range of <min;max>
|
|
5
|
+
*/
|
|
6
|
+
nextInteger(min, max) {
|
|
7
|
+
assert(Number.isInteger(min) && !Number.isNaN(min), `min is expected to be an integer, was: ${min}`);
|
|
8
|
+
assert(Number.isInteger(max) && !Number.isNaN(max), `max is expected to be an integer, was: ${max}`);
|
|
9
|
+
assert(min < max, `expected min to be less than max, min=${min} max=${max}`);
|
|
10
|
+
return Math.floor(this.next() * (max - min + 1)) + min;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns next random number in range of <min, max)
|
|
14
|
+
*/
|
|
15
|
+
nextNumber(min, max) {
|
|
16
|
+
assert(Number.isFinite(min), `min is expected to be a number, was: ${min}`);
|
|
17
|
+
assert(Number.isFinite(max), `max is expected to be a number, was: ${max}`);
|
|
18
|
+
assert(min < max, `expected min to be less than max, min=${min} max=${max}`);
|
|
19
|
+
return this.next() * (max - min) + min;
|
|
20
|
+
}
|
|
21
|
+
nextBoolean() {
|
|
22
|
+
return this.nextInteger(0, 1) === 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RealRandom.d.ts","sourceRoot":"","sources":["../../src/random/RealRandom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEzC,qBAAa,UAAW,SAAQ,cAAc;IAC5C,IAAI,IAAI,MAAM;CAGf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SeededRandom.d.ts","sourceRoot":"","sources":["../../src/random/SeededRandom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEzC,qBAAa,YAAa,SAAQ,cAAc;IAC9C,OAAO,CAAC,CAAC,CAAU;IACnB,OAAO,CAAC,CAAC,CAAa;IACtB,OAAO,CAAC,CAAC,CAAQ;IACjB,OAAO,CAAC,KAAK,CAAQ;gBAET,IAAI,GAAE,MAAgB;IAK3B,IAAI,IAAI,MAAM;CAItB"}
|