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,15 @@
|
|
|
1
|
+
import { AbstractRandom } from "./Random.js";
|
|
2
|
+
export class SeededRandom extends AbstractRandom {
|
|
3
|
+
m = 2 ** 31;
|
|
4
|
+
a = 1103515245;
|
|
5
|
+
c = 12345;
|
|
6
|
+
state;
|
|
7
|
+
constructor(seed = 4202137) {
|
|
8
|
+
super();
|
|
9
|
+
this.state = seed >>> 0; // force to uint32
|
|
10
|
+
}
|
|
11
|
+
next() {
|
|
12
|
+
this.state = (this.a * this.state + this.c) % this.m;
|
|
13
|
+
return this.state / this.m;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/random/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The Standard Schema interface. */
|
|
2
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
|
+
/** The Standard Schema properties. */
|
|
4
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace StandardSchemaV1 {
|
|
7
|
+
/** The Standard Schema properties interface. */
|
|
8
|
+
interface Props<Input = unknown, Output = Input> {
|
|
9
|
+
/** The version number of the standard. */
|
|
10
|
+
readonly version: 1;
|
|
11
|
+
/** The vendor name of the schema library. */
|
|
12
|
+
readonly vendor: string;
|
|
13
|
+
/** Validates unknown input values. */
|
|
14
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options) => Result<Output> | Promise<Result<Output>>;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The result interface of the validate function. */
|
|
19
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
|
+
/** The result interface if validation succeeds. */
|
|
21
|
+
interface SuccessResult<Output> {
|
|
22
|
+
/** The typed output value. */
|
|
23
|
+
readonly value: Output;
|
|
24
|
+
/** A falsy value for `issues` indicates success. */
|
|
25
|
+
readonly issues?: undefined;
|
|
26
|
+
}
|
|
27
|
+
interface Options {
|
|
28
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
29
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** The result interface if validation fails. */
|
|
32
|
+
interface FailureResult {
|
|
33
|
+
/** The issues of failed validation. */
|
|
34
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
35
|
+
}
|
|
36
|
+
/** The issue interface of the failure output. */
|
|
37
|
+
interface Issue {
|
|
38
|
+
/** The error message of the issue. */
|
|
39
|
+
readonly message: string;
|
|
40
|
+
/** The path of the issue, if any. */
|
|
41
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** The path segment interface of the issue. */
|
|
44
|
+
interface PathSegment {
|
|
45
|
+
/** The key representing a path segment. */
|
|
46
|
+
readonly key: PropertyKey;
|
|
47
|
+
}
|
|
48
|
+
/** The Standard Schema types interface. */
|
|
49
|
+
interface Types<Input = unknown, Output = Input> {
|
|
50
|
+
/** The input type of the schema. */
|
|
51
|
+
readonly input: Input;
|
|
52
|
+
/** The output type of the schema. */
|
|
53
|
+
readonly output: Output;
|
|
54
|
+
}
|
|
55
|
+
/** Infers the input type of a Standard Schema. */
|
|
56
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
57
|
+
/** Infers the output type of a Standard Schema. */
|
|
58
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=StandardSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardSchema.d.ts","sourceRoot":"","sources":["../../src/schema/StandardSchema.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,sCAAsC;IACtC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;CAC5D;AAED,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC,gDAAgD;IAChD,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,0CAA0C;QAC1C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;QACnB,6CAA6C;QAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,sCAAsC;QACtC,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,KAC/B,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QAC7C,iDAAiD;QACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;KAClD;IAED,qDAAqD;IACrD,KAAY,MAAM,CAAC,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAA;IAElE,mDAAmD;IACnD,UAAiB,aAAa,CAAC,MAAM;QACnC,8BAA8B;QAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;QACtB,oDAAoD;QACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAC5B;IAED,UAAiB,OAAO;QACtB,6EAA6E;QAC7E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;KAC9D;IAED,gDAAgD;IAChD,UAAiB,aAAa;QAC5B,uCAAuC;QACvC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;KACtC;IAED,iDAAiD;IACjD,UAAiB,KAAK;QACpB,sCAAsC;QACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;QACxB,qCAAqC;QACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,SAAS,CAAA;KACrE;IAED,+CAA+C;IAC/C,UAAiB,WAAW;QAC1B,2CAA2C;QAC3C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAA;KAC1B;IAED,2CAA2C;IAC3C,UAAiB,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,oCAAoC;QACpC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;QACrB,qCAAqC;QACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KACxB;IAED,kDAAkD;IAClD,KAAY,UAAU,CAAC,MAAM,SAAS,gBAAgB,IAAI,WAAW,CACnE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,OAAO,CAAC,CAAA;IAEV,mDAAmD;IACnD,KAAY,WAAW,CAAC,MAAM,SAAS,gBAAgB,IAAI,WAAW,CACpE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,QAAQ,CAAC,CAAA;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "./StandardSchema";
|
|
2
|
+
import { type Result } from "../basic";
|
|
3
|
+
export type ValidationError = {
|
|
4
|
+
type: "schema/validate";
|
|
5
|
+
issue: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
6
|
+
};
|
|
7
|
+
export type ValidateSchemaResult<T> = Result<T, ValidationError>;
|
|
8
|
+
export declare function validateSchema<T>(schema: StandardSchemaV1<T>, value: unknown): ValidateSchemaResult<T>;
|
|
9
|
+
//# sourceMappingURL=validateSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateSchema.d.ts","sourceRoot":"","sources":["../../src/schema/validateSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAmB,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AAEvD,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,iBAAiB,CAAA;IACvB,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;CAC7C,CAAA;AACD,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,eAAe,CAAC,CAAA;AAEhE,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC3B,KAAK,EAAE,OAAO,GACb,oBAAoB,CAAC,CAAC,CAAC,CAUzB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { assert, Err, Ok } from "../basic/index.js";
|
|
2
|
+
export function validateSchema(schema, value) {
|
|
3
|
+
const result = schema["~standard"].validate(value);
|
|
4
|
+
assert(!(result instanceof Promise), "Only sync validation supported at the moment");
|
|
5
|
+
if (result.issues) {
|
|
6
|
+
return Err({ type: "schema/validate", issue: result.issues });
|
|
7
|
+
}
|
|
8
|
+
return Ok(result.value);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Task } from "./types";
|
|
2
|
+
export type AllOptions = {
|
|
3
|
+
concurrency: number | `batches-of-${number}` | "unbounded";
|
|
4
|
+
};
|
|
5
|
+
export declare function all<T extends unknown[]>(tasks: {
|
|
6
|
+
[K in keyof T]: Task<T[K]>;
|
|
7
|
+
}, options: AllOptions): Promise<{
|
|
8
|
+
[K in keyof T]: Awaited<T[K]>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function all<K extends PropertyKey, R extends Record<K, Task<unknown>>>(tasks: R, options: AllOptions): Promise<{
|
|
11
|
+
[P in keyof R]: Awaited<ReturnType<R[P]>>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function allWithArray<T>(tasks: ReadonlyArray<Task<T>>, options: AllOptions): Promise<T[]>;
|
|
14
|
+
//# sourceMappingURL=all.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/task/all.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAInC,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,GAAG,cAAc,MAAM,EAAE,GAAG,WAAW,CAAA;CAC3D,CAAA;AAED,wBAAsB,GAAG,CAAC,CAAC,SAAS,OAAO,EAAE,EAC3C,KAAK,EAAE;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,EACrC,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAA;AAE7C,wBAAsB,GAAG,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,EACjF,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAA;AA4BzD,wBAAsB,YAAY,CAAC,CAAC,EAClC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAC7B,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,CAAC,EAAE,CAAC,CAsDd"}
|
package/dist/task/all.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { chunk, zip } from "remeda";
|
|
2
|
+
import { assert } from "../basic/index.js";
|
|
3
|
+
export async function all(taskArrayOrObject, options) {
|
|
4
|
+
if (Array.isArray(taskArrayOrObject)) {
|
|
5
|
+
return allWithArray(taskArrayOrObject, options);
|
|
6
|
+
}
|
|
7
|
+
const entries = Object.entries(taskArrayOrObject);
|
|
8
|
+
const keys = entries.map((e) => e[0]);
|
|
9
|
+
const values = entries.map((e) => e[1]);
|
|
10
|
+
const result = await allWithArray(values, options);
|
|
11
|
+
const resultObject = Object.fromEntries(zip(keys, result));
|
|
12
|
+
return resultObject;
|
|
13
|
+
}
|
|
14
|
+
function assertPositiveIntegerConcurrency(value) {
|
|
15
|
+
assert(value > 0 && Number.isFinite(value) && Number.isInteger(value), `options.concurrency must be a positive integer (got ${value})`);
|
|
16
|
+
}
|
|
17
|
+
export async function allWithArray(tasks, options) {
|
|
18
|
+
if (options.concurrency === "unbounded" || options.concurrency === Number.POSITIVE_INFINITY) {
|
|
19
|
+
return Promise.all(tasks.map((t) => t()));
|
|
20
|
+
}
|
|
21
|
+
if (typeof options.concurrency === "string" && options.concurrency.startsWith("batches-of-")) {
|
|
22
|
+
const batchSizeRaw = Number(options.concurrency.slice("batches-of-".length));
|
|
23
|
+
assertPositiveIntegerConcurrency(batchSizeRaw);
|
|
24
|
+
const batchSize = batchSizeRaw;
|
|
25
|
+
const chunks = chunk(tasks, batchSize);
|
|
26
|
+
let result = [];
|
|
27
|
+
for (const c of chunks) {
|
|
28
|
+
result = result.concat(await allWithArray(c, { concurrency: "unbounded" }));
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
const concurrency = options.concurrency;
|
|
33
|
+
assertPositiveIntegerConcurrency(concurrency);
|
|
34
|
+
if (tasks.length === 0) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const results = Array.from({ length: tasks.length });
|
|
38
|
+
let nextIndex = 0;
|
|
39
|
+
let cancelled = false; // prevent extra scheduling after a failure
|
|
40
|
+
async function worker() {
|
|
41
|
+
while (true) {
|
|
42
|
+
if (cancelled) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const i = nextIndex++;
|
|
46
|
+
if (i >= tasks.length) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
results[i] = await tasks[i]();
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
cancelled = true;
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const workerCount = Math.min(concurrency, tasks.length);
|
|
59
|
+
await Promise.all(Array.from({ length: workerCount }, worker));
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { all } from "./all";
|
|
2
|
+
import { pipe } from "./pipe";
|
|
3
|
+
import { retry } from "./retry";
|
|
4
|
+
import { timeout } from "./timeout";
|
|
5
|
+
import { type Task as TaskTypeReexport } from "./types";
|
|
6
|
+
export declare const Task: {
|
|
7
|
+
all: typeof all;
|
|
8
|
+
pipe: typeof pipe;
|
|
9
|
+
retry: typeof retry;
|
|
10
|
+
timeout: typeof timeout;
|
|
11
|
+
};
|
|
12
|
+
export declare namespace Task {
|
|
13
|
+
type Task<T> = TaskTypeReexport<T>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,KAAK,IAAI,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEvD,eAAO,MAAM,IAAI;;;;;CAKhB,CAAA;AAED,yBAAiB,IAAI,CAAC;IACpB,KAAY,IAAI,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAC1C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Task, TaskMapper } from "./types";
|
|
2
|
+
export declare function pipe<A>(task: Task<A>): Promise<A>;
|
|
3
|
+
export declare function pipe<A, B>(task: Task<A>, m1: TaskMapper<A, B> | undefined): Promise<B>;
|
|
4
|
+
export declare function pipe<A, B, C>(task: Task<A>, m1: TaskMapper<A, B> | undefined, m2: TaskMapper<B, C> | undefined): Promise<C>;
|
|
5
|
+
export declare function pipe<A, B, C, D>(task: Task<A>, m1: TaskMapper<A, B> | undefined, m2: TaskMapper<B, C> | undefined, m3: TaskMapper<C, D> | undefined): Promise<D>;
|
|
6
|
+
export declare function pipe<A, B, C, D, E>(task: Task<A>, m1: TaskMapper<A, B> | undefined, m2: TaskMapper<B, C> | undefined, m3: TaskMapper<C, D> | undefined, m4: TaskMapper<D, E> | undefined): Promise<E>;
|
|
7
|
+
export declare function pipe<A, B, C, D, E, F>(task: Task<A>, m1: TaskMapper<A, B> | undefined, m2: TaskMapper<B, C> | undefined, m3: TaskMapper<C, D> | undefined, m4: TaskMapper<D, E> | undefined, m5: TaskMapper<E, F> | undefined): Promise<F>;
|
|
8
|
+
//# sourceMappingURL=pipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../../src/task/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/C,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAClD,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AACvF,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC1B,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,GAC/B,OAAO,CAAC,CAAC,CAAC,CAAA;AACb,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAC7B,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,GAC/B,OAAO,CAAC,CAAC,CAAC,CAAA;AACb,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAChC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,GAC/B,OAAO,CAAC,CAAC,CAAC,CAAA;AACb,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EACnC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAChC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,GAC/B,OAAO,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Task, TaskMapper } from "./types";
|
|
2
|
+
import { ErrResult, Result } from "../basic";
|
|
3
|
+
import { type IRandom } from "../random";
|
|
4
|
+
import { type DurationLike } from "../time";
|
|
5
|
+
export type ErrResultOrError<T> = T extends Result<any, infer E> ? ErrResult<unknown, E> : unknown;
|
|
6
|
+
export interface RetryOptions<R> {
|
|
7
|
+
until?: (error: ErrResultOrError<R>) => boolean;
|
|
8
|
+
times: number;
|
|
9
|
+
delay: DurationLike | RetryDelayPolicy;
|
|
10
|
+
}
|
|
11
|
+
export type RetryDelayPolicy = (attempt: number) => DurationLike;
|
|
12
|
+
export interface RetryDependencies {
|
|
13
|
+
random: IRandom;
|
|
14
|
+
}
|
|
15
|
+
export declare function retry<T>(task: Task<T>, options: RetryOptions<T>, dependencies?: RetryDependencies): Promise<T>;
|
|
16
|
+
export declare function retry<T>(options: RetryOptions<T>, dependencies?: RetryDependencies): TaskMapper<T, T>;
|
|
17
|
+
export declare function ExponentialBackoffRetryPolicy(base: DurationLike): RetryDelayPolicy;
|
|
18
|
+
interface JitteredRetryOptions {
|
|
19
|
+
minFactor?: number;
|
|
20
|
+
maxFactor?: number;
|
|
21
|
+
}
|
|
22
|
+
interface JitteredRetryDependencies {
|
|
23
|
+
random: IRandom;
|
|
24
|
+
}
|
|
25
|
+
export declare function JitteredRetryPolicy(base: DurationLike | RetryDelayPolicy, options?: JitteredRetryOptions, dependencies?: JitteredRetryDependencies): RetryDelayPolicy;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/task/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,EAAU,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,WAAW,CAAA;AACpD,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAEpE,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,OAAO,CAAA;AAElG,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAA;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,YAAY,GAAG,gBAAgB,CAAA;CACvC;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,YAAY,CAAA;AAEhE,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,YAAY,CAAC,EAAE,iBAAiB,GAC/B,OAAO,CAAC,CAAC,CAAC,CAAA;AACb,wBAAgB,KAAK,CAAC,CAAC,EACrB,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,YAAY,CAAC,EAAE,iBAAiB,GAC/B,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAqDnB,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,YAAY,GAAG,gBAAgB,CAKlF;AAED,UAAU,oBAAoB;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,UAAU,yBAAyB;IACjC,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,YAAY,GAAG,gBAAgB,EACrC,OAAO,CAAC,EAAE,oBAAoB,EAC9B,YAAY,CAAC,EAAE,yBAAyB,GACvC,gBAAgB,CAgBlB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { assert, ErrResult, Result } from "../basic/index.js";
|
|
2
|
+
import { RealRandom } from "../random/index.js";
|
|
3
|
+
import { multiplyDuration, sleep } from "../time/index.js";
|
|
4
|
+
export function retry(taskOrOptions, optionsOrDependencies, dependencies) {
|
|
5
|
+
if (typeof taskOrOptions === "function") {
|
|
6
|
+
return runRetry(taskOrOptions, optionsOrDependencies, dependencies);
|
|
7
|
+
}
|
|
8
|
+
return (task) => () => runRetry(task, taskOrOptions, optionsOrDependencies);
|
|
9
|
+
}
|
|
10
|
+
async function runRetry(task, options, dependencies) {
|
|
11
|
+
const until = options.until ?? (() => true);
|
|
12
|
+
const delay = options.delay instanceof Function
|
|
13
|
+
? options.delay
|
|
14
|
+
: JitteredRetryPolicy(ExponentialBackoffRetryPolicy(options.delay), {}, dependencies);
|
|
15
|
+
let attempt = 0;
|
|
16
|
+
while (true) {
|
|
17
|
+
let thrownError = undefined;
|
|
18
|
+
let resultError = undefined;
|
|
19
|
+
try {
|
|
20
|
+
const result = await task();
|
|
21
|
+
if (!(result instanceof Result) || result.isOk()) {
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
resultError = result;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
thrownError = error;
|
|
28
|
+
}
|
|
29
|
+
assert(!!(thrownError || resultError));
|
|
30
|
+
if (attempt < options.times && until(thrownError || resultError)) {
|
|
31
|
+
const sleepDuration = delay(attempt++);
|
|
32
|
+
await sleep(sleepDuration);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (thrownError) {
|
|
36
|
+
throw thrownError;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return resultError;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function ExponentialBackoffRetryPolicy(base) {
|
|
45
|
+
const baseDuration = Temporal.Duration.from(base);
|
|
46
|
+
return (attempt) => {
|
|
47
|
+
return multiplyDuration(baseDuration, 2 ** attempt);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function JitteredRetryPolicy(base, options, dependencies) {
|
|
51
|
+
const random = dependencies?.random ?? new RealRandom();
|
|
52
|
+
const minFactor = options?.minFactor ?? 0;
|
|
53
|
+
const maxFactor = options?.maxFactor ?? 1;
|
|
54
|
+
assert(minFactor >= 0 && maxFactor > minFactor, `invalid jitter range: min=${minFactor} max=${maxFactor}`);
|
|
55
|
+
const basePolicy = base instanceof Function ? base : () => base;
|
|
56
|
+
return (attempt) => {
|
|
57
|
+
const baseDuration = Temporal.Duration.from(basePolicy(attempt));
|
|
58
|
+
const factor = random.nextNumber(minFactor, maxFactor);
|
|
59
|
+
return multiplyDuration(baseDuration, factor);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Task, TaskMapper } from "./types";
|
|
2
|
+
import { BaseError, Result } from "../basic";
|
|
3
|
+
import { type DurationLike } from "../time";
|
|
4
|
+
export interface TimeoutOptions {
|
|
5
|
+
timeout: DurationLike;
|
|
6
|
+
useResult?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type TimeoutErr = {
|
|
9
|
+
type: "timeout";
|
|
10
|
+
timeout: Temporal.Duration;
|
|
11
|
+
};
|
|
12
|
+
type TimeoutAsResult<Return, Options> = Options extends {
|
|
13
|
+
useResult: true;
|
|
14
|
+
} ? Return extends Result<infer V, infer E> ? Result<V, E | TimeoutErr> : never : Return;
|
|
15
|
+
export declare function timeout<T, O extends TimeoutOptions>(task: Task<T>, options: O): Promise<TimeoutAsResult<T, O>>;
|
|
16
|
+
export declare function timeout<T, O extends TimeoutOptions>(options: O): TaskMapper<T, TimeoutAsResult<T, O>>;
|
|
17
|
+
export declare class TimeoutError extends BaseError {
|
|
18
|
+
constructor(duration: Temporal.Duration);
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/task/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAkB,MAAM,EAAE,MAAM,UAAU,CAAA;AAC5D,OAAO,EAAqC,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAI9E,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,YAAY,CAAA;IACrB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAA;CAAE,CAAA;AAExE,KAAK,eAAe,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,SAAS;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,GACvE,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GACrC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,GACzB,KAAK,GACP,MAAM,CAAA;AAGV,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,cAAc,EACjD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,OAAO,EAAE,CAAC,GACT,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACjC,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,cAAc,EACjD,OAAO,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AA4CvC,qBAAa,YAAa,SAAQ,SAAS;gBAC7B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;CAGxC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseError, Err, ErrResult, Result } from "../basic/index.js";
|
|
2
|
+
import { durationToMs, prettyPrintDuration } from "../time/index.js";
|
|
3
|
+
const { setTimeout, clearTimeout: cancelTimeout } = globalThis;
|
|
4
|
+
export function timeout(taskOrOptions, options) {
|
|
5
|
+
if (typeof taskOrOptions === "function") {
|
|
6
|
+
return runTimeout(taskOrOptions, options);
|
|
7
|
+
}
|
|
8
|
+
return (task) => () => runTimeout(task, taskOrOptions);
|
|
9
|
+
}
|
|
10
|
+
async function runTimeout(task, options) {
|
|
11
|
+
const useResult = !!options.useResult;
|
|
12
|
+
const timeoutDuration = Temporal.Duration.from(options.timeout);
|
|
13
|
+
const timeoutMs = durationToMs(timeoutDuration);
|
|
14
|
+
// note: we can't use sleep here because we want to ensure timeoutPromise cancellation
|
|
15
|
+
let timeoutId = undefined;
|
|
16
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
17
|
+
timeoutId = setTimeout(() => {
|
|
18
|
+
reject(new TimeoutError(timeoutDuration));
|
|
19
|
+
}, timeoutMs);
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
return (await Promise.race([task(), timeoutPromise]).catch((e) => {
|
|
23
|
+
if (useResult) {
|
|
24
|
+
return Err({ type: "timeout", timeout: timeoutDuration });
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (timeoutId !== undefined) {
|
|
31
|
+
cancelTimeout(timeoutId);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class TimeoutError extends BaseError {
|
|
36
|
+
constructor(duration) {
|
|
37
|
+
super(`Task has timeout after ${prettyPrintDuration(duration)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/task/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;AAEtC,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PublicInterface } from "../types";
|
|
2
|
+
import type { DurationLike } from "./index";
|
|
3
|
+
export type IClock = PublicInterface<AbstractClock>;
|
|
4
|
+
export declare abstract class AbstractClock implements IClock {
|
|
5
|
+
abstract now(): Temporal.Instant;
|
|
6
|
+
nowDate(): Date;
|
|
7
|
+
}
|
|
8
|
+
export declare class Clock extends AbstractClock {
|
|
9
|
+
now(): Temporal.Instant;
|
|
10
|
+
}
|
|
11
|
+
export declare class TestClock extends AbstractClock {
|
|
12
|
+
private _now;
|
|
13
|
+
constructor(_now: Temporal.Instant);
|
|
14
|
+
now(): Temporal.Instant;
|
|
15
|
+
advance(duration: DurationLike): void;
|
|
16
|
+
reset(now: Temporal.Instant): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Clock.d.ts","sourceRoot":"","sources":["../../src/time/Clock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,CAAA;AAEnD,8BAAsB,aAAc,YAAW,MAAM;IACnD,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,OAAO;IAEhC,OAAO,IAAI,IAAI;CAGhB;AAED,qBAAa,KAAM,SAAQ,aAAa;IACtC,GAAG,IAAI,QAAQ,CAAC,OAAO;CAGxB;AAED,qBAAa,SAAU,SAAQ,aAAa;IAC9B,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,QAAQ,CAAC,OAAO;IAI1C,GAAG,IAAI,QAAQ,CAAC,OAAO;IAIvB,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAIrC,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,IAAI;CAGnC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class AbstractClock {
|
|
2
|
+
nowDate() {
|
|
3
|
+
return new Date(this.now().epochMilliseconds);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export class Clock extends AbstractClock {
|
|
7
|
+
now() {
|
|
8
|
+
return Temporal.Now.instant();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class TestClock extends AbstractClock {
|
|
12
|
+
_now;
|
|
13
|
+
constructor(_now) {
|
|
14
|
+
super();
|
|
15
|
+
this._now = _now;
|
|
16
|
+
}
|
|
17
|
+
now() {
|
|
18
|
+
return this._now;
|
|
19
|
+
}
|
|
20
|
+
advance(duration) {
|
|
21
|
+
this._now = this._now.add(Temporal.Duration.from(duration));
|
|
22
|
+
}
|
|
23
|
+
reset(now) {
|
|
24
|
+
this._now = now;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/time/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/time/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAEzD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAI3D"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type DurationLike = Omit<Temporal.DurationLike, "microseconds" | "nanoseconds"> | Omit<Temporal.Duration, "microseconds" | "nanoseconds">;
|
|
2
|
+
export declare function multiplyDuration(base: Temporal.Duration, factor: number): Temporal.Duration;
|
|
3
|
+
export declare function durationToMs(duration: Temporal.Duration): number;
|
|
4
|
+
export declare function prettyPrintDuration(duration: Temporal.Duration): string;
|
|
5
|
+
//# sourceMappingURL=temporal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal.d.ts","sourceRoot":"","sources":["../../src/time/temporal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACpB,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,cAAc,GAAG,aAAa,CAAC,GAC3D,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,aAAa,CAAC,CAAA;AAE3D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAW3F;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAIhE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAEvE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function multiplyDuration(base, factor) {
|
|
2
|
+
return Temporal.Duration.from({
|
|
3
|
+
years: Math.round(base.years * factor),
|
|
4
|
+
months: Math.round(base.months * factor),
|
|
5
|
+
weeks: Math.round(base.weeks * factor),
|
|
6
|
+
days: Math.round(base.days * factor),
|
|
7
|
+
hours: Math.round(base.hours * factor),
|
|
8
|
+
minutes: Math.round(base.minutes * factor),
|
|
9
|
+
seconds: Math.round(base.seconds * factor),
|
|
10
|
+
milliseconds: Math.round(base.milliseconds * factor),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function durationToMs(duration) {
|
|
14
|
+
const now = Temporal.Now.instant();
|
|
15
|
+
const target = now.add(Temporal.Duration.from(duration));
|
|
16
|
+
return target.epochMilliseconds - now.epochMilliseconds;
|
|
17
|
+
}
|
|
18
|
+
export function prettyPrintDuration(duration) {
|
|
19
|
+
return new Intl.DurationFormat("en", { style: "narrow" }).format(duration); // @todo polyfill typings are off
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|