barely-effect 0.1.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.
Files changed (89) hide show
  1. package/README.md +1 -0
  2. package/dist/ansi-colors/ansiColors.d.ts +11 -0
  3. package/dist/ansi-colors/ansiColors.d.ts.map +1 -0
  4. package/dist/ansi-colors/ansiColors.js +15 -0
  5. package/dist/ansi-colors/index.d.ts +2 -0
  6. package/dist/ansi-colors/index.d.ts.map +1 -0
  7. package/dist/ansi-colors/index.js +1 -0
  8. package/dist/assert.d.ts +10 -0
  9. package/dist/assert.d.ts.map +1 -0
  10. package/dist/assert.js +30 -0
  11. package/dist/index.d.ts +13 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +12 -0
  14. package/dist/logger/LogFormatterJson.d.ts +5 -0
  15. package/dist/logger/LogFormatterJson.d.ts.map +1 -0
  16. package/dist/logger/LogFormatterJson.js +19 -0
  17. package/dist/logger/LogFormatterPretty.d.ts +17 -0
  18. package/dist/logger/LogFormatterPretty.d.ts.map +1 -0
  19. package/dist/logger/LogFormatterPretty.js +88 -0
  20. package/dist/logger/LogLevel.d.ts +4 -0
  21. package/dist/logger/LogLevel.d.ts.map +1 -0
  22. package/dist/logger/LogLevel.js +5 -0
  23. package/dist/logger/Logger.d.ts +36 -0
  24. package/dist/logger/Logger.d.ts.map +1 -0
  25. package/dist/logger/Logger.js +115 -0
  26. package/dist/logger/index.d.ts +7 -0
  27. package/dist/logger/index.d.ts.map +1 -0
  28. package/dist/logger/index.js +5 -0
  29. package/dist/logger/parseLogArguments.d.ts +7 -0
  30. package/dist/logger/parseLogArguments.d.ts.map +1 -0
  31. package/dist/logger/parseLogArguments.js +51 -0
  32. package/dist/logger/resolveError.d.ts +7 -0
  33. package/dist/logger/resolveError.d.ts.map +1 -0
  34. package/dist/logger/resolveError.js +13 -0
  35. package/dist/logger/types.d.ts +38 -0
  36. package/dist/logger/types.d.ts.map +1 -0
  37. package/dist/logger/types.js +3 -0
  38. package/dist/networking/HttpClient.d.ts +78 -0
  39. package/dist/networking/HttpClient.d.ts.map +1 -0
  40. package/dist/networking/HttpClient.js +77 -0
  41. package/dist/networking/index.d.ts +2 -0
  42. package/dist/networking/index.d.ts.map +1 -0
  43. package/dist/networking/index.js +1 -0
  44. package/dist/platform/filesystem/AbsolutePath.d.ts +18 -0
  45. package/dist/platform/filesystem/AbsolutePath.d.ts.map +1 -0
  46. package/dist/platform/filesystem/AbsolutePath.js +41 -0
  47. package/dist/platform/filesystem/FileSystem.d.ts +30 -0
  48. package/dist/platform/filesystem/FileSystem.d.ts.map +1 -0
  49. package/dist/platform/filesystem/FileSystem.js +129 -0
  50. package/dist/platform/filesystem/IFileSystem.d.ts +98 -0
  51. package/dist/platform/filesystem/IFileSystem.d.ts.map +1 -0
  52. package/dist/platform/filesystem/IFileSystem.js +19 -0
  53. package/dist/platform/filesystem/KeyedMap.d.ts +23 -0
  54. package/dist/platform/filesystem/KeyedMap.d.ts.map +1 -0
  55. package/dist/platform/filesystem/KeyedMap.js +59 -0
  56. package/dist/platform/filesystem/MemoryFileSystem.d.ts +42 -0
  57. package/dist/platform/filesystem/MemoryFileSystem.d.ts.map +1 -0
  58. package/dist/platform/filesystem/MemoryFileSystem.js +200 -0
  59. package/dist/platform/filesystem/glob/cachedFs.d.ts +9 -0
  60. package/dist/platform/filesystem/glob/cachedFs.d.ts.map +1 -0
  61. package/dist/platform/filesystem/glob/cachedFs.js +25 -0
  62. package/dist/platform/filesystem/glob/glob.d.ts +15 -0
  63. package/dist/platform/filesystem/glob/glob.d.ts.map +1 -0
  64. package/dist/platform/filesystem/glob/glob.js +62 -0
  65. package/dist/platform/filesystem/glob/parseGlob.d.ts +11 -0
  66. package/dist/platform/filesystem/glob/parseGlob.d.ts.map +1 -0
  67. package/dist/platform/filesystem/glob/parseGlob.js +61 -0
  68. package/dist/platform/filesystem/index.d.ts +6 -0
  69. package/dist/platform/filesystem/index.d.ts.map +1 -0
  70. package/dist/platform/filesystem/index.js +5 -0
  71. package/dist/platform/process/EnvReader.d.ts +13 -0
  72. package/dist/platform/process/EnvReader.d.ts.map +1 -0
  73. package/dist/platform/process/EnvReader.js +92 -0
  74. package/dist/platform/process/ProcessContext.d.ts +34 -0
  75. package/dist/platform/process/ProcessContext.d.ts.map +1 -0
  76. package/dist/platform/process/ProcessContext.js +47 -0
  77. package/dist/time/Clock.d.ts +21 -0
  78. package/dist/time/Clock.d.ts.map +1 -0
  79. package/dist/time/Clock.js +27 -0
  80. package/dist/time/temporal.d.ts +5 -0
  81. package/dist/time/temporal.d.ts.map +1 -0
  82. package/dist/time/temporal.js +39 -0
  83. package/dist/utils/jsonStringify.d.ts +7 -0
  84. package/dist/utils/jsonStringify.d.ts.map +1 -0
  85. package/dist/utils/jsonStringify.js +23 -0
  86. package/dist/utils/runMain.d.ts +3 -0
  87. package/dist/utils/runMain.d.ts.map +1 -0
  88. package/dist/utils/runMain.js +75 -0
  89. package/package.json +71 -0
@@ -0,0 +1,21 @@
1
+ import { type DurationLike } from "./temporal";
2
+ type PublicInterface<T> = {
3
+ [K in keyof T]: T[K];
4
+ };
5
+ export type IClock = PublicInterface<AbstractClock>;
6
+ export declare abstract class AbstractClock implements IClock {
7
+ abstract now(): Temporal.Instant;
8
+ nowDate(): Date;
9
+ }
10
+ export declare class Clock extends AbstractClock {
11
+ now(): Temporal.Instant;
12
+ }
13
+ export declare class TestClock extends AbstractClock {
14
+ private _now;
15
+ constructor(_now: Temporal.Instant);
16
+ now(): Temporal.Instant;
17
+ advance(duration: DurationLike): void;
18
+ reset(now: Temporal.Instant): void;
19
+ }
20
+ export {};
21
+ //# 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,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,KAAK,eAAe,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAElD,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,27 @@
1
+ import {} from "./temporal.js";
2
+ export class AbstractClock {
3
+ nowDate() {
4
+ return new Date(this.now().epochMilliseconds);
5
+ }
6
+ }
7
+ export class Clock extends AbstractClock {
8
+ now() {
9
+ return Temporal.Now.instant();
10
+ }
11
+ }
12
+ export class TestClock extends AbstractClock {
13
+ _now;
14
+ constructor(_now) {
15
+ super();
16
+ this._now = _now;
17
+ }
18
+ now() {
19
+ return this._now;
20
+ }
21
+ advance(duration) {
22
+ this._now = this._now.add(Temporal.Duration.from(duration));
23
+ }
24
+ reset(now) {
25
+ this._now = now;
26
+ }
27
+ }
@@ -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,CAEhE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAkBvE"}
@@ -0,0 +1,39 @@
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
+ return duration.total("milliseconds");
15
+ }
16
+ export function prettyPrintDuration(duration) {
17
+ // note: there is Intl.DurationFormat("en", { style: "narrow" }).format(duration) which should do the same thing but:
18
+ // 1. It's not available in node <= 22, Intl.DurationFormat is not available
19
+ // 2. Exact formatting output is dependent on ICU data and on some environments (CI) months get formatted as m instead of mo
20
+ // for these reasons it's better to always use bespoke implementation
21
+ const parts = [];
22
+ if (duration.years)
23
+ parts.push(`${duration.years}y`);
24
+ if (duration.months)
25
+ parts.push(`${duration.months}mo`);
26
+ if (duration.weeks)
27
+ parts.push(`${duration.weeks}w`);
28
+ if (duration.days)
29
+ parts.push(`${duration.days}d`);
30
+ if (duration.hours)
31
+ parts.push(`${duration.hours}h`);
32
+ if (duration.minutes)
33
+ parts.push(`${duration.minutes}m`);
34
+ if (duration.seconds)
35
+ parts.push(`${duration.seconds}s`);
36
+ if (duration.milliseconds)
37
+ parts.push(`${duration.milliseconds}ms`);
38
+ return parts.join(" ");
39
+ }
@@ -0,0 +1,7 @@
1
+ export declare function jsonStringifyAll(value: object, space?: number): string;
2
+ export interface PrettyJsonStringifyAllOptions {
3
+ space?: number;
4
+ singleLineUntilLength?: number;
5
+ }
6
+ export declare function prettyJsonStringifyAll(value: object, options?: PrettyJsonStringifyAllOptions): string;
7
+ //# sourceMappingURL=jsonStringify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonStringify.d.ts","sourceRoot":"","sources":["../../src/utils/jsonStringify.ts"],"names":[],"mappings":"AAYA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,MAAM,WAAW,6BAA6B;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,6BAA6B,GACtC,MAAM,CAYR"}
@@ -0,0 +1,23 @@
1
+ function replacer(_k, v) {
2
+ if (typeof v === "bigint") {
3
+ return v.toString();
4
+ }
5
+ if (v instanceof Promise) {
6
+ return "Promise";
7
+ }
8
+ return v;
9
+ }
10
+ export function jsonStringifyAll(value, space) {
11
+ return JSON.stringify(value, replacer, space);
12
+ }
13
+ export function prettyJsonStringifyAll(value, options) {
14
+ const singleLineUntilLength = options?.singleLineUntilLength;
15
+ const space = options?.space;
16
+ if (singleLineUntilLength !== undefined) {
17
+ const compact = jsonStringifyAll(value);
18
+ if (compact.length <= singleLineUntilLength) {
19
+ return compact;
20
+ }
21
+ }
22
+ return jsonStringifyAll(value, space);
23
+ }
@@ -0,0 +1,3 @@
1
+ import { Effect } from "effect";
2
+ export declare function runMain<E>(program: Effect.Effect<void, E>): Promise<void>;
3
+ //# sourceMappingURL=runMain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runMain.d.ts","sourceRoot":"","sources":["../../src/utils/runMain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAQ,MAAM,QAAQ,CAAA;AAkF5C,wBAAsB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAW/E"}
@@ -0,0 +1,75 @@
1
+ import { Cause, Effect, Exit } from "effect";
2
+ import { ansiColors } from "../ansi-colors/index.js";
3
+ function prettyValue(value) {
4
+ if (value instanceof Error) {
5
+ return value.message || value.name;
6
+ }
7
+ return String(value);
8
+ }
9
+ function findDeepestError(value) {
10
+ if (!(value instanceof Object)) {
11
+ return undefined;
12
+ }
13
+ for (const v of Object.values(value)) {
14
+ if (v instanceof Error) {
15
+ return findDeepestError(v) ?? v;
16
+ }
17
+ }
18
+ return value instanceof Error ? value : undefined;
19
+ }
20
+ function formatStackTrace(stack) {
21
+ const lines = stack.split("\n");
22
+ const stackLines = lines.filter((line) => line.trimStart().startsWith("at "));
23
+ return stackLines.map((line) => ansiColors.gray(` ${line.trim()}`)).join("\n");
24
+ }
25
+ function prettyReason(reason) {
26
+ const lines = [];
27
+ if (Cause.isFailReason(reason)) {
28
+ const error = reason.error;
29
+ const name = error instanceof Object && "_tag" in error ? String(error._tag) : String(error);
30
+ const args = error instanceof Object
31
+ ? Object.entries(error)
32
+ .filter(([key]) => key !== "_tag")
33
+ .map(([key, value]) => ` ${ansiColors.cyan(key)}: ${prettyValue(value)}`)
34
+ : undefined;
35
+ lines.push(ansiColors.red(name));
36
+ if (args?.length) {
37
+ lines.push(...args);
38
+ }
39
+ const deepestError = error instanceof Object ? findDeepestError(error) : undefined;
40
+ const stackSource = deepestError ?? (error instanceof Error ? error : undefined);
41
+ if (stackSource?.stack) {
42
+ lines.push(formatStackTrace(stackSource.stack));
43
+ }
44
+ }
45
+ else if (Cause.isDieReason(reason)) {
46
+ lines.push(ansiColors.bold(ansiColors.red("Die")));
47
+ lines.push(` ${prettyValue(reason.defect)}`);
48
+ const stackSource = reason.defect instanceof Object
49
+ ? (findDeepestError(reason.defect) ??
50
+ (reason.defect instanceof Error ? reason.defect : undefined))
51
+ : undefined;
52
+ if (stackSource?.stack) {
53
+ lines.push(formatStackTrace(stackSource.stack));
54
+ }
55
+ }
56
+ else if (Cause.isInterruptReason(reason)) {
57
+ lines.push(ansiColors.bold(ansiColors.yellow("Interrupt")) +
58
+ (reason.fiberId != null ? ansiColors.gray(` (fiber #${String(reason.fiberId)})`) : ""));
59
+ }
60
+ return lines.join("\n");
61
+ }
62
+ function prettyCause(cause) {
63
+ return cause.reasons.map((reason) => prettyReason(reason)).join("\n\n");
64
+ }
65
+ export async function runMain(program) {
66
+ const exit = await Effect.runPromiseExit(program);
67
+ Exit.match(exit, {
68
+ onSuccess: () => process.exit(0),
69
+ onFailure: (cause) => {
70
+ process.stderr.write(ansiColors.bold(ansiColors.red("Fatal error occured\n")) + "\n");
71
+ process.stderr.write(prettyCause(cause) + "\n");
72
+ process.exit(1);
73
+ },
74
+ });
75
+ }
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "barely-effect",
3
+ "version": "0.1.0",
4
+ "description": "A missing standard library for TypeScript, providing utilities for async orchestration, error handling, filesystem abstraction, and common patterns",
5
+ "keywords": [
6
+ "async",
7
+ "result",
8
+ "stdlib",
9
+ "task",
10
+ "typescript",
11
+ "utilities"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Kris Kaczor",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/krzkaczor/barely-effect.git"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md"
22
+ ],
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./platform/filesystem": {
33
+ "types": "./dist/platform/filesystem/index.d.ts",
34
+ "default": "./dist/platform/filesystem/index.js"
35
+ },
36
+ "./platform/getPort": {
37
+ "types": "./dist/platform/getPort/index.d.ts",
38
+ "default": "./dist/platform/getPort/index.js"
39
+ },
40
+ "./platform/JsonHttpClient": {
41
+ "types": "./dist/platform/JsonHttpClient/index.d.ts",
42
+ "default": "./dist/platform/JsonHttpClient/index.js"
43
+ },
44
+ "./platform/ProcessContext": {
45
+ "types": "./dist/platform/ProcessContext/index.d.ts",
46
+ "default": "./dist/platform/ProcessContext/index.js"
47
+ },
48
+ "./platform/safeFetch": {
49
+ "types": "./dist/platform/safeFetch/index.d.ts",
50
+ "default": "./dist/platform/safeFetch/index.js"
51
+ }
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.build.json && bun run scripts/fix-imports.ts && cp ../../README.md .",
55
+ "lint": "oxlint --type-aware --type-check --deny-warnings",
56
+ "lint:fix": "bun run lint --fix --fix-dangerously --fix-suggestions",
57
+ "test": "bun test",
58
+ "test:vitest": "bun run scripts/transform-tests-for-vitest.ts && vitest run",
59
+ "fix": "cd ../.. && bun run fix"
60
+ },
61
+ "dependencies": {
62
+ "effect": "4.0.0-beta.23",
63
+ "remeda": "^2.32.0",
64
+ "temporal-polyfill": "^0.3.0"
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": "^22.0.0",
68
+ "vitest": "^3.0.0",
69
+ "zod": "^4.3.5"
70
+ }
71
+ }