superlib 1.0.20 → 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 -21
- package/tests/providers.js +0 -13
- package/tests/utilities.js +0 -13
- package/utilities.js +0 -116
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseError.d.ts","sourceRoot":"","sources":["../../src/basic/BaseError.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface TaggedError {
|
|
2
|
+
type: string;
|
|
3
|
+
}
|
|
4
|
+
export declare abstract class Result<V, E extends TaggedError> {
|
|
5
|
+
abstract isOk(): this is OkResult<V, E>;
|
|
6
|
+
abstract isErr(): this is ErrResult<V, E>;
|
|
7
|
+
abstract unwrap(): V;
|
|
8
|
+
abstract andThen<V2, E2 extends TaggedError>(mapper: (value: V) => Result<V2, E2>): Result<V2, E | E2>;
|
|
9
|
+
static try<V, E extends TaggedError>(fn: () => V, catchFn: (e: unknown) => E): Result<V, E>;
|
|
10
|
+
}
|
|
11
|
+
export declare class OkResult<V, E extends TaggedError> extends Result<V, E> {
|
|
12
|
+
readonly value: V;
|
|
13
|
+
constructor(value: V);
|
|
14
|
+
isOk(): this is OkResult<V, E>;
|
|
15
|
+
isErr(): this is ErrResult<V, E>;
|
|
16
|
+
unwrap(): V;
|
|
17
|
+
andThen<V2, E2 extends TaggedError>(mapper: (value: V) => Result<V2, E2>): Result<V2, E | E2>;
|
|
18
|
+
}
|
|
19
|
+
export declare class ErrResult<V, E extends TaggedError> extends Result<V, E> {
|
|
20
|
+
readonly err: E;
|
|
21
|
+
constructor(err: E);
|
|
22
|
+
isOk(): this is OkResult<V, E>;
|
|
23
|
+
isErr(): this is ErrResult<V, E>;
|
|
24
|
+
unwrap(): never;
|
|
25
|
+
andThen<V2, E2 extends TaggedError>(_mapper: (value: V) => Result<V2, E2>): Result<V2, E | E2>;
|
|
26
|
+
}
|
|
27
|
+
export declare function Ok<V = void>(value?: V): OkResult<V, never>;
|
|
28
|
+
export declare function Err<E extends TaggedError>(err: E): ErrResult<never, E>;
|
|
29
|
+
//# sourceMappingURL=Result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../src/basic/Result.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;CACb;AAED,8BAAsB,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW;IACnD,QAAQ,CAAC,IAAI,IAAI,IAAI,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,SAAS,WAAW,EACzC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GACnC,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;IAGrB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;CAO5F;AAED,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;aACtC,KAAK,EAAE,CAAC;gBAAR,KAAK,EAAE,CAAC;IAIpC,IAAI,IAAI,IAAI,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAI9B,KAAK,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IAIhC,MAAM,IAAI,CAAC;IAIF,OAAO,CAAC,EAAE,EAAE,EAAE,SAAS,WAAW,EACzC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GACnC,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;CAGtB;AAED,qBAAa,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;aACvC,GAAG,EAAE,CAAC;gBAAN,GAAG,EAAE,CAAC;IAIlC,IAAI,IAAI,IAAI,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IAI9B,KAAK,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IAIhC,MAAM,IAAI,KAAK;IAIN,OAAO,CAAC,EAAE,EAAE,EAAE,SAAS,WAAW,EACzC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GACpC,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;CAGtB;AAED,wBAAgB,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAE1D;AAED,wBAAgB,GAAG,CAAC,CAAC,SAAS,WAAW,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAEtE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export class Result {
|
|
2
|
+
// @todo: catchFn should be able to return Result<V,E> to turn exception into Ok
|
|
3
|
+
static try(fn, catchFn) {
|
|
4
|
+
try {
|
|
5
|
+
return Ok(fn());
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
return Err(catchFn(e));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class OkResult extends Result {
|
|
13
|
+
value;
|
|
14
|
+
constructor(value) {
|
|
15
|
+
super();
|
|
16
|
+
this.value = value;
|
|
17
|
+
}
|
|
18
|
+
isOk() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
isErr() {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
unwrap() {
|
|
25
|
+
return this.value;
|
|
26
|
+
}
|
|
27
|
+
andThen(mapper) {
|
|
28
|
+
return mapper(this.value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class ErrResult extends Result {
|
|
32
|
+
err;
|
|
33
|
+
constructor(err) {
|
|
34
|
+
super();
|
|
35
|
+
this.err = err;
|
|
36
|
+
}
|
|
37
|
+
isOk() {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
isErr() {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
unwrap() {
|
|
44
|
+
throw this.err;
|
|
45
|
+
}
|
|
46
|
+
andThen(_mapper) {
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function Ok(value) {
|
|
51
|
+
return new OkResult(value);
|
|
52
|
+
}
|
|
53
|
+
export function Err(err) {
|
|
54
|
+
return new ErrResult(err);
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Result, type TaggedError } from "./Result";
|
|
2
|
+
export declare class ResultAsync<V, E extends TaggedError> {
|
|
3
|
+
private readonly promisedResult;
|
|
4
|
+
constructor(promisedResult: Promise<Result<V, E>>);
|
|
5
|
+
andThen<V2, E2 extends TaggedError>(mapper: (value: V) => Result<V2, E2> | ResultAsync<V2, E2>): ResultAsync<V2, E | E2>;
|
|
6
|
+
toPromise(): Promise<Result<V, E>>;
|
|
7
|
+
static try<V, E extends TaggedError>(fn: () => Promise<V>, catchFn: (e: unknown) => E | Result<V, E>): ResultAsync<V, E>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ResultAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResultAsync.d.ts","sourceRoot":"","sources":["../../src/basic/ResultAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAA;AAE5D,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAElE,OAAO,CAAC,EAAE,EAAE,EAAE,SAAS,WAAW,EAChC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,GACzD,WAAW,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;IAiB1B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAIlC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACxC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;CAcrB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Err, Ok, Result } from "./Result.js";
|
|
2
|
+
export class ResultAsync {
|
|
3
|
+
promisedResult;
|
|
4
|
+
constructor(promisedResult) {
|
|
5
|
+
this.promisedResult = promisedResult;
|
|
6
|
+
}
|
|
7
|
+
andThen(mapper) {
|
|
8
|
+
const result = this.promisedResult.then(async (r) => {
|
|
9
|
+
if (r.isOk()) {
|
|
10
|
+
const result = mapper(r.value);
|
|
11
|
+
if (result instanceof Result) {
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return result.promisedResult;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return r;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return new ResultAsync(result);
|
|
23
|
+
}
|
|
24
|
+
toPromise() {
|
|
25
|
+
return this.promisedResult;
|
|
26
|
+
}
|
|
27
|
+
static try(fn, catchFn) {
|
|
28
|
+
const result = fn()
|
|
29
|
+
.then((v) => Ok(v))
|
|
30
|
+
.catch((e) => {
|
|
31
|
+
const r = catchFn(e);
|
|
32
|
+
if (r instanceof Result) {
|
|
33
|
+
return r;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return Err(r);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return new ResultAsync(result);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError";
|
|
2
|
+
export declare class AssertionError extends BaseError {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function assert(condition: boolean, error?: string | Error): asserts condition;
|
|
6
|
+
export declare function raise(error: string | Error): never;
|
|
7
|
+
export declare function assertNever(x: never): never;
|
|
8
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/basic/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,qBAAa,cAAe,SAAQ,SAAS;gBAC/B,OAAO,CAAC,EAAE,MAAM;CAO7B;AAED,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC,SAAS,CAIpF;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAMlD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAE3C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
export class AssertionError extends BaseError {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
if (message !== undefined) {
|
|
5
|
+
super(`assertion failed: ${message}`);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
super("assertion failed");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function assert(condition, error) {
|
|
13
|
+
if (!condition) {
|
|
14
|
+
raise(error ?? "Assertion failed");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function raise(error) {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
throw new AssertionError(error);
|
|
22
|
+
}
|
|
23
|
+
export function assertNever(x) {
|
|
24
|
+
throw new AssertionError(`assertNever: Unexpected object: ${x}`);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/basic/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type RetryDependencies, type RetryOptions } from "../task/retry";
|
|
2
|
+
export declare function Retry<TThis, TArgs extends unknown[], TResult>(options: RetryOptions<TResult>, dependencies?: RetryDependencies): (value: (this: TThis, ...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => Promise<TResult>>) => (this: TThis, ...args: TArgs) => Promise<TResult>;
|
|
3
|
+
//# sourceMappingURL=Retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Retry.d.ts","sourceRoot":"","sources":["../../src/decorators/Retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAGhF,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EAC3D,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAC9B,YAAY,CAAC,EAAE,iBAAiB,GAC/B,CACD,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EACxD,OAAO,EAAE,2BAA2B,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,KAC3F,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAMrD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { retry } from "../task/retry.js";
|
|
2
|
+
import { universalMethodDecorator } from "./common.js";
|
|
3
|
+
export function Retry(options, dependencies) {
|
|
4
|
+
return universalMethodDecorator((value) => {
|
|
5
|
+
return function (...args) {
|
|
6
|
+
return retry(() => value.apply(this, args), options, dependencies);
|
|
7
|
+
};
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type TimeoutOptions } from "../task/timeout";
|
|
2
|
+
export declare function Timeout<TThis, TArgs extends unknown[], TResult>(options: TimeoutOptions): (value: (this: TThis, ...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => Promise<TResult>>) => (this: TThis, ...args: TArgs) => Promise<TResult>;
|
|
3
|
+
//# sourceMappingURL=Timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Timeout.d.ts","sourceRoot":"","sources":["../../src/decorators/Timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAG9D,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,SAAS,OAAO,EAAE,EAAE,OAAO,EAC7D,OAAO,EAAE,cAAc,GACtB,CACD,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,EACxD,OAAO,EAAE,2BAA2B,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,KAC3F,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,OAAO,CAAC,CAMrD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { timeout } from "../task/timeout.js";
|
|
2
|
+
import { universalMethodDecorator } from "./common.js";
|
|
3
|
+
export function Timeout(options) {
|
|
4
|
+
return universalMethodDecorator((value) => {
|
|
5
|
+
return function (...args) {
|
|
6
|
+
return timeout(() => value.apply(this, args), options);
|
|
7
|
+
};
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/decorators/common.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,CAAC,gBAAgB,EAAE,QAAQ,KAAK,QAAQ,GAAG,GAAG,CAoBjG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { assert } from "../basic/index.js";
|
|
2
|
+
// bun only supports legacy TS decorator spec this function deals with all the inconsistencies and supports both standards at the same time
|
|
3
|
+
export function universalMethodDecorator(decorator) {
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
if (typeof context === "object" && context !== null && "kind" in context) {
|
|
6
|
+
assert(context.kind === "method", "Decorator can only be used on methods");
|
|
7
|
+
return decorator(value);
|
|
8
|
+
}
|
|
9
|
+
const descriptor = arguments[2];
|
|
10
|
+
assert(descriptor?.value instanceof Function, "Decorator can only be used on methods");
|
|
11
|
+
const original = descriptor.value;
|
|
12
|
+
return {
|
|
13
|
+
...descriptor,
|
|
14
|
+
value: decorator(original),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAA;AAEjC,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "../../schema/StandardSchema";
|
|
2
|
+
import { type Result } from "../../basic";
|
|
3
|
+
import { type ValidationError } from "../../schema/validateSchema";
|
|
4
|
+
import { type SafeFetch, type SafeFetchError } from "../safeFetch";
|
|
5
|
+
export type JsonHttpClientError = SafeFetchError | {
|
|
6
|
+
type: "jsonHttpClient/json-parse";
|
|
7
|
+
cause: unknown;
|
|
8
|
+
} | ValidationError;
|
|
9
|
+
export declare class JsonHttpClient {
|
|
10
|
+
private readonly safeFetch;
|
|
11
|
+
constructor(safeFetch?: SafeFetch);
|
|
12
|
+
private request;
|
|
13
|
+
get<T>(url: string, schema: StandardSchemaV1<T>): Promise<Result<T, JsonHttpClientError>>;
|
|
14
|
+
post<T>(url: string, body: unknown, schema: StandardSchemaV1<T>): Promise<Result<T, JsonHttpClientError>>;
|
|
15
|
+
patch<T>(url: string, body: unknown, schema: StandardSchemaV1<T>): Promise<Result<T, JsonHttpClientError>>;
|
|
16
|
+
delete<T>(url: string, schema: StandardSchemaV1<T>): Promise<Result<T, JsonHttpClientError>>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=JsonHttpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonHttpClient.d.ts","sourceRoot":"","sources":["../../../src/platform/JsonHttpClient/JsonHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClF,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAA;AAErB,MAAM,MAAM,mBAAmB,GAC3B,cAAc,GACd;IAAE,IAAI,EAAE,2BAA2B,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACrD,eAAe,CAAA;AAWnB,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,GAAE,SAAkD;YAE5E,OAAO;IAsBf,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAIzF,IAAI,CAAC,CAAC,EACV,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAOpC,KAAK,CAAC,CAAC,EACX,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAOpC,MAAM,CAAC,CAAC,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;CAG3C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ResultAsync } from "../../basic/index.js";
|
|
2
|
+
import { validateSchema } from "../../schema/validateSchema.js";
|
|
3
|
+
import { makeSafeFetch, } from "../safeFetch/index.js";
|
|
4
|
+
const defaultSafeFetchOptions = {
|
|
5
|
+
retry: {
|
|
6
|
+
times: 3,
|
|
7
|
+
delay: { milliseconds: 200 }, // @note: jittered by default
|
|
8
|
+
untilStatus: (status) => status >= 200 && status < 300,
|
|
9
|
+
},
|
|
10
|
+
timeout: { seconds: 5 },
|
|
11
|
+
};
|
|
12
|
+
export class JsonHttpClient {
|
|
13
|
+
safeFetch;
|
|
14
|
+
constructor(safeFetch = makeSafeFetch(defaultSafeFetchOptions)) {
|
|
15
|
+
this.safeFetch = safeFetch;
|
|
16
|
+
}
|
|
17
|
+
async request(url, schema, _requestInit) {
|
|
18
|
+
const requestInit = {
|
|
19
|
+
..._requestInit,
|
|
20
|
+
headers: { ...defaultHeaders, ..._requestInit?.headers },
|
|
21
|
+
};
|
|
22
|
+
return new ResultAsync(this.safeFetch(url, requestInit))
|
|
23
|
+
.andThen((response) => ResultAsync.try(() => response.json(), (err) => ({ type: "jsonHttpClient/json-parse", cause: err })))
|
|
24
|
+
.andThen((json) => {
|
|
25
|
+
return validateSchema(schema, json);
|
|
26
|
+
})
|
|
27
|
+
.toPromise();
|
|
28
|
+
}
|
|
29
|
+
async get(url, schema) {
|
|
30
|
+
return this.request(url, schema);
|
|
31
|
+
}
|
|
32
|
+
async post(url, body, schema) {
|
|
33
|
+
return this.request(url, schema, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify(body),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async patch(url, body, schema) {
|
|
39
|
+
return this.request(url, schema, {
|
|
40
|
+
method: "PATCH",
|
|
41
|
+
body: JSON.stringify(body),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async delete(url, schema) {
|
|
45
|
+
return this.request(url, schema, { method: "DELETE" });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const defaultHeaders = { "content-type": "application/json" };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/platform/JsonHttpClient/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./JsonHttpClient.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class EnvReader {
|
|
2
|
+
private readonly env;
|
|
3
|
+
constructor(env: Record<string, string | undefined>);
|
|
4
|
+
string(name: string, defaultValue?: string): string;
|
|
5
|
+
optionalString(name: string): string | undefined;
|
|
6
|
+
stringOf<T extends string[]>(key: string, allowedValues: readonly [...T], fallback?: T[number]): T[number];
|
|
7
|
+
number(name: string, defaultValue?: number): number;
|
|
8
|
+
optionalNumber(name: string): number | undefined;
|
|
9
|
+
boolean(name: string, defaultValue?: boolean): boolean;
|
|
10
|
+
optionalBoolean(name: string): boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=EnvReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvReader.d.ts","sourceRoot":"","sources":["../../../src/platform/ProcessContext/EnvReader.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAEpE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM;IAMnD,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIhD,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,EACzB,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,EAC9B,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GACnB,CAAC,CAAC,MAAM,CAAC;IAoBZ,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM;IAMnD,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAehD,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO;IAMtD,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;CAiBnD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { raise } from "../../basic/index.js";
|
|
2
|
+
export class EnvReader {
|
|
3
|
+
env;
|
|
4
|
+
constructor(env) {
|
|
5
|
+
this.env = env;
|
|
6
|
+
}
|
|
7
|
+
string(name, defaultValue) {
|
|
8
|
+
return (this.optionalString(name) ?? defaultValue ?? raise(`Environment variable ${name} not found`));
|
|
9
|
+
}
|
|
10
|
+
optionalString(name) {
|
|
11
|
+
return this.env[name];
|
|
12
|
+
}
|
|
13
|
+
stringOf(key, allowedValues, fallback) {
|
|
14
|
+
const value = this.optionalString(key);
|
|
15
|
+
if (value === undefined) {
|
|
16
|
+
return fallback ?? raise(`Environment variable ${key} not found`);
|
|
17
|
+
}
|
|
18
|
+
if (allowedValues.includes(value)) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
if (fallback !== undefined) {
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
raise(`Environment variable ${key} has invalid value "${value}". Allowed values: ${allowedValues.join(", ")}`);
|
|
25
|
+
}
|
|
26
|
+
number(name, defaultValue) {
|
|
27
|
+
return (this.optionalNumber(name) ?? defaultValue ?? raise(`Environment variable ${name} not found`));
|
|
28
|
+
}
|
|
29
|
+
optionalNumber(name) {
|
|
30
|
+
const value = this.optionalString(name);
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const parsed = Number(value);
|
|
35
|
+
if (Number.isNaN(parsed) || value.trim() === "") {
|
|
36
|
+
raise(`Environment variable ${name} has invalid number value "${value}"`);
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
}
|
|
40
|
+
boolean(name, defaultValue) {
|
|
41
|
+
return (this.optionalBoolean(name) ?? defaultValue ?? raise(`Environment variable ${name} not found`));
|
|
42
|
+
}
|
|
43
|
+
optionalBoolean(name) {
|
|
44
|
+
const value = this.optionalString(name);
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
if (value === "true" || value === "1" || value === "yes") {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (value === "false" || value === "0" || value === "no") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
raise(`Environment variable ${name} has invalid boolean value "${value}"`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AbsolutePath } from "../filesystem";
|
|
2
|
+
import { EnvReader } from "./EnvReader";
|
|
3
|
+
export interface IProcessContext {
|
|
4
|
+
readonly cwd: AbsolutePath;
|
|
5
|
+
readonly env: EnvReader;
|
|
6
|
+
readonly home: AbsolutePath;
|
|
7
|
+
pathFromCwd(path: string): AbsolutePath;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves and expands paths.
|
|
10
|
+
* - Absolute paths (e.g., "/usr/local") are returned as-is
|
|
11
|
+
* - Paths starting with "~" are resolved relative to home directory
|
|
12
|
+
* - All other paths are resolved relative to current working directory
|
|
13
|
+
*/
|
|
14
|
+
resolvePath(path: string): AbsolutePath;
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class AbstractProcessContext implements IProcessContext {
|
|
17
|
+
abstract readonly cwd: AbsolutePath;
|
|
18
|
+
abstract readonly env: EnvReader;
|
|
19
|
+
abstract readonly home: AbsolutePath;
|
|
20
|
+
pathFromCwd(path: string): AbsolutePath;
|
|
21
|
+
resolvePath(inputPath: string): AbsolutePath;
|
|
22
|
+
}
|
|
23
|
+
export declare class ProcessContext extends AbstractProcessContext {
|
|
24
|
+
readonly home: AbsolutePath;
|
|
25
|
+
readonly cwd: AbsolutePath;
|
|
26
|
+
readonly env: EnvReader;
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
export interface InMemoryProcessContextOptions {
|
|
30
|
+
cwd?: AbsolutePath;
|
|
31
|
+
home?: AbsolutePath;
|
|
32
|
+
env?: Dict<string>;
|
|
33
|
+
}
|
|
34
|
+
export declare class InMemoryProcessContext extends AbstractProcessContext {
|
|
35
|
+
readonly home: AbsolutePath;
|
|
36
|
+
readonly cwd: AbsolutePath;
|
|
37
|
+
readonly env: EnvReader;
|
|
38
|
+
constructor(options?: InMemoryProcessContextOptions);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ProcessContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessContext.d.ts","sourceRoot":"","sources":["../../../src/platform/ProcessContext/ProcessContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAA;IAC1B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAG3B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;IACvC;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;CACxC;AAED,8BAAsB,sBAAuB,YAAW,eAAe;IACrE,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;IAChC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAEpC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAIvC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;CA8B7C;AAED,qBAAa,cAAe,SAAQ,sBAAsB;IACxD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAiC;IAC5D,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAkC;IAC5D,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;;CAOxB;AAED,MAAM,WAAW,6BAA6B;IAC5C,GAAG,CAAC,EAAE,YAAY,CAAA;IAClB,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;CACnB;AAED,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAA;IAC1B,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAA;gBAEX,OAAO,CAAC,EAAE,6BAA6B;CAMpD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { assert } from "../../basic/assert.js";
|
|
4
|
+
import { AbsolutePath } from "../filesystem/index.js";
|
|
5
|
+
import { EnvReader } from "./EnvReader.js";
|
|
6
|
+
export class AbstractProcessContext {
|
|
7
|
+
pathFromCwd(path) {
|
|
8
|
+
return this.cwd.join(path);
|
|
9
|
+
}
|
|
10
|
+
resolvePath(inputPath) {
|
|
11
|
+
// Handle empty string
|
|
12
|
+
assert(inputPath !== "", "Path cannot be empty");
|
|
13
|
+
// Handle absolute paths
|
|
14
|
+
if (path.isAbsolute(inputPath)) {
|
|
15
|
+
return new AbsolutePath(inputPath);
|
|
16
|
+
}
|
|
17
|
+
// Handle home directory paths (~...)
|
|
18
|
+
if (inputPath.startsWith("~")) {
|
|
19
|
+
const pathAfterTilde = inputPath.slice(1);
|
|
20
|
+
// Handle ~ alone or ~/
|
|
21
|
+
if (pathAfterTilde === "" || pathAfterTilde === "/") {
|
|
22
|
+
return this.home;
|
|
23
|
+
}
|
|
24
|
+
// Handle ~/path
|
|
25
|
+
if (pathAfterTilde.startsWith("/")) {
|
|
26
|
+
return this.home.join(pathAfterTilde);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Handle all other paths as relative to cwd
|
|
30
|
+
// This includes paths like:
|
|
31
|
+
// - ./file.txt
|
|
32
|
+
// - ../parent
|
|
33
|
+
// - file.txt
|
|
34
|
+
// - subdir/file.txt
|
|
35
|
+
return this.cwd.join(inputPath);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class ProcessContext extends AbstractProcessContext {
|
|
39
|
+
home = new AbsolutePath(os.homedir());
|
|
40
|
+
cwd = new AbsolutePath(process.cwd());
|
|
41
|
+
env;
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
this.env = new EnvReader(process.env);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class InMemoryProcessContext extends AbstractProcessContext {
|
|
48
|
+
home;
|
|
49
|
+
cwd;
|
|
50
|
+
env;
|
|
51
|
+
constructor(options) {
|
|
52
|
+
super();
|
|
53
|
+
this.home = options?.home ?? new AbsolutePath("/home");
|
|
54
|
+
this.cwd = options?.cwd ?? new AbsolutePath("/home/workspace");
|
|
55
|
+
this.env = new EnvReader(options?.env ?? {});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/platform/ProcessContext/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare class AbsolutePathClazz {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
constructor(path: string);
|
|
4
|
+
join(...paths: Array<string>): AbsolutePath;
|
|
5
|
+
dirname(): AbsolutePath;
|
|
6
|
+
/**
|
|
7
|
+
* Note: this returns string representing relative path
|
|
8
|
+
*/
|
|
9
|
+
relativeFrom(root: AbsolutePath): string;
|
|
10
|
+
}
|
|
11
|
+
declare function AbsolutePathClass(absolutePath: string): AbsolutePathClazz;
|
|
12
|
+
declare namespace AbsolutePathClass {
|
|
13
|
+
var prototype: AbsolutePathClazz;
|
|
14
|
+
}
|
|
15
|
+
export declare const AbsolutePath: typeof AbsolutePathClass & typeof AbsolutePathClazz;
|
|
16
|
+
export type AbsolutePath = InstanceType<typeof AbsolutePathClazz>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=AbsolutePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbsolutePath.d.ts","sourceRoot":"","sources":["../../../src/platform/filesystem/AbsolutePath.ts"],"names":[],"mappings":"AAGA,cAAM,iBAAiB;IACrB,SAAgB,IAAI,EAAE,MAAM,CAAA;gBAEhB,IAAI,EAAE,MAAM;IAMxB,IAAI,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,YAAY;IAI3C,OAAO,IAAI,YAAY;IAIvB;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM;CAGzC;AAED,iBAAS,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,iBAAiB,CAElE;kBAFQ,iBAAiB;;;AAM1B,eAAO,MAAM,YAAY,qDAAsD,CAAA;AAC/E,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,iBAAiB,CAAC,CAAA"}
|