From bf151e0d369a639b921eb9eb98727a6a85609f3d Mon Sep 17 00:00:00 2001 From: Alberto Villa Date: Tue, 2 Apr 2024 13:42:44 +0200 Subject: [PATCH] feat: support Fx in place of fp-ts and Effect-TS (#13) BREAKING CHANGE: support for fp-ts and Effect-TS was dropped, and there is now a single file per module/dependency --- .docker/nginx/nginx.conf | 18 - .env.dist | 4 - .github/workflows/test.yaml | 9 +- docker-compose.yaml | 15 - package-lock.json | 320 +++++++++--------- package.json | 9 +- packages/cache-effect-ts-redis/CHANGELOG.md | 37 -- packages/cache-effect-ts-redis/README.md | 3 - packages/cache-effect-ts-redis/package.json | 33 -- .../src/RedisCache.test.ts | 151 --------- .../cache-effect-ts-redis/src/RedisCache.ts | 51 --- packages/cache-effect-ts-redis/src/index.ts | 1 - packages/cache-effect-ts-redis/tsconfig.json | 10 - packages/cache-effect-ts/CHANGELOG.md | 48 --- packages/cache-effect-ts/README.md | 3 - packages/cache-effect-ts/package.json | 35 -- packages/cache-effect-ts/src/Cache.ts | 27 -- .../src/FpTsToEffectTsCache.ts | 67 ---- packages/cache-effect-ts/src/MapCache.test.ts | 115 ------- packages/cache-effect-ts/src/MapCache.ts | 15 - packages/cache-effect-ts/src/index.ts | 3 - packages/cache-effect-ts/tsconfig.json | 13 - packages/cache-fp-ts-redis/README.md | 3 - .../cache-fp-ts-redis/src/RedisCache.test.ts | 120 ------- packages/cache-fp-ts-redis/src/RedisCache.ts | 204 ----------- packages/cache-fp-ts-redis/src/index.ts | 1 - packages/cache-fp-ts-redis/tsconfig.json | 13 - packages/cache-fp-ts/CHANGELOG.md | 37 -- packages/cache-fp-ts/README.md | 3 - packages/cache-fp-ts/package.json | 31 -- packages/cache-fp-ts/src/Cache.ts | 45 --- packages/cache-fp-ts/src/MapCache.test.ts | 95 ------ packages/cache-fp-ts/src/MapCache.ts | 98 ------ packages/cache-fp-ts/src/index.ts | 2 - packages/cache-fp-ts/tsconfig.json | 12 - packages/cache-raw-redis/CHANGELOG.md | 37 -- packages/cache-raw-redis/README.md | 3 - packages/cache-raw-redis/package.json | 31 -- packages/cache-raw-redis/src/RedisCache.ts | 19 -- packages/cache-raw-redis/src/index.ts | 1 - packages/cache-raw-redis/tsconfig.json | 11 - packages/cache-raw/CHANGELOG.md | 37 -- packages/cache-raw/README.md | 3 - packages/cache-raw/package.json | 33 -- packages/cache-raw/src/Cache.ts | 7 - packages/cache-raw/src/FpTsToRawCache.ts | 50 --- packages/cache-raw/src/MapCache.test.ts | 81 ----- packages/cache-raw/src/MapCache.ts | 9 - packages/cache-raw/src/index.ts | 3 - packages/cache-raw/tsconfig.json | 12 - .../CHANGELOG.md | 0 packages/cache-redis/README.md | 3 + .../package.json | 23 +- .../src/CacheItemNotFoundError.ts | 2 +- packages/cache-redis/src/FxRedisCache.test.ts | 153 +++++++++ packages/cache-redis/src/FxRedisCache.ts | 160 +++++++++ .../src/RedisCache.test.ts | 52 +-- packages/cache-redis/src/RedisCache.ts | 150 ++++++++ packages/cache-redis/src/index.ts | 2 + .../cache-redis/test/Redis.ts | 4 +- packages/cache-redis/test/RedisMock.ts | 47 +++ packages/cache-redis/tsconfig.json | 10 + packages/cache/package.json | 9 +- packages/cache/src/Cache.ts | 35 +- packages/cache/src/CacheError.ts | 2 +- packages/cache/tsconfig.json | 2 +- packages/clock-effect-ts/CHANGELOG.md | 30 -- packages/clock-effect-ts/README.md | 3 - packages/clock-effect-ts/package.json | 29 -- packages/clock-effect-ts/src/Clock.ts | 12 - .../clock-effect-ts/src/DateClock.test.ts | 17 - packages/clock-effect-ts/src/DateClock.ts | 8 - .../src/EffectTsToFpTsClock.ts | 11 - .../src/FpTsToEffectTsClock.ts | 11 - .../src/PerformanceClock.test.ts | 17 - .../clock-effect-ts/src/PerformanceClock.ts | 8 - packages/clock-effect-ts/src/index.ts | 5 - packages/clock-effect-ts/tsconfig.json | 9 - packages/clock-fp-ts/CHANGELOG.md | 19 -- packages/clock-fp-ts/README.md | 3 - packages/clock-fp-ts/package.json | 28 -- packages/clock-fp-ts/src/Clock.ts | 14 - packages/clock-fp-ts/src/DateClock.test.ts | 11 - packages/clock-fp-ts/src/DateClock.ts | 7 - .../clock-fp-ts/src/PerformanceClock.test.ts | 14 - packages/clock-fp-ts/src/PerformanceClock.ts | 7 - packages/clock-fp-ts/src/index.ts | 3 - packages/clock-fp-ts/tsconfig.json | 5 - packages/clock-raw/CHANGELOG.md | 30 -- packages/clock-raw/README.md | 3 - packages/clock-raw/package.json | 28 -- packages/clock-raw/src/Clock.ts | 4 - packages/clock-raw/src/DateClock.test.ts | 9 - packages/clock-raw/src/DateClock.ts | 8 - packages/clock-raw/src/FpTsToRawClock.ts | 10 - .../clock-raw/src/PerformanceClock.test.ts | 12 - packages/clock-raw/src/PerformanceClock.ts | 8 - packages/clock-raw/src/RawToFpTsClock.ts | 10 - packages/clock-raw/src/index.ts | 5 - packages/clock-raw/tsconfig.json | 9 - packages/clock/package.json | 7 +- packages/clock/src/Clock.ts | 9 +- packages/clock/src/date/DateClock.ts | 7 + packages/clock/src/date/FxDateClock.test.ts | 17 + packages/clock/src/date/FxDateClock.ts | 7 + packages/clock/src/index.ts | 4 + .../performance/FxPerformanceClock.test.ts | 17 + .../src/performance/FxPerformanceClock.ts | 7 + .../clock/src/performance/PerformanceClock.ts | 7 + packages/clock/tsconfig.json | 7 +- packages/codec-effect-ts-io-ts/CHANGELOG.md | 37 -- packages/codec-effect-ts-io-ts/README.md | 3 - packages/codec-effect-ts-io-ts/package.json | 30 -- .../src/IoTsCodec.test.ts | 58 ---- .../codec-effect-ts-io-ts/src/IoTsCodec.ts | 13 - packages/codec-effect-ts-io-ts/tsconfig.json | 9 - packages/codec-effect-ts/CHANGELOG.md | 30 -- packages/codec-effect-ts/README.md | 3 - packages/codec-effect-ts/package.json | 29 -- packages/codec-effect-ts/src/Codec.ts | 15 - .../src/EffectTsToFpTsCodec.ts | 54 --- .../src/FpTsToEffectTsCodec.ts | 31 -- packages/codec-effect-ts/src/index.ts | 3 - packages/codec-effect-ts/tsconfig.json | 5 - packages/codec-fp-ts-io-ts/README.md | 3 - packages/codec-fp-ts-io-ts/package.json | 29 -- .../codec-fp-ts-io-ts/src/IoTsCodec.test.ts | 58 ---- packages/codec-fp-ts-io-ts/src/index.ts | 1 - packages/codec-fp-ts-io-ts/tsconfig.json | 5 - packages/codec-fp-ts/CHANGELOG.md | 30 -- packages/codec-fp-ts/README.md | 3 - packages/codec-fp-ts/package.json | 27 -- packages/codec-fp-ts/src/Codec.ts | 15 - packages/codec-fp-ts/src/index.ts | 1 - packages/codec-fp-ts/tsconfig.json | 9 - .../CHANGELOG.md | 0 packages/codec-io-ts/README.md | 3 + .../package.json | 11 +- .../src/IoTsCodec.test.ts | 6 +- .../src/IoTsCodec.ts | 24 +- .../src/index.ts | 0 .../tsconfig.json | 2 +- packages/codec-raw-io-ts/CHANGELOG.md | 37 -- packages/codec-raw-io-ts/README.md | 3 - packages/codec-raw-io-ts/package.json | 30 -- packages/codec-raw-io-ts/src/IoTsCodec.ts | 9 - packages/codec-raw-io-ts/src/index.ts | 1 - packages/codec-raw-io-ts/tsconfig.json | 9 - packages/codec-raw/CHANGELOG.md | 30 -- packages/codec-raw/README.md | 3 - packages/codec-raw/package.json | 28 -- packages/codec-raw/src/Codec.ts | 13 - packages/codec-raw/src/FpTsToRawCodec.ts | 28 -- packages/codec-raw/src/RawToFpTsCodec.ts | 62 ---- packages/codec-raw/src/index.ts | 3 - packages/codec-raw/tsconfig.json | 5 - packages/codec/package.json | 8 +- packages/codec/src/Codec.ts | 13 +- packages/codec/src/CodecError.ts | 2 +- packages/codec/src/Decoder.ts | 4 + packages/codec/src/Encoder.ts | 3 + packages/codec/src/index.ts | 2 + packages/codec/tsconfig.json | 1 - packages/effect-effect-ts/CHANGELOG.md | 75 ---- packages/effect-effect-ts/README.md | 3 - packages/effect-effect-ts/package.json | 27 -- packages/effect-effect-ts/src/index.ts | 22 -- packages/effect-effect-ts/tsconfig.json | 9 - packages/effect-fp-ts/CHANGELOG.md | 59 ---- packages/effect-fp-ts/README.md | 3 - packages/effect-fp-ts/package.json | 27 -- packages/effect-fp-ts/src/index.ts | 33 -- packages/effect-fp-ts/tsconfig.json | 9 - packages/effect-raw/CHANGELOG.md | 59 ---- packages/effect-raw/README.md | 3 - packages/effect-raw/package.json | 26 -- packages/effect-raw/src/index.ts | 17 - packages/effect-raw/tsconfig.json | 9 - packages/effect/CHANGELOG.md | 19 -- packages/effect/README.md | 3 - packages/effect/package.json | 23 -- packages/effect/src/index.ts | 19 -- packages/effect/tsconfig.json | 8 - .../CHANGELOG.md | 0 packages/http-axios/README.md | 3 + .../{http-fp-ts => http-axios}/package.json | 15 +- .../src/AxiosHttp.test.ts | 30 +- packages/http-axios/src/AxiosHttp.ts | 94 +++++ packages/http-axios/src/FxAxiosHttp.test.ts | 63 ++++ packages/http-axios/src/FxAxiosHttp.ts | 75 ++++ packages/http-axios/src/Response.ts | 14 + packages/http-axios/src/index.ts | 2 + .../{http-raw => http-axios}/tsconfig.json | 4 +- packages/http-effect-ts-axios/CHANGELOG.md | 19 -- packages/http-effect-ts-axios/README.md | 3 - packages/http-effect-ts-axios/package.json | 33 -- .../src/AxiosHttp.test.ts | 55 --- .../http-effect-ts-axios/src/AxiosHttp.ts | 21 -- packages/http-effect-ts-axios/src/index.ts | 1 - packages/http-effect-ts-axios/tsconfig.json | 11 - packages/http-effect-ts/CHANGELOG.md | 19 -- packages/http-effect-ts/README.md | 3 - packages/http-effect-ts/package.json | 32 -- .../http-effect-ts/src/FpTsToEffectTsHttp.ts | 51 --- packages/http-effect-ts/src/Http.ts | 13 - packages/http-effect-ts/src/index.ts | 2 - packages/http-effect-ts/tsconfig.json | 9 - packages/http-fp-ts-axios/README.md | 3 - packages/http-fp-ts-axios/package.json | 31 -- .../http-fp-ts-axios/src/AxiosHttp.test.ts | 42 --- packages/http-fp-ts-axios/src/AxiosHttp.ts | 125 ------- packages/http-fp-ts-axios/src/index.ts | 1 - packages/http-fp-ts-axios/tsconfig.json | 10 - packages/http-fp-ts/CHANGELOG.md | 19 -- packages/http-fp-ts/README.md | 3 - packages/http-fp-ts/src/Http.ts | 26 -- packages/http-fp-ts/src/index.ts | 1 - packages/http-fp-ts/tsconfig.json | 5 - packages/http-raw-axios/CHANGELOG.md | 19 -- packages/http-raw-axios/README.md | 3 - packages/http-raw-axios/package.json | 32 -- packages/http-raw-axios/src/AxiosHttp.ts | 16 - packages/http-raw-axios/src/index.ts | 1 - packages/http-raw-axios/tsconfig.json | 11 - packages/http-raw/CHANGELOG.md | 19 -- packages/http-raw/README.md | 3 - packages/http-raw/package.json | 31 -- packages/http-raw/src/FpTsToRawHttp.ts | 48 --- packages/http-raw/src/Http.ts | 4 - packages/http-raw/src/index.ts | 2 - packages/http/package.json | 7 +- packages/http/src/Http.ts | 37 +- packages/http/src/HttpError.ts | 2 +- packages/http/src/HttpResponseError.ts | 2 +- packages/http/tsconfig.json | 1 - packages/log-effect-ts-pino/CHANGELOG.md | 37 -- packages/log-effect-ts-pino/README.md | 3 - packages/log-effect-ts-pino/package.json | 30 -- .../log-effect-ts-pino/src/PinoLog.test.ts | 49 --- packages/log-effect-ts-pino/src/PinoLog.ts | 9 - packages/log-effect-ts-pino/src/index.ts | 1 - packages/log-effect-ts-pino/tsconfig.json | 8 - packages/log-effect-ts/CHANGELOG.md | 48 --- packages/log-effect-ts/README.md | 3 - packages/log-effect-ts/package.json | 29 -- .../log-effect-ts/src/EffectTsToFpTsLog.ts | 39 --- .../log-effect-ts/src/FpTsToEffectTsLog.ts | 39 --- packages/log-effect-ts/src/Log.ts | 22 -- packages/log-effect-ts/src/VoidLog.ts | 8 - packages/log-effect-ts/src/index.ts | 4 - packages/log-effect-ts/tsconfig.json | 9 - packages/log-fp-ts-pino/README.md | 3 - packages/log-fp-ts-pino/src/PinoLog.test.ts | 38 --- packages/log-fp-ts-pino/src/PinoLog.ts | 43 --- packages/log-fp-ts-pino/src/index.ts | 1 - packages/log-fp-ts/CHANGELOG.md | 37 -- packages/log-fp-ts/README.md | 3 - packages/log-fp-ts/package.json | 28 -- packages/log-fp-ts/src/Log.ts | 24 -- packages/log-fp-ts/src/VoidLog.ts | 36 -- packages/log-fp-ts/src/index.ts | 2 - .../{log-fp-ts-pino => log-pino}/CHANGELOG.md | 0 packages/log-pino/README.md | 3 + .../{log-raw-pino => log-pino}/package.json | 13 +- .../src/FxPinoLog.test.ts} | 27 +- packages/log-pino/src/FxPinoLog.ts | 8 + packages/log-pino/src/PinoLog.ts | 42 +++ packages/log-pino/src/index.ts | 2 + .../{log-fp-ts => log-pino}/tsconfig.json | 2 +- packages/log-raw-pino/CHANGELOG.md | 37 -- packages/log-raw-pino/README.md | 3 - packages/log-raw-pino/src/PinoLog.ts | 9 - packages/log-raw-pino/src/index.ts | 1 - packages/log-raw-pino/tsconfig.json | 5 - packages/log-raw/CHANGELOG.md | 37 -- packages/log-raw/README.md | 3 - packages/log-raw/package.json | 28 -- packages/log-raw/src/FpTsToRawLog.ts | 38 --- packages/log-raw/src/Log.ts | 4 - packages/log-raw/src/RawToFpTsLog.ts | 38 --- packages/log-raw/src/VoidLog.ts | 8 - packages/log-raw/src/index.ts | 4 - packages/log-raw/tsconfig.json | 9 - packages/log/package.json | 7 +- packages/log/src/Log.ts | 22 +- packages/log/src/Severity.ts | 2 +- packages/log/src/index.ts | 2 + packages/log/src/void/FxVoidLog.ts | 7 + packages/log/src/void/VoidLog.ts | 19 ++ packages/log/tsconfig.json | 7 +- test/tsconfig.json | 1 - tsconfig.build.json | 1 - 292 files changed, 1311 insertions(+), 5139 deletions(-) delete mode 100644 .docker/nginx/nginx.conf delete mode 100644 packages/cache-effect-ts-redis/CHANGELOG.md delete mode 100644 packages/cache-effect-ts-redis/README.md delete mode 100644 packages/cache-effect-ts-redis/package.json delete mode 100644 packages/cache-effect-ts-redis/src/RedisCache.test.ts delete mode 100644 packages/cache-effect-ts-redis/src/RedisCache.ts delete mode 100644 packages/cache-effect-ts-redis/src/index.ts delete mode 100644 packages/cache-effect-ts-redis/tsconfig.json delete mode 100644 packages/cache-effect-ts/CHANGELOG.md delete mode 100644 packages/cache-effect-ts/README.md delete mode 100644 packages/cache-effect-ts/package.json delete mode 100644 packages/cache-effect-ts/src/Cache.ts delete mode 100644 packages/cache-effect-ts/src/FpTsToEffectTsCache.ts delete mode 100644 packages/cache-effect-ts/src/MapCache.test.ts delete mode 100644 packages/cache-effect-ts/src/MapCache.ts delete mode 100644 packages/cache-effect-ts/src/index.ts delete mode 100644 packages/cache-effect-ts/tsconfig.json delete mode 100644 packages/cache-fp-ts-redis/README.md delete mode 100644 packages/cache-fp-ts-redis/src/RedisCache.test.ts delete mode 100644 packages/cache-fp-ts-redis/src/RedisCache.ts delete mode 100644 packages/cache-fp-ts-redis/src/index.ts delete mode 100644 packages/cache-fp-ts-redis/tsconfig.json delete mode 100644 packages/cache-fp-ts/CHANGELOG.md delete mode 100644 packages/cache-fp-ts/README.md delete mode 100644 packages/cache-fp-ts/package.json delete mode 100644 packages/cache-fp-ts/src/Cache.ts delete mode 100644 packages/cache-fp-ts/src/MapCache.test.ts delete mode 100644 packages/cache-fp-ts/src/MapCache.ts delete mode 100644 packages/cache-fp-ts/src/index.ts delete mode 100644 packages/cache-fp-ts/tsconfig.json delete mode 100644 packages/cache-raw-redis/CHANGELOG.md delete mode 100644 packages/cache-raw-redis/README.md delete mode 100644 packages/cache-raw-redis/package.json delete mode 100644 packages/cache-raw-redis/src/RedisCache.ts delete mode 100644 packages/cache-raw-redis/src/index.ts delete mode 100644 packages/cache-raw-redis/tsconfig.json delete mode 100644 packages/cache-raw/CHANGELOG.md delete mode 100644 packages/cache-raw/README.md delete mode 100644 packages/cache-raw/package.json delete mode 100644 packages/cache-raw/src/Cache.ts delete mode 100644 packages/cache-raw/src/FpTsToRawCache.ts delete mode 100644 packages/cache-raw/src/MapCache.test.ts delete mode 100644 packages/cache-raw/src/MapCache.ts delete mode 100644 packages/cache-raw/src/index.ts delete mode 100644 packages/cache-raw/tsconfig.json rename packages/{cache-fp-ts-redis => cache-redis}/CHANGELOG.md (100%) create mode 100644 packages/cache-redis/README.md rename packages/{cache-fp-ts-redis => cache-redis}/package.json (52%) rename packages/{cache-fp-ts-redis => cache-redis}/src/CacheItemNotFoundError.ts (71%) create mode 100644 packages/cache-redis/src/FxRedisCache.test.ts create mode 100644 packages/cache-redis/src/FxRedisCache.ts rename packages/{cache-raw-redis => cache-redis}/src/RedisCache.test.ts (56%) create mode 100644 packages/cache-redis/src/RedisCache.ts create mode 100644 packages/cache-redis/src/index.ts rename test/redis.ts => packages/cache-redis/test/Redis.ts (90%) create mode 100644 packages/cache-redis/test/RedisMock.ts create mode 100644 packages/cache-redis/tsconfig.json delete mode 100644 packages/clock-effect-ts/CHANGELOG.md delete mode 100644 packages/clock-effect-ts/README.md delete mode 100644 packages/clock-effect-ts/package.json delete mode 100644 packages/clock-effect-ts/src/Clock.ts delete mode 100644 packages/clock-effect-ts/src/DateClock.test.ts delete mode 100644 packages/clock-effect-ts/src/DateClock.ts delete mode 100644 packages/clock-effect-ts/src/EffectTsToFpTsClock.ts delete mode 100644 packages/clock-effect-ts/src/FpTsToEffectTsClock.ts delete mode 100644 packages/clock-effect-ts/src/PerformanceClock.test.ts delete mode 100644 packages/clock-effect-ts/src/PerformanceClock.ts delete mode 100644 packages/clock-effect-ts/src/index.ts delete mode 100644 packages/clock-effect-ts/tsconfig.json delete mode 100644 packages/clock-fp-ts/CHANGELOG.md delete mode 100644 packages/clock-fp-ts/README.md delete mode 100644 packages/clock-fp-ts/package.json delete mode 100644 packages/clock-fp-ts/src/Clock.ts delete mode 100644 packages/clock-fp-ts/src/DateClock.test.ts delete mode 100644 packages/clock-fp-ts/src/DateClock.ts delete mode 100644 packages/clock-fp-ts/src/PerformanceClock.test.ts delete mode 100644 packages/clock-fp-ts/src/PerformanceClock.ts delete mode 100644 packages/clock-fp-ts/src/index.ts delete mode 100644 packages/clock-fp-ts/tsconfig.json delete mode 100644 packages/clock-raw/CHANGELOG.md delete mode 100644 packages/clock-raw/README.md delete mode 100644 packages/clock-raw/package.json delete mode 100644 packages/clock-raw/src/Clock.ts delete mode 100644 packages/clock-raw/src/DateClock.test.ts delete mode 100644 packages/clock-raw/src/DateClock.ts delete mode 100644 packages/clock-raw/src/FpTsToRawClock.ts delete mode 100644 packages/clock-raw/src/PerformanceClock.test.ts delete mode 100644 packages/clock-raw/src/PerformanceClock.ts delete mode 100644 packages/clock-raw/src/RawToFpTsClock.ts delete mode 100644 packages/clock-raw/src/index.ts delete mode 100644 packages/clock-raw/tsconfig.json create mode 100644 packages/clock/src/date/DateClock.ts create mode 100644 packages/clock/src/date/FxDateClock.test.ts create mode 100644 packages/clock/src/date/FxDateClock.ts create mode 100644 packages/clock/src/performance/FxPerformanceClock.test.ts create mode 100644 packages/clock/src/performance/FxPerformanceClock.ts create mode 100644 packages/clock/src/performance/PerformanceClock.ts delete mode 100644 packages/codec-effect-ts-io-ts/CHANGELOG.md delete mode 100644 packages/codec-effect-ts-io-ts/README.md delete mode 100644 packages/codec-effect-ts-io-ts/package.json delete mode 100644 packages/codec-effect-ts-io-ts/src/IoTsCodec.test.ts delete mode 100644 packages/codec-effect-ts-io-ts/src/IoTsCodec.ts delete mode 100644 packages/codec-effect-ts-io-ts/tsconfig.json delete mode 100644 packages/codec-effect-ts/CHANGELOG.md delete mode 100644 packages/codec-effect-ts/README.md delete mode 100644 packages/codec-effect-ts/package.json delete mode 100644 packages/codec-effect-ts/src/Codec.ts delete mode 100644 packages/codec-effect-ts/src/EffectTsToFpTsCodec.ts delete mode 100644 packages/codec-effect-ts/src/FpTsToEffectTsCodec.ts delete mode 100644 packages/codec-effect-ts/src/index.ts delete mode 100644 packages/codec-effect-ts/tsconfig.json delete mode 100644 packages/codec-fp-ts-io-ts/README.md delete mode 100644 packages/codec-fp-ts-io-ts/package.json delete mode 100644 packages/codec-fp-ts-io-ts/src/IoTsCodec.test.ts delete mode 100644 packages/codec-fp-ts-io-ts/src/index.ts delete mode 100644 packages/codec-fp-ts-io-ts/tsconfig.json delete mode 100644 packages/codec-fp-ts/CHANGELOG.md delete mode 100644 packages/codec-fp-ts/README.md delete mode 100644 packages/codec-fp-ts/package.json delete mode 100644 packages/codec-fp-ts/src/Codec.ts delete mode 100644 packages/codec-fp-ts/src/index.ts delete mode 100644 packages/codec-fp-ts/tsconfig.json rename packages/{codec-fp-ts-io-ts => codec-io-ts}/CHANGELOG.md (100%) create mode 100644 packages/codec-io-ts/README.md rename packages/{log-fp-ts-pino => codec-io-ts}/package.json (74%) rename packages/{codec-raw-io-ts => codec-io-ts}/src/IoTsCodec.test.ts (92%) rename packages/{codec-fp-ts-io-ts => codec-io-ts}/src/IoTsCodec.ts (51%) rename packages/{codec-effect-ts-io-ts => codec-io-ts}/src/index.ts (100%) rename packages/{log-fp-ts-pino => codec-io-ts}/tsconfig.json (69%) delete mode 100644 packages/codec-raw-io-ts/CHANGELOG.md delete mode 100644 packages/codec-raw-io-ts/README.md delete mode 100644 packages/codec-raw-io-ts/package.json delete mode 100644 packages/codec-raw-io-ts/src/IoTsCodec.ts delete mode 100644 packages/codec-raw-io-ts/src/index.ts delete mode 100644 packages/codec-raw-io-ts/tsconfig.json delete mode 100644 packages/codec-raw/CHANGELOG.md delete mode 100644 packages/codec-raw/README.md delete mode 100644 packages/codec-raw/package.json delete mode 100644 packages/codec-raw/src/Codec.ts delete mode 100644 packages/codec-raw/src/FpTsToRawCodec.ts delete mode 100644 packages/codec-raw/src/RawToFpTsCodec.ts delete mode 100644 packages/codec-raw/src/index.ts delete mode 100644 packages/codec-raw/tsconfig.json create mode 100644 packages/codec/src/Decoder.ts create mode 100644 packages/codec/src/Encoder.ts delete mode 100644 packages/effect-effect-ts/CHANGELOG.md delete mode 100644 packages/effect-effect-ts/README.md delete mode 100644 packages/effect-effect-ts/package.json delete mode 100644 packages/effect-effect-ts/src/index.ts delete mode 100644 packages/effect-effect-ts/tsconfig.json delete mode 100644 packages/effect-fp-ts/CHANGELOG.md delete mode 100644 packages/effect-fp-ts/README.md delete mode 100644 packages/effect-fp-ts/package.json delete mode 100644 packages/effect-fp-ts/src/index.ts delete mode 100644 packages/effect-fp-ts/tsconfig.json delete mode 100644 packages/effect-raw/CHANGELOG.md delete mode 100644 packages/effect-raw/README.md delete mode 100644 packages/effect-raw/package.json delete mode 100644 packages/effect-raw/src/index.ts delete mode 100644 packages/effect-raw/tsconfig.json delete mode 100644 packages/effect/CHANGELOG.md delete mode 100644 packages/effect/README.md delete mode 100644 packages/effect/package.json delete mode 100644 packages/effect/src/index.ts delete mode 100644 packages/effect/tsconfig.json rename packages/{http-fp-ts-axios => http-axios}/CHANGELOG.md (100%) create mode 100644 packages/http-axios/README.md rename packages/{http-fp-ts => http-axios}/package.json (67%) rename packages/{http-raw-axios => http-axios}/src/AxiosHttp.test.ts (53%) create mode 100644 packages/http-axios/src/AxiosHttp.ts create mode 100644 packages/http-axios/src/FxAxiosHttp.test.ts create mode 100644 packages/http-axios/src/FxAxiosHttp.ts create mode 100644 packages/http-axios/src/Response.ts create mode 100644 packages/http-axios/src/index.ts rename packages/{http-raw => http-axios}/tsconfig.json (70%) delete mode 100644 packages/http-effect-ts-axios/CHANGELOG.md delete mode 100644 packages/http-effect-ts-axios/README.md delete mode 100644 packages/http-effect-ts-axios/package.json delete mode 100644 packages/http-effect-ts-axios/src/AxiosHttp.test.ts delete mode 100644 packages/http-effect-ts-axios/src/AxiosHttp.ts delete mode 100644 packages/http-effect-ts-axios/src/index.ts delete mode 100644 packages/http-effect-ts-axios/tsconfig.json delete mode 100644 packages/http-effect-ts/CHANGELOG.md delete mode 100644 packages/http-effect-ts/README.md delete mode 100644 packages/http-effect-ts/package.json delete mode 100644 packages/http-effect-ts/src/FpTsToEffectTsHttp.ts delete mode 100644 packages/http-effect-ts/src/Http.ts delete mode 100644 packages/http-effect-ts/src/index.ts delete mode 100644 packages/http-effect-ts/tsconfig.json delete mode 100644 packages/http-fp-ts-axios/README.md delete mode 100644 packages/http-fp-ts-axios/package.json delete mode 100644 packages/http-fp-ts-axios/src/AxiosHttp.test.ts delete mode 100644 packages/http-fp-ts-axios/src/AxiosHttp.ts delete mode 100644 packages/http-fp-ts-axios/src/index.ts delete mode 100644 packages/http-fp-ts-axios/tsconfig.json delete mode 100644 packages/http-fp-ts/CHANGELOG.md delete mode 100644 packages/http-fp-ts/README.md delete mode 100644 packages/http-fp-ts/src/Http.ts delete mode 100644 packages/http-fp-ts/src/index.ts delete mode 100644 packages/http-fp-ts/tsconfig.json delete mode 100644 packages/http-raw-axios/CHANGELOG.md delete mode 100644 packages/http-raw-axios/README.md delete mode 100644 packages/http-raw-axios/package.json delete mode 100644 packages/http-raw-axios/src/AxiosHttp.ts delete mode 100644 packages/http-raw-axios/src/index.ts delete mode 100644 packages/http-raw-axios/tsconfig.json delete mode 100644 packages/http-raw/CHANGELOG.md delete mode 100644 packages/http-raw/README.md delete mode 100644 packages/http-raw/package.json delete mode 100644 packages/http-raw/src/FpTsToRawHttp.ts delete mode 100644 packages/http-raw/src/Http.ts delete mode 100644 packages/http-raw/src/index.ts delete mode 100644 packages/log-effect-ts-pino/CHANGELOG.md delete mode 100644 packages/log-effect-ts-pino/README.md delete mode 100644 packages/log-effect-ts-pino/package.json delete mode 100644 packages/log-effect-ts-pino/src/PinoLog.test.ts delete mode 100644 packages/log-effect-ts-pino/src/PinoLog.ts delete mode 100644 packages/log-effect-ts-pino/src/index.ts delete mode 100644 packages/log-effect-ts-pino/tsconfig.json delete mode 100644 packages/log-effect-ts/CHANGELOG.md delete mode 100644 packages/log-effect-ts/README.md delete mode 100644 packages/log-effect-ts/package.json delete mode 100644 packages/log-effect-ts/src/EffectTsToFpTsLog.ts delete mode 100644 packages/log-effect-ts/src/FpTsToEffectTsLog.ts delete mode 100644 packages/log-effect-ts/src/Log.ts delete mode 100644 packages/log-effect-ts/src/VoidLog.ts delete mode 100644 packages/log-effect-ts/src/index.ts delete mode 100644 packages/log-effect-ts/tsconfig.json delete mode 100644 packages/log-fp-ts-pino/README.md delete mode 100644 packages/log-fp-ts-pino/src/PinoLog.test.ts delete mode 100644 packages/log-fp-ts-pino/src/PinoLog.ts delete mode 100644 packages/log-fp-ts-pino/src/index.ts delete mode 100644 packages/log-fp-ts/CHANGELOG.md delete mode 100644 packages/log-fp-ts/README.md delete mode 100644 packages/log-fp-ts/package.json delete mode 100644 packages/log-fp-ts/src/Log.ts delete mode 100644 packages/log-fp-ts/src/VoidLog.ts delete mode 100644 packages/log-fp-ts/src/index.ts rename packages/{log-fp-ts-pino => log-pino}/CHANGELOG.md (100%) create mode 100644 packages/log-pino/README.md rename packages/{log-raw-pino => log-pino}/package.json (69%) rename packages/{log-raw-pino/src/PinoLog.test.ts => log-pino/src/FxPinoLog.test.ts} (55%) create mode 100644 packages/log-pino/src/FxPinoLog.ts create mode 100644 packages/log-pino/src/PinoLog.ts create mode 100644 packages/log-pino/src/index.ts rename packages/{log-fp-ts => log-pino}/tsconfig.json (59%) delete mode 100644 packages/log-raw-pino/CHANGELOG.md delete mode 100644 packages/log-raw-pino/README.md delete mode 100644 packages/log-raw-pino/src/PinoLog.ts delete mode 100644 packages/log-raw-pino/src/index.ts delete mode 100644 packages/log-raw-pino/tsconfig.json delete mode 100644 packages/log-raw/CHANGELOG.md delete mode 100644 packages/log-raw/README.md delete mode 100644 packages/log-raw/package.json delete mode 100644 packages/log-raw/src/FpTsToRawLog.ts delete mode 100644 packages/log-raw/src/Log.ts delete mode 100644 packages/log-raw/src/RawToFpTsLog.ts delete mode 100644 packages/log-raw/src/VoidLog.ts delete mode 100644 packages/log-raw/src/index.ts delete mode 100644 packages/log-raw/tsconfig.json create mode 100644 packages/log/src/void/FxVoidLog.ts create mode 100644 packages/log/src/void/VoidLog.ts delete mode 100644 test/tsconfig.json diff --git a/.docker/nginx/nginx.conf b/.docker/nginx/nginx.conf deleted file mode 100644 index c94ef64..0000000 --- a/.docker/nginx/nginx.conf +++ /dev/null @@ -1,18 +0,0 @@ -server { - listen 8080 default_server; - - location = /json { - default_type application/json; - return 200 '{"foo":"bar"}'; - } - - location = /text { - default_type text/plain; - return 200 'foobar'; - } - - location = /xml { - default_type application/xml; - return 200 'bar'; - } -} diff --git a/.env.dist b/.env.dist index 6dffc2a..250388f 100644 --- a/.env.dist +++ b/.env.dist @@ -1,7 +1,3 @@ GITHUB_TOKEN= -NGINX_URL=http://nginx:8080 - NPM_TOKEN= - -REDIS_URL=redis://redis:6379 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7c8553c..b02f0d1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - NODEJS_VERSION: [16, 18, 20] + NODEJS_VERSION: [16, 18, 20, 21] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -21,15 +21,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - NODEJS_VERSION: [16, 18, 20] + NODEJS_VERSION: [16, 18, 20, 21] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: + node-version: ${{ matrix.NODEJS_VERSION }} cache: npm - - run: make test - env: - NODEJS_VERSION: ${{ matrix.NODEJS_VERSION }} + - run: make _test - uses: codecov/codecov-action@v3 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/docker-compose.yaml b/docker-compose.yaml index 0667b61..5aebd51 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,21 +12,6 @@ services: environment: - GITHUB_TOKEN - NPM_TOKEN - # links: - # - nginx - # - redis volumes: - .:/opt/${COMPOSE_PROJECT_NAME}:cached working_dir: /opt/${COMPOSE_PROJECT_NAME} - - nginx: - image: nginx:1-alpine - expose: - - 8080 - volumes: - - .docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:cached,ro - - redis: - image: redis:7-alpine - expose: - - 6379 diff --git a/package-lock.json b/package-lock.json index a3c7e87..f4c3832 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,17 +12,13 @@ "packages/*" ], "devDependencies": { - "@effect-ts/core": "^0.60.5", - "@redis/client": "^1.5.8", "@swc/core": "^1.3.71", "@swc/jest": "^0.2.27", "@types/jest": "^29.5.2", - "fp-ts": "^2.16.0", - "io-ts": "^2.2.20", "jest": "^29.6.1", "lerna": "^7.1.3", - "pino": "^8.14.1", - "typescript": "^5.1.3" + "nock": "^13.5.4", + "typescript": "^5.4.3" } }, "node_modules/@ampproject/remapping": { @@ -520,19 +516,6 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, - "node_modules/@effect-ts/core": { - "version": "0.60.5", - "resolved": "https://registry.npmjs.org/@effect-ts/core/-/core-0.60.5.tgz", - "integrity": "sha512-qi1WrtJA90XLMnj2hnUszW9Sx4dXP03ZJtCc5DiUBIOhF4Vw7plfb65/bdBySPoC9s7zy995TdUX1XBSxUkl5w==", - "dependencies": { - "@effect-ts/system": "^0.57.5" - } - }, - "node_modules/@effect-ts/system": { - "version": "0.57.5", - "resolved": "https://registry.npmjs.org/@effect-ts/system/-/system-0.57.5.tgz", - "integrity": "sha512-/crHGujo0xnuHIYNc1VgP0HGJGFSoSqq88JFXe6FmFyXPpWt8Xu39LyLg7rchsxfXFeEdA9CrIZvLV5eswXV5g==" - }, "node_modules/@hutson/parse-repository-url": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz", @@ -546,144 +529,36 @@ "resolved": "packages/cache", "link": true }, - "node_modules/@imho/cache-effect-ts": { - "resolved": "packages/cache-effect-ts", - "link": true - }, - "node_modules/@imho/cache-effect-ts-redis": { - "resolved": "packages/cache-effect-ts-redis", - "link": true - }, - "node_modules/@imho/cache-fp-ts": { - "resolved": "packages/cache-fp-ts", - "link": true - }, - "node_modules/@imho/cache-fp-ts-redis": { - "resolved": "packages/cache-fp-ts-redis", - "link": true - }, - "node_modules/@imho/cache-raw": { - "resolved": "packages/cache-raw", - "link": true - }, - "node_modules/@imho/cache-raw-redis": { - "resolved": "packages/cache-raw-redis", + "node_modules/@imho/cache-redis": { + "resolved": "packages/cache-redis", "link": true }, "node_modules/@imho/clock": { "resolved": "packages/clock", "link": true }, - "node_modules/@imho/clock-effect-ts": { - "resolved": "packages/clock-effect-ts", - "link": true - }, - "node_modules/@imho/clock-fp-ts": { - "resolved": "packages/clock-fp-ts", - "link": true - }, - "node_modules/@imho/clock-raw": { - "resolved": "packages/clock-raw", - "link": true - }, "node_modules/@imho/codec": { "resolved": "packages/codec", "link": true }, - "node_modules/@imho/codec-effect-ts": { - "resolved": "packages/codec-effect-ts", - "link": true - }, - "node_modules/@imho/codec-effect-ts-io-ts": { - "resolved": "packages/codec-effect-ts-io-ts", - "link": true - }, - "node_modules/@imho/codec-fp-ts": { - "resolved": "packages/codec-fp-ts", - "link": true - }, - "node_modules/@imho/codec-fp-ts-io-ts": { - "resolved": "packages/codec-fp-ts-io-ts", - "link": true - }, - "node_modules/@imho/codec-raw": { - "resolved": "packages/codec-raw", - "link": true - }, - "node_modules/@imho/codec-raw-io-ts": { - "resolved": "packages/codec-raw-io-ts", - "link": true - }, - "node_modules/@imho/effect": { - "resolved": "packages/effect", - "link": true - }, - "node_modules/@imho/effect-effect-ts": { - "resolved": "packages/effect-effect-ts", - "link": true - }, - "node_modules/@imho/effect-fp-ts": { - "resolved": "packages/effect-fp-ts", - "link": true - }, - "node_modules/@imho/effect-raw": { - "resolved": "packages/effect-raw", + "node_modules/@imho/codec-io-ts": { + "resolved": "packages/codec-io-ts", "link": true }, "node_modules/@imho/http": { "resolved": "packages/http", "link": true }, - "node_modules/@imho/http-effect-ts": { - "resolved": "packages/http-effect-ts", - "link": true - }, - "node_modules/@imho/http-effect-ts-axios": { - "resolved": "packages/http-effect-ts-axios", - "link": true - }, - "node_modules/@imho/http-fp-ts": { - "resolved": "packages/http-fp-ts", - "link": true - }, - "node_modules/@imho/http-fp-ts-axios": { - "resolved": "packages/http-fp-ts-axios", - "link": true - }, - "node_modules/@imho/http-raw": { - "resolved": "packages/http-raw", - "link": true - }, - "node_modules/@imho/http-raw-axios": { - "resolved": "packages/http-raw-axios", + "node_modules/@imho/http-axios": { + "resolved": "packages/http-axios", "link": true }, "node_modules/@imho/log": { "resolved": "packages/log", "link": true }, - "node_modules/@imho/log-effect-ts": { - "resolved": "packages/log-effect-ts", - "link": true - }, - "node_modules/@imho/log-effect-ts-pino": { - "resolved": "packages/log-effect-ts-pino", - "link": true - }, - "node_modules/@imho/log-fp-ts": { - "resolved": "packages/log-fp-ts", - "link": true - }, - "node_modules/@imho/log-fp-ts-pino": { - "resolved": "packages/log-fp-ts-pino", - "link": true - }, - "node_modules/@imho/log-raw": { - "resolved": "packages/log-raw", - "link": true - }, - "node_modules/@imho/log-raw-pino": { - "resolved": "packages/log-raw-pino", + "node_modules/@imho/log-pino": { + "resolved": "packages/log-pino", "link": true }, "node_modules/@isaacs/cliui": { @@ -3065,6 +2940,7 @@ "version": "1.5.8", "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.8.tgz", "integrity": "sha512-xzElwHIO6rBAqzPeVnCzgvrnBEcFL1P0w8P65VNLRkdVW8rOE58f52hdj0BDgmsdOm4f1EoXPZtH4Fh7M/qUpw==", + "peer": true, "dependencies": { "cluster-key-slot": "1.1.2", "generic-pool": "3.9.0", @@ -3523,6 +3399,12 @@ "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", "dev": true }, + "node_modules/@xzhayon/fx": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@xzhayon/fx/-/fx-0.4.0.tgz", + "integrity": "sha512-WkSE1LKygmH+01LVBGfdGOGTFYi0J3kTjdqy3A+FxK3rFTNPyEETPJ3By6GWZERG5DNqUC+ruv7brnAXhwePTw==", + "peer": true + }, "node_modules/@yarnpkg/lockfile": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", @@ -3570,6 +3452,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "peer": true, "dependencies": { "event-target-shim": "^5.0.0" }, @@ -3756,16 +3639,17 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "peer": true, "engines": { "node": ">=8.0.0" } }, "node_modules/axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -4285,6 +4169,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -4964,6 +4849,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "peer": true, "engines": { "node": ">=6" } @@ -4978,6 +4864,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "peer": true, "engines": { "node": ">=0.8.x" } @@ -5202,6 +5089,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-3.2.0.tgz", "integrity": "sha512-zaTadChr+NekyzallAMXATXLOR8MNx3zqpZ0MUF2aGf4EathnG0f32VLODNlY8IuGY3HoRO2L6/6fSzNsLaHIw==", + "peer": true, "engines": { "node": ">=6" } @@ -5304,9 +5192,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -5366,7 +5254,8 @@ "node_modules/fp-ts": { "version": "2.16.1", "resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-2.16.1.tgz", - "integrity": "sha512-by7U5W8dkIzcvDofUcO42yl9JbnHTEDBrzu3pt5fKT+Z4Oy85I21K80EYJYdjQGC2qum4Vo55Ag57iiIK4FYuA==" + "integrity": "sha512-by7U5W8dkIzcvDofUcO42yl9JbnHTEDBrzu3pt5fKT+Z4Oy85I21K80EYJYdjQGC2qum4Vo55Ag57iiIK4FYuA==", + "peer": true }, "node_modules/fs-constants": { "version": "1.0.0", @@ -5449,6 +5338,7 @@ "version": "3.9.0", "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", + "peer": true, "engines": { "node": ">= 4" } @@ -10691,6 +10581,20 @@ "monocle-ts": "^2.0.0" } }, + "node_modules/nock": { + "version": "13.5.4", + "resolved": "https://registry.npmjs.org/nock/-/nock-13.5.4.tgz", + "integrity": "sha512-yAyTfdeNJGGBFxWdzSKCBYxs5FxLbCg5X5Q4ets974hcQzG1+qCxvIyOo4j2Ry6MUlhWVMX4OoYDefAIIwupjw==", + "dev": true, + "dependencies": { + "debug": "^4.1.0", + "json-stringify-safe": "^5.0.1", + "propagate": "^2.0.0" + }, + "engines": { + "node": ">= 10.13" + } + }, "node_modules/node-addon-api": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", @@ -11490,7 +11394,8 @@ "node_modules/on-exit-leak-free": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.0.tgz", - "integrity": "sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w==" + "integrity": "sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w==", + "peer": true }, "node_modules/once": { "version": "1.4.0", @@ -12093,6 +11998,7 @@ "version": "8.14.1", "resolved": "https://registry.npmjs.org/pino/-/pino-8.14.1.tgz", "integrity": "sha512-8LYNv7BKWXSfS+k6oEc6occy5La+q2sPwU3q2ljTX5AZk7v+5kND2o5W794FyRaqha6DJajmkNRsWtPpFyMUdw==", + "peer": true, "dependencies": { "atomic-sleep": "^1.0.0", "fast-redact": "^3.1.1", @@ -12114,6 +12020,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-1.0.0.tgz", "integrity": "sha512-c7vo5OpW4wIS42hUVcT5REsL8ZljsUfBjqV/e2sFxmFEFZiq1XLUp5EYLtuDH6PEHq9W1egWqRbnLUP5FuZmOA==", + "peer": true, "dependencies": { "readable-stream": "^4.0.0", "split2": "^4.0.0" @@ -12137,6 +12044,7 @@ "url": "https://feross.org/support" } ], + "peer": true, "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" @@ -12146,6 +12054,7 @@ "version": "4.4.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "peer": true, "dependencies": { "abort-controller": "^3.0.0", "buffer": "^6.0.3", @@ -12161,6 +12070,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "peer": true, "engines": { "node": ">= 10.x" } @@ -12168,7 +12078,8 @@ "node_modules/pino-std-serializers": { "version": "6.2.2", "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", - "integrity": "sha512-cHjPPsE+vhj/tnhCy/wiMh3M3z3h/j15zHQX+S9GkTBgqJuTuJzYJ4gUyACLhDaJ7kk9ba9iRDmbH2tJU03OiA==" + "integrity": "sha512-cHjPPsE+vhj/tnhCy/wiMh3M3z3h/j15zHQX+S9GkTBgqJuTuJzYJ4gUyACLhDaJ7kk9ba9iRDmbH2tJU03OiA==", + "peer": true }, "node_modules/pirates": { "version": "4.0.6", @@ -12230,6 +12141,7 @@ "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "peer": true, "engines": { "node": ">= 0.6.0" } @@ -12243,7 +12155,8 @@ "node_modules/process-warning": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-2.2.0.tgz", - "integrity": "sha512-/1WZ8+VQjR6avWOgHeEPd7SDQmFQ1B5mC1eRXsCm5TarlNmx/wCsa5GEaxGm05BORRtyG/Ex/3xq3TuRvq57qg==" + "integrity": "sha512-/1WZ8+VQjR6avWOgHeEPd7SDQmFQ1B5mC1eRXsCm5TarlNmx/wCsa5GEaxGm05BORRtyG/Ex/3xq3TuRvq57qg==", + "peer": true }, "node_modules/promise-inflight": { "version": "1.0.1", @@ -12289,6 +12202,15 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/propagate": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", + "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/protocols": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/protocols/-/protocols-2.0.1.tgz", @@ -12339,7 +12261,8 @@ "node_modules/quick-format-unescaped": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", - "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==" + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "peer": true }, "node_modules/quick-lru": { "version": "4.0.1", @@ -12756,6 +12679,7 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "peer": true, "engines": { "node": ">= 12.13.0" } @@ -12994,6 +12918,7 @@ "version": "2.4.3", "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz", "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==", + "peer": true, "engines": { "node": ">=10" } @@ -13133,6 +13058,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.3.0.tgz", "integrity": "sha512-LYxp34KlZ1a2Jb8ZQgFCK3niIHzibdwtwNUWKg0qQRzsDoJ3Gfgkf8KdBTFU3SkejDEIlWwnSnpVdOZIhFMl/g==", + "peer": true, "dependencies": { "atomic-sleep": "^1.0.0" } @@ -13523,6 +13449,7 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-2.3.0.tgz", "integrity": "sha512-kaDqm1DET9pp3NXwR8382WHbnpXnRkN9xGN9dQt3B2+dmXiW8X1SOwmFOxAErEQ47ObhZ96J6yhZNXuyCOL7KA==", + "peer": true, "dependencies": { "real-require": "^0.2.0" } @@ -13713,9 +13640,9 @@ "dev": true }, "node_modules/typescript": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", - "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz", + "integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -14218,12 +14145,13 @@ "license": "MIT", "peerDependencies": { "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.4.0" } }, "packages/cache-effect-ts": { "name": "@imho/cache-effect-ts", "version": "0.3.2", + "extraneous": true, "license": "MIT", "dependencies": { "fp-ts": "^2.16.0" @@ -14241,6 +14169,7 @@ "packages/cache-effect-ts-redis": { "name": "@imho/cache-effect-ts-redis", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/cache-fp-ts-redis": "^0.3.1" @@ -14256,6 +14185,7 @@ "packages/cache-fp-ts": { "name": "@imho/cache-fp-ts", "version": "0.3.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/cache": "^0.2.0 || ^0.3.0", @@ -14269,6 +14199,7 @@ "packages/cache-fp-ts-redis": { "name": "@imho/cache-fp-ts-redis", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/codec-fp-ts-io-ts": "^0.3.1", @@ -14288,6 +14219,7 @@ "packages/cache-raw": { "name": "@imho/cache-raw", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "fp-ts": "^2.16.0" @@ -14303,6 +14235,7 @@ "packages/cache-raw-redis": { "name": "@imho/cache-raw-redis", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/cache-fp-ts-redis": "^0.3.1" @@ -14313,17 +14246,35 @@ "@redis/client": "^1.5.8" } }, + "packages/cache-redis": { + "name": "@imho/cache-redis", + "version": "0.3.1", + "license": "MIT", + "dependencies": { + "@imho/codec-io-ts": "^0.3.1", + "io-ts": "^2.2.20", + "io-ts-types": "^0.5.19" + }, + "peerDependencies": { + "@imho/cache": "^0.2.0 || ^0.3.0", + "@imho/codec": "^0.2.0 || ^0.3.0", + "@imho/log": "^0.3.1", + "@redis/client": "^1.5.8", + "@xzhayon/fx": "^0.4.0" + } + }, "packages/clock": { "name": "@imho/clock", "version": "0.1.1", "license": "MIT", "peerDependencies": { - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.2.1 || ^0.3.0 || ^0.4.0" } }, "packages/clock-effect-ts": { "name": "@imho/clock-effect-ts", "version": "0.1.2", + "extraneous": true, "license": "MIT", "peerDependencies": { "@effect-ts/core": "^0.60.5", @@ -14335,6 +14286,7 @@ "packages/clock-fp-ts": { "name": "@imho/clock-fp-ts", "version": "0.1.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/clock": "^0.1.0", @@ -14345,6 +14297,7 @@ "packages/clock-raw": { "name": "@imho/clock-raw", "version": "0.1.2", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/clock": "^0.1.0", @@ -14355,14 +14308,12 @@ "packages/codec": { "name": "@imho/codec", "version": "0.3.1", - "license": "MIT", - "peerDependencies": { - "@imho/effect": "^0.2.0" - } + "license": "MIT" }, "packages/codec-effect-ts": { "name": "@imho/codec-effect-ts", "version": "0.2.2", + "extraneous": true, "license": "MIT", "peerDependencies": { "@effect-ts/core": "^0.60.5", @@ -14374,6 +14325,7 @@ "packages/codec-effect-ts-io-ts": { "name": "@imho/codec-effect-ts-io-ts", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/codec-fp-ts-io-ts": "^0.3.1" @@ -14386,6 +14338,7 @@ "packages/codec-fp-ts": { "name": "@imho/codec-fp-ts", "version": "0.2.2", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/codec": "^0.2.0 || ^0.3.0", @@ -14395,6 +14348,7 @@ "packages/codec-fp-ts-io-ts": { "name": "@imho/codec-fp-ts-io-ts", "version": "0.3.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/codec": "^0.2.0 || ^0.3.0", @@ -14403,9 +14357,20 @@ "io-ts": "^2.2.20" } }, + "packages/codec-io-ts": { + "name": "@imho/codec-io-ts", + "version": "0.3.1", + "license": "MIT", + "peerDependencies": { + "@imho/codec": "^0.2.0 || ^0.3.0", + "fp-ts": "^2.16.0", + "io-ts": "^2.2.20" + } + }, "packages/codec-raw": { "name": "@imho/codec-raw", "version": "0.2.2", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/codec": "^0.2.0 || ^0.3.0", @@ -14416,6 +14381,7 @@ "packages/codec-raw-io-ts": { "name": "@imho/codec-raw-io-ts", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/codec-fp-ts-io-ts": "^0.3.1" @@ -14428,11 +14394,13 @@ "packages/effect": { "name": "@imho/effect", "version": "0.2.1", + "extraneous": true, "license": "MIT" }, "packages/effect-effect-ts": { "name": "@imho/effect-effect-ts", "version": "0.4.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@effect-ts/core": "^0.60.5", @@ -14442,6 +14410,7 @@ "packages/effect-fp-ts": { "name": "@imho/effect-fp-ts", "version": "0.3.3", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/effect": "^0.2.0", @@ -14451,6 +14420,7 @@ "packages/effect-raw": { "name": "@imho/effect-raw", "version": "0.3.3", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/effect": "^0.2.0" @@ -14461,12 +14431,25 @@ "version": "0.1.1", "license": "MIT", "peerDependencies": { - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.2.3 || ^0.3.0 || ^0.4.0" + } + }, + "packages/http-axios": { + "name": "@imho/http-axios", + "version": "0.1.1", + "license": "MIT", + "peerDependencies": { + "@imho/clock": "^0.1.1", + "@imho/http": "^0.1.0", + "@imho/log": "^0.3.1", + "@xzhayon/fx": "^0.3.0 || ^0.4.0", + "axios": "^1.4.0" } }, "packages/http-effect-ts": { "name": "@imho/http-effect-ts", "version": "0.1.1", + "extraneous": true, "license": "MIT", "dependencies": { "fp-ts": "^2.16.1" @@ -14481,6 +14464,7 @@ "packages/http-effect-ts-axios": { "name": "@imho/http-effect-ts-axios", "version": "0.1.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/http-fp-ts-axios": "^0.1.1" @@ -14496,6 +14480,7 @@ "packages/http-fp-ts": { "name": "@imho/http-fp-ts", "version": "0.1.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/effect-fp-ts": "^0.3.2", @@ -14506,6 +14491,7 @@ "packages/http-fp-ts-axios": { "name": "@imho/http-fp-ts-axios", "version": "0.1.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/clock-fp-ts": "^0.1.0", @@ -14519,6 +14505,7 @@ "packages/http-raw": { "name": "@imho/http-raw", "version": "0.1.1", + "extraneous": true, "license": "MIT", "dependencies": { "fp-ts": "^2.16.1" @@ -14532,6 +14519,7 @@ "packages/http-raw-axios": { "name": "@imho/http-raw-axios", "version": "0.1.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/http-fp-ts-axios": "^0.1.1" @@ -14548,12 +14536,13 @@ "version": "0.3.1", "license": "MIT", "peerDependencies": { - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.2.1 || ^0.3.0 || ^0.4.0" } }, "packages/log-effect-ts": { "name": "@imho/log-effect-ts", "version": "0.3.2", + "extraneous": true, "license": "MIT", "peerDependencies": { "@effect-ts/core": "^0.60.5", @@ -14565,6 +14554,7 @@ "packages/log-effect-ts-pino": { "name": "@imho/log-effect-ts-pino", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/log-fp-ts-pino": "^0.3.1" @@ -14577,6 +14567,7 @@ "packages/log-fp-ts": { "name": "@imho/log-fp-ts", "version": "0.3.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/effect-fp-ts": "^0.2.0 || ^0.3.0", @@ -14587,6 +14578,7 @@ "packages/log-fp-ts-pino": { "name": "@imho/log-fp-ts-pino", "version": "0.3.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/log-fp-ts": "^0.2.0 || ^0.3.0", @@ -14594,9 +14586,20 @@ "pino": "^8.14.1" } }, + "packages/log-pino": { + "name": "@imho/log-pino", + "version": "0.3.1", + "license": "MIT", + "peerDependencies": { + "@imho/log": "^0.3.1", + "@xzhayon/fx": "^0.2.3 || ^0.3.0 || ^0.4.0", + "pino": "^8.14.1" + } + }, "packages/log-raw": { "name": "@imho/log-raw", "version": "0.3.1", + "extraneous": true, "license": "MIT", "peerDependencies": { "@imho/effect-raw": "^0.2.0 || ^0.3.0", @@ -14607,6 +14610,7 @@ "packages/log-raw-pino": { "name": "@imho/log-raw-pino", "version": "0.3.1", + "extraneous": true, "license": "MIT", "dependencies": { "@imho/log-fp-ts-pino": "^0.3.1" diff --git a/package.json b/package.json index 85c8e06..205fd4b 100644 --- a/package.json +++ b/package.json @@ -18,23 +18,18 @@ ], "scripts": { "build": "npm run build -ws --if-present", - "preclean": "rm -rf test/dist", "clean": "npm run clean -ws --if-present", "release": "env GH_TOKEN=${GITHUB_TOKEN} NODE_AUTH_TOKEN=${NPM_TOKEN} lerna publish -y", "test": "jest --coverage", "version": "scripts/tag-workspaces.sh packages/*" }, "devDependencies": { - "@effect-ts/core": "^0.60.5", - "@redis/client": "^1.5.8", "@swc/core": "^1.3.71", "@swc/jest": "^0.2.27", "@types/jest": "^29.5.2", - "fp-ts": "^2.16.0", - "io-ts": "^2.2.20", "jest": "^29.6.1", "lerna": "^7.1.3", - "pino": "^8.14.1", - "typescript": "^5.1.3" + "nock": "^13.5.4", + "typescript": "^5.4.3" } } diff --git a/packages/cache-effect-ts-redis/CHANGELOG.md b/packages/cache-effect-ts-redis/CHANGELOG.md deleted file mode 100644 index cfe5ce8..0000000 --- a/packages/cache-effect-ts-redis/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/cache-effect-ts-redis@0.3.0...@imho/cache-effect-ts-redis@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/cache-effect-ts-redis - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/cache-effect-ts-redis@0.2.0...@imho/cache-effect-ts-redis@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **cache:** add Redis Cache implementation ([804d190](https://github.com/xzhavilla/imho/commit/804d19040de57074a8aa45edf6e945f9e80cc315)) diff --git a/packages/cache-effect-ts-redis/README.md b/packages/cache-effect-ts-redis/README.md deleted file mode 100644 index 9037ef7..0000000 --- a/packages/cache-effect-ts-redis/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/cache-effect-ts-redis - -[![npm](https://img.shields.io/npm/v/@imho/cache-effect-ts-redis)](https://www.npmjs.com/package/@imho/cache-effect-ts-redis) diff --git a/packages/cache-effect-ts-redis/package.json b/packages/cache-effect-ts-redis/package.json deleted file mode 100644 index 2520b4c..0000000 --- a/packages/cache-effect-ts-redis/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@imho/cache-effect-ts-redis", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/cache-fp-ts-redis": "^0.3.1" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/cache": "^0.2.0 || ^0.3.0", - "@imho/cache-effect-ts": "^0.2.0 || ^0.3.0", - "@imho/log-effect-ts": "^0.2.0 || ^0.3.0", - "@redis/client": "^1.5.8" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/cache-effect-ts-redis/src/RedisCache.test.ts b/packages/cache-effect-ts-redis/src/RedisCache.test.ts deleted file mode 100644 index 9902b56..0000000 --- a/packages/cache-effect-ts-redis/src/RedisCache.test.ts +++ /dev/null @@ -1,151 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import * as Layer from '@effect-ts/core/Effect/Layer' -import { Cache, HasCache } from '@imho/cache-effect-ts' -import { IoTsCodec } from '@imho/codec-effect-ts-io-ts' -import { HasLog, VoidLog } from '@imho/log-effect-ts' -import { RedisFlushModes, createClient } from '@redis/client' -import * as t from 'io-ts' -import { mapRedis } from '../../../test/redis' -import { RedisCache } from './RedisCache' - -describe('RedisCache', () => { - const redis = createClient({ url: process.env.REDIS_URL }) - const layer = pipe( - Layer.fromManaged(HasCache)(RedisCache(redis)), - Layer.using(Layer.fromValue(HasLog)(new VoidLog())), - Layer.main, - ) - - beforeEach(async () => { - await mapRedis(redis, (redis) => redis.flushDb(RedisFlushModes.ASYNC)) - await redis.quit() - }) - - afterAll(async () => { - await redis.quit() - }) - - test('connecting to Redis', async () => { - await expect( - pipe(Cache.has('foo'), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.not.toThrow() - }) - - test('using an already open connection', async () => { - await expect( - pipe( - Cache.has('foo'), - Effect.chain(() => Cache.has('foo')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.not.toThrow() - }) - - test('disconnecting on teardown', async () => { - await expect( - pipe(Cache.has('foo'), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.not.toThrow() - expect(redis.isReady).toBeFalsy() - }) - - describe('has', () => { - test('checking for missing item', async () => { - await expect( - pipe(Cache.has('foo'), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.toBeFalsy() - }) - - test('checking for existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) - await expect( - pipe(Cache.has('foo'), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.toBeTruthy() - }) - }) - - describe('get', () => { - test('failing to fetch data', async () => { - class FooError extends Error {} - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.any), () => - Effect.fail(new FooError()), - ), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).rejects.toBeInstanceOf(FooError) - }) - - test('fetching data on missing item', async () => { - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.any), () => Effect.succeed('bar')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toStrictEqual('bar') - }) - - test('fetching data on invalid codec', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.never), () => Effect.succeed('bar')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toStrictEqual('bar') - }) - - test('getting existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.any), () => Effect.succeed('bar')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toStrictEqual('qux') - }) - }) - - describe('delete', () => { - test('deleting missing item', async () => { - await expect( - pipe( - Cache.delete('foo'), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toBeFalsy() - }) - - test('deleting existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect( - pipe( - Cache.delete('foo'), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toBeTruthy() - await expect( - mapRedis(redis, (redis) => redis.exists('foo')), - ).resolves.toStrictEqual(0) - }) - }) - - describe('clear', () => { - test('clearing cache', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) - await expect( - pipe(Cache.clear(), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.toStrictEqual(undefined) - await expect( - mapRedis(redis, (redis) => redis.dbSize()), - ).resolves.toStrictEqual(0) - }) - }) -}) diff --git a/packages/cache-effect-ts-redis/src/RedisCache.ts b/packages/cache-effect-ts-redis/src/RedisCache.ts deleted file mode 100644 index ac45bd0..0000000 --- a/packages/cache-effect-ts-redis/src/RedisCache.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Effect, Managed, pipe } from '@effect-ts/core' -import { CacheError } from '@imho/cache' -import { Cache, FpTsToEffectTsCache } from '@imho/cache-effect-ts' -import * as fpTs from '@imho/cache-fp-ts-redis' -import { EffectTsToFpTsLog, HasLog, Log } from '@imho/log-effect-ts' -import { - RedisClientType, - RedisFunctions, - RedisModules, - RedisScripts, -} from '@redis/client' - -const channel = 'RedisCache' - -export const RedisCache = < - M extends RedisModules, - F extends RedisFunctions, - S extends RedisScripts, ->( - redis: RedisClientType, -) => - pipe( - Effect.accessService(HasLog)( - (log) => - ({ - cache: new (class RedisCache extends FpTsToEffectTsCache { - constructor(redis: RedisClientType, log: Log) { - super(fpTs.RedisCache(redis)(new EffectTsToFpTsLog(log))) - } - })(redis, log), - log, - } as const), - ), - Managed.make(({ log }) => - !redis.isReady - ? Effect.unit - : pipe( - Effect.tryCatchPromise( - () => redis.quit(), - (cause) => - new CacheError('Cannot disconnect from Redis', { cause }), - ), - Effect.tapBoth( - (error) => log.error('Disconnection failed', { channel, error }), - () => log.debug('Connection closed', { channel }), - ), - Effect.orElse(() => Effect.unit), - ), - ), - Managed.map(({ cache }): Cache => cache), - ) diff --git a/packages/cache-effect-ts-redis/src/index.ts b/packages/cache-effect-ts-redis/src/index.ts deleted file mode 100644 index 611b555..0000000 --- a/packages/cache-effect-ts-redis/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './RedisCache' diff --git a/packages/cache-effect-ts-redis/tsconfig.json b/packages/cache-effect-ts-redis/tsconfig.json deleted file mode 100644 index 63dccca..0000000 --- a/packages/cache-effect-ts-redis/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../cache-effect-ts" }, - { "path": "../cache-fp-ts-redis" }, - { "path": "../codec-effect-ts-io-ts" }, - { "path": "../log-effect-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/cache-effect-ts/CHANGELOG.md b/packages/cache-effect-ts/CHANGELOG.md deleted file mode 100644 index bcf3054..0000000 --- a/packages/cache-effect-ts/CHANGELOG.md +++ /dev/null @@ -1,48 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.2](https://github.com/xzhavilla/imho/compare/@imho/cache-effect-ts@0.3.1...@imho/cache-effect-ts@0.3.2) (2023-07-28) - -**Note:** Version bump only for package @imho/cache-effect-ts - - - - - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/cache-effect-ts@0.3.0...@imho/cache-effect-ts@0.3.1) (2023-07-24) - - -### Bug Fixes - -* update dependencies ([8153a62](https://github.com/xzhavilla/imho/commit/8153a62440343badf7cd715f276b7850b9fb4d32)) - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/cache-effect-ts@0.2.0...@imho/cache-effect-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **cache:** add Cache module ([8b6a3e5](https://github.com/xzhavilla/imho/commit/8b6a3e557cc0759c0435c529b17e1c5b6a83d899)) diff --git a/packages/cache-effect-ts/README.md b/packages/cache-effect-ts/README.md deleted file mode 100644 index 449b14f..0000000 --- a/packages/cache-effect-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/cache-effect-ts - -[![npm](https://img.shields.io/npm/v/@imho/cache-effect-ts)](https://www.npmjs.com/package/@imho/cache-effect-ts) diff --git a/packages/cache-effect-ts/package.json b/packages/cache-effect-ts/package.json deleted file mode 100644 index 335dd7d..0000000 --- a/packages/cache-effect-ts/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "@imho/cache-effect-ts", - "version": "0.3.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "fp-ts": "^2.16.0" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/cache": "^0.2.0 || ^0.3.0", - "@imho/cache-fp-ts": "^0.2.0 || ^0.3.0", - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/codec-effect-ts": "^0.2.0", - "@imho/effect-effect-ts": "^0.2.0 || ^0.3.0 || ^0.4.0", - "@imho/log-effect-ts": "^0.2.0 || ^0.3.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/cache-effect-ts/src/Cache.ts b/packages/cache-effect-ts/src/Cache.ts deleted file mode 100644 index 7ac2c91..0000000 --- a/packages/cache-effect-ts/src/Cache.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Effect, Has } from '@effect-ts/core' -import { IO } from '@effect-ts/core/Effect' -import * as _ from '@imho/cache' -import { CacheError } from '@imho/cache' -import { CodecError } from '@imho/codec' -import { Decoder } from '@imho/codec-effect-ts' -import { EffectTs } from '@imho/effect-effect-ts' - -export interface Cache extends EffectTs> { - get( - key: string, - decoder: Decoder, - onMiss: () => IO, - ): IO -} - -export const HasCache = Has.tag() - -export const Cache = { - ...Effect.deriveLifted(HasCache)(['has', 'delete', 'clear'], [], []), - get: ( - key: string, - decoder: Decoder, - onMiss: () => IO, - ) => - Effect.accessServiceM(HasCache)((cache) => cache.get(key, decoder, onMiss)), -} diff --git a/packages/cache-effect-ts/src/FpTsToEffectTsCache.ts b/packages/cache-effect-ts/src/FpTsToEffectTsCache.ts deleted file mode 100644 index 81bc75e..0000000 --- a/packages/cache-effect-ts/src/FpTsToEffectTsCache.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import { IO } from '@effect-ts/core/Effect' -import * as fpTs from '@imho/cache-fp-ts' -import { Decoder, EffectTsToFpTsDecoder } from '@imho/codec-effect-ts' -import { either } from 'fp-ts' -import { Cache } from './Cache' - -export class FpTsToEffectTsCache implements Cache { - constructor(private readonly cache: fpTs.Cache) {} - - has(key: string) { - return pipe( - Effect.promise(this.cache.has(key)), - Effect.chain((found) => - either.isLeft(found) - ? Effect.fail(found.left) - : Effect.succeed(found.right), - ), - ) - } - - get( - key: string, - decoder: Decoder, - onMiss: () => IO, - ) { - return pipe( - Effect.promise( - this.cache.get( - key, - new EffectTsToFpTsDecoder(decoder), - () => () => - pipe( - onMiss(), - Effect.fold(either.left, either.right), - Effect.runPromise, - ), - ), - ), - Effect.chain((a) => - either.isLeft(a) ? Effect.fail(a.left) : Effect.succeed(a.right), - ), - ) - } - - delete(key: string) { - return pipe( - Effect.promise(this.cache.delete(key)), - Effect.chain((found) => - either.isLeft(found) - ? Effect.fail(found.left) - : Effect.succeed(found.right), - ), - ) - } - - clear() { - return pipe( - Effect.promise(this.cache.clear()), - Effect.chain((cleared) => - either.isLeft(cleared) - ? Effect.fail(cleared.left) - : Effect.succeed(cleared.right), - ), - ) - } -} diff --git a/packages/cache-effect-ts/src/MapCache.test.ts b/packages/cache-effect-ts/src/MapCache.test.ts deleted file mode 100644 index ada74e0..0000000 --- a/packages/cache-effect-ts/src/MapCache.test.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import * as Layer from '@effect-ts/core/Effect/Layer' -import { IoTsCodec } from '@imho/codec-effect-ts-io-ts' -import { HasLog, VoidLog } from '@imho/log-effect-ts' -import * as t from 'io-ts' -import { Cache, HasCache } from './Cache' -import { MapCache } from './MapCache' - -describe('MapCache', () => { - const map = new Map() - const layer = pipe( - Layer.fromEffect(HasCache)(MapCache(map)), - Layer.using(Layer.fromValue(HasLog)(new VoidLog())), - Layer.main, - ) - - beforeEach(() => { - map.clear() - }) - - describe('has', () => { - test('checking for missing item', async () => { - await expect( - pipe(Cache.has('foo'), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.toBeFalsy() - }) - - test('checking for existing item', async () => { - map.set('foo', 'bar') - await expect( - pipe(Cache.has('foo'), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.toBeTruthy() - }) - }) - - describe('get', () => { - test('failing to fetch data', async () => { - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.any), () => - Effect.fail(new Error()), - ), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).rejects.toBeInstanceOf(Error) - }) - - test('fetching data on missing item', async () => { - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.any), () => Effect.succeed('bar')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toStrictEqual('bar') - }) - - test('fetching data on invalid codec', async () => { - map.set('foo', 'qux') - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.never), () => Effect.succeed('bar')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toStrictEqual('bar') - }) - - test('getting existing item', async () => { - map.set('foo', 'qux') - await expect( - pipe( - Cache.get('foo', new IoTsCodec(t.any), () => Effect.succeed('bar')), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toStrictEqual('qux') - }) - }) - - describe('delete', () => { - test('deleting missing item', async () => { - await expect( - pipe( - Cache.delete('foo'), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toBeFalsy() - }) - - test('deleting existing item', async () => { - map.set('foo', 'bar') - await expect( - pipe( - Cache.delete('foo'), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toBeTruthy() - expect(map.has('foo')).toBeFalsy() - }) - }) - - describe('clear', () => { - test('clearing cache', async () => { - map.set('foo', 'bar') - await expect( - pipe(Cache.clear(), Effect.provideLayer(layer), Effect.runPromise), - ).resolves.toBeUndefined() - expect(map.size).toStrictEqual(0) - }) - }) -}) diff --git a/packages/cache-effect-ts/src/MapCache.ts b/packages/cache-effect-ts/src/MapCache.ts deleted file mode 100644 index 231c7c1..0000000 --- a/packages/cache-effect-ts/src/MapCache.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Effect } from '@effect-ts/core' -import * as fpTs from '@imho/cache-fp-ts' -import { EffectTsToFpTsLog, HasLog, Log } from '@imho/log-effect-ts' -import { Cache } from './Cache' -import { FpTsToEffectTsCache } from './FpTsToEffectTsCache' - -export const MapCache = (map = new Map()) => - Effect.accessService(HasLog)( - (log): Cache => - new (class MapCache extends FpTsToEffectTsCache { - constructor(map: Map, log: Log) { - super(fpTs.MapCache(map)(new EffectTsToFpTsLog(log))) - } - })(map, log), - ) diff --git a/packages/cache-effect-ts/src/index.ts b/packages/cache-effect-ts/src/index.ts deleted file mode 100644 index 56184e8..0000000 --- a/packages/cache-effect-ts/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Cache' -export * from './FpTsToEffectTsCache' -export * from './MapCache' diff --git a/packages/cache-effect-ts/tsconfig.json b/packages/cache-effect-ts/tsconfig.json deleted file mode 100644 index 4b758a9..0000000 --- a/packages/cache-effect-ts/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../cache" }, - { "path": "../cache-fp-ts" }, - { "path": "../codec" }, - { "path": "../codec-effect-ts" }, - { "path": "../codec-effect-ts-io-ts" }, - { "path": "../effect-effect-ts" }, - { "path": "../log-effect-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/cache-fp-ts-redis/README.md b/packages/cache-fp-ts-redis/README.md deleted file mode 100644 index f0d366d..0000000 --- a/packages/cache-fp-ts-redis/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/cache-fp-ts-redis - -[![npm](https://img.shields.io/npm/v/@imho/cache-fp-ts-redis)](https://www.npmjs.com/package/@imho/cache-fp-ts-redis) diff --git a/packages/cache-fp-ts-redis/src/RedisCache.test.ts b/packages/cache-fp-ts-redis/src/RedisCache.test.ts deleted file mode 100644 index b172471..0000000 --- a/packages/cache-fp-ts-redis/src/RedisCache.test.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { Cache } from '@imho/cache-fp-ts' -import { IoTsCodec } from '@imho/codec-fp-ts-io-ts' -import { VoidLog } from '@imho/log-fp-ts' -import { RedisFlushModes, createClient } from '@redis/client' -import { either, readerTaskEither, taskEither } from 'fp-ts' -import { pipe } from 'fp-ts/function' -import * as t from 'io-ts' -import { mapRedis } from '../../../test/redis' -import { RedisCache } from './RedisCache' - -describe('RedisCache', () => { - const redis = createClient({ url: process.env.REDIS_URL }) - const cache = RedisCache(redis)(new VoidLog()) - - beforeEach(async () => { - await mapRedis(redis, (redis) => redis.flushDb(RedisFlushModes.ASYNC)) - await redis.quit() - }) - - afterAll(async () => { - await redis.quit() - }) - - test('connecting to Redis', async () => { - await expect(Cache.has('foo')(cache)()).resolves.not.toThrow() - }) - - test('using an already open connection', async () => { - await expect( - pipe( - Cache.has('foo'), - readerTaskEither.chain(() => Cache.has('foo')), - )(cache)(), - ).resolves.not.toThrow() - }) - - describe('has', () => { - test('checking for missing item', async () => { - await expect(Cache.has('foo')(cache)()).resolves.toStrictEqual( - either.right(false), - ) - }) - - test('checking for existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) - await expect(Cache.has('foo')(cache)()).resolves.toStrictEqual( - either.right(true), - ) - }) - }) - - describe('get', () => { - test('failing to fetch data', async () => { - class FooError extends Error {} - expect( - ( - (await Cache.get('foo', new IoTsCodec(t.any), () => - taskEither.left(new FooError()), - )(cache)()) as any - ).left, - ).toBeInstanceOf(FooError) - }) - - test('fetching data on missing item', async () => { - await expect( - Cache.get('foo', new IoTsCodec(t.any), () => taskEither.right('bar'))( - cache, - )(), - ).resolves.toStrictEqual(either.right('bar')) - }) - - test('fetching data on invalid codec', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect( - Cache.get('foo', new IoTsCodec(t.never), () => taskEither.right('bar'))( - cache, - )(), - ).resolves.toStrictEqual(either.right('bar')) - }) - - test('getting existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect( - Cache.get('foo', new IoTsCodec(t.any), () => taskEither.right('bar'))( - cache, - )(), - ).resolves.toStrictEqual(either.right('qux')) - }) - }) - - describe('delete', () => { - test('deleting missing item', async () => { - await expect(Cache.delete('foo')(cache)()).resolves.toStrictEqual( - either.right(false), - ) - }) - - test('deleting existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect(Cache.delete('foo')(cache)()).resolves.toStrictEqual( - either.right(true), - ) - await expect( - mapRedis(redis, (redis) => redis.exists('foo')), - ).resolves.toStrictEqual(0) - }) - }) - - describe('clear', () => { - test('clearing cache', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) - await expect(Cache.clear()(cache)()).resolves.toStrictEqual( - either.right(undefined), - ) - await expect( - mapRedis(redis, (redis) => redis.dbSize()), - ).resolves.toStrictEqual(0) - }) - }) -}) diff --git a/packages/cache-fp-ts-redis/src/RedisCache.ts b/packages/cache-fp-ts-redis/src/RedisCache.ts deleted file mode 100644 index d50f8a3..0000000 --- a/packages/cache-fp-ts-redis/src/RedisCache.ts +++ /dev/null @@ -1,204 +0,0 @@ -import { CacheError } from '@imho/cache' -import { Cache } from '@imho/cache-fp-ts' -import { CodecError } from '@imho/codec' -import { Decoder } from '@imho/codec-fp-ts' -import { IoTsCodec } from '@imho/codec-fp-ts-io-ts' -import { Log } from '@imho/log-fp-ts' -import { - RedisClientType, - RedisFlushModes, - RedisFunctions, - RedisModules, - RedisScripts, -} from '@redis/client' -import { reader, task, taskEither } from 'fp-ts' -import { TaskEither } from 'fp-ts/TaskEither' -import { identity, pipe } from 'fp-ts/function' -import * as t from 'io-ts' -import * as tt from 'io-ts-types' -import { CacheItemNotFoundError } from './CacheItemNotFoundError' - -const channel = 'RedisCache' - -export const RedisCache = < - M extends RedisModules, - F extends RedisFunctions, - S extends RedisScripts, ->( - redis: RedisClientType, -) => - pipe( - reader.ask(), - reader.map( - (log): Cache => - new (class RedisCache implements Cache { - constructor( - private readonly redis: RedisClientType, - private readonly log: Log, - ) {} - - has(key: string) { - return pipe( - this.connect(), - taskEither.chain(() => - taskEither.tryCatch( - async () => (await this.redis.exists(key)) === 1, - (cause) => - new CacheError(`Cannot check for item "${key}" on Redis`, { - cause, - }), - ), - ), - taskEither.orElseFirstTaskK((error) => - this.log.error('Cache item not found', { - channel, - error, - key, - }), - ), - ) - } - - get( - key: string, - decoder: Decoder, - onMiss: () => TaskEither, - ) { - return pipe( - this.has(key), - taskEither.filterOrElseW( - identity, - () => - new CacheItemNotFoundError(`Cannot find cache item "${key}"`), - ), - taskEither.chain(() => - taskEither.tryCatch( - () => this.redis.get(key), - (cause) => - new CacheError(`Cannot get item "${key}" from Redis`, { - cause, - }), - ), - ), - taskEither.chainEitherKW((u) => - new IoTsCodec(t.string.pipe(tt.JsonFromString)).decode(u), - ), - taskEither.chainEitherKW((json) => decoder.decode(json)), - taskEither.tapTask(() => - this.log.debug('Cache item retrieved', { channel, key }), - ), - taskEither.orElseFirstTaskK((error) => - error instanceof CacheItemNotFoundError - ? this.log.debug('Cache item not found', { channel, key }) - : error instanceof CodecError - ? this.log.error('Cache item decoding failed', { - channel, - error, - key, - codec: decoder.name, - }) - : this.log.error('Cache item not found', { - channel, - error, - key, - }), - ), - taskEither.altW(() => - pipe( - onMiss(), - taskEither.tap((a) => - taskEither.tryCatch( - () => this.redis.set(key, JSON.stringify(a)), - (cause) => - new CacheError(`Cannot save item "${key}" to Redis`, { - cause, - }), - ), - ), - taskEither.tapTask(() => - this.log.debug('Cache item refreshed', { channel, key }), - ), - taskEither.orElseFirstTaskK((error) => - error instanceof CacheError - ? this.log.error('Cache item not saved', { - channel, - error, - key, - }) - : task.of(undefined), - ), - ), - ), - ) - } - - delete(key: string) { - return pipe( - this.connect(), - taskEither.chain(() => - taskEither.tryCatch( - async () => (await this.redis.del(key)) === 1, - (cause) => - new CacheError(`Cannot delete item "${key}" from Redis`, { - cause, - }), - ), - ), - taskEither.tapTask((found) => - this.log.debug( - found - ? 'Cache item deleted' - : 'Cache item not found for deletion', - { channel, key }, - ), - ), - taskEither.orElseFirstTaskK((error) => - this.log.error('Cache item not deleted', { - channel, - error, - key, - }), - ), - ) - } - - clear() { - return pipe( - this.connect(), - taskEither.chain(() => - taskEither.tryCatch( - async () => this.redis.flushDb(RedisFlushModes.ASYNC), - (cause) => - new CacheError('Cannot flush Redis database', { cause }), - ), - ), - taskEither.asUnit, - taskEither.tapTask(() => - this.log.debug('Cache cleared', { channel }), - ), - taskEither.orElseFirstTaskK((error) => - this.log.error('Cache not cleared', { channel, error }), - ), - ) - } - - private connect() { - return this.redis.isReady - ? taskEither.of(undefined) - : pipe( - taskEither.tryCatch( - () => this.redis.connect(), - (cause) => - new CacheError('Cannot connect to Redis', { cause }), - ), - taskEither.tapTask(() => - this.log.debug('Connection opened', { channel }), - ), - taskEither.orElseFirstTaskK((error) => - this.log.error('Connection failed', { channel, error }), - ), - ) - } - })(redis, log), - ), - ) diff --git a/packages/cache-fp-ts-redis/src/index.ts b/packages/cache-fp-ts-redis/src/index.ts deleted file mode 100644 index 611b555..0000000 --- a/packages/cache-fp-ts-redis/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './RedisCache' diff --git a/packages/cache-fp-ts-redis/tsconfig.json b/packages/cache-fp-ts-redis/tsconfig.json deleted file mode 100644 index 83b8825..0000000 --- a/packages/cache-fp-ts-redis/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../../test" }, - { "path": "../cache" }, - { "path": "../cache-fp-ts" }, - { "path": "../codec" }, - { "path": "../codec-fp-ts" }, - { "path": "../codec-fp-ts-io-ts" }, - { "path": "../log-fp-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/cache-fp-ts/CHANGELOG.md b/packages/cache-fp-ts/CHANGELOG.md deleted file mode 100644 index a6210db..0000000 --- a/packages/cache-fp-ts/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/cache-fp-ts@0.3.0...@imho/cache-fp-ts@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/cache-fp-ts - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/cache-fp-ts@0.2.0...@imho/cache-fp-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **cache:** add Cache module ([8b6a3e5](https://github.com/xzhavilla/imho/commit/8b6a3e557cc0759c0435c529b17e1c5b6a83d899)) diff --git a/packages/cache-fp-ts/README.md b/packages/cache-fp-ts/README.md deleted file mode 100644 index c55fd1e..0000000 --- a/packages/cache-fp-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/cache-fp-ts - -[![npm](https://img.shields.io/npm/v/@imho/cache-fp-ts)](https://www.npmjs.com/package/@imho/cache-fp-ts) diff --git a/packages/cache-fp-ts/package.json b/packages/cache-fp-ts/package.json deleted file mode 100644 index 4aa2067..0000000 --- a/packages/cache-fp-ts/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@imho/cache-fp-ts", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/cache": "^0.2.0 || ^0.3.0", - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/codec-fp-ts": "^0.2.0", - "@imho/effect-fp-ts": "^0.2.0 || ^0.3.0", - "@imho/log-fp-ts": "^0.2.0 || ^0.3.0", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/cache-fp-ts/src/Cache.ts b/packages/cache-fp-ts/src/Cache.ts deleted file mode 100644 index 60440d9..0000000 --- a/packages/cache-fp-ts/src/Cache.ts +++ /dev/null @@ -1,45 +0,0 @@ -import * as _ from '@imho/cache' -import { CacheError } from '@imho/cache' -import { CodecError } from '@imho/codec' -import { Decoder } from '@imho/codec-fp-ts' -import { FpTs } from '@imho/effect-fp-ts' -import { readerTaskEither } from 'fp-ts' -import { TaskEither } from 'fp-ts/TaskEither' -import { pipe } from 'fp-ts/function' - -export interface Cache extends FpTs> { - get( - key: string, - decoder: Decoder, - onMiss: () => TaskEither, - ): TaskEither -} - -export const Cache = { - has: (key: string) => - pipe( - readerTaskEither.ask(), - readerTaskEither.chainTaskEitherK((cache) => cache.has(key)), - ), - get: ( - key: string, - decoder: Decoder, - onMiss: () => TaskEither, - ) => - pipe( - readerTaskEither.ask(), - readerTaskEither.chainTaskEitherK((cache) => - cache.get(key, decoder, onMiss), - ), - ), - delete: (key: string) => - pipe( - readerTaskEither.ask(), - readerTaskEither.chainTaskEitherK((cache) => cache.delete(key)), - ), - clear: () => - pipe( - readerTaskEither.ask(), - readerTaskEither.chainTaskEitherK((cache) => cache.clear()), - ), -} diff --git a/packages/cache-fp-ts/src/MapCache.test.ts b/packages/cache-fp-ts/src/MapCache.test.ts deleted file mode 100644 index a2eb50a..0000000 --- a/packages/cache-fp-ts/src/MapCache.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { IoTsCodec } from '@imho/codec-fp-ts-io-ts' -import { VoidLog } from '@imho/log-fp-ts' -import { either, taskEither } from 'fp-ts' -import {} from 'fp-ts/function' -import * as t from 'io-ts' -import { Cache } from './Cache' -import { MapCache } from './MapCache' - -describe('MapCache', () => { - const map = new Map() - const cache = MapCache(map)(new VoidLog()) - - beforeEach(() => { - map.clear() - }) - - describe('has', () => { - test('checking for missing item', async () => { - await expect(Cache.has('foo')(cache)()).resolves.toStrictEqual( - either.right(false), - ) - }) - - test('checking for existing item', async () => { - map.set('foo', 'bar') - await expect(Cache.has('foo')(cache)()).resolves.toStrictEqual( - either.right(true), - ) - }) - }) - - describe('get', () => { - test('failing to fetch data', async () => { - expect( - ( - (await Cache.get('foo', new IoTsCodec(t.any), () => - taskEither.left(new Error()), - )(cache)()) as any - ).left, - ).toBeInstanceOf(Error) - }) - - test('fetching data on missing item', async () => { - await expect( - Cache.get('foo', new IoTsCodec(t.any), () => taskEither.right('bar'))( - cache, - )(), - ).resolves.toStrictEqual(either.right('bar')) - }) - - test('fetching data on invalid codec', async () => { - map.set('foo', 'qux') - await expect( - Cache.get('foo', new IoTsCodec(t.never), () => taskEither.right('bar'))( - cache, - )(), - ).resolves.toStrictEqual(either.right('bar')) - }) - - test('getting existing item', async () => { - map.set('foo', 'qux') - await expect( - Cache.get('foo', new IoTsCodec(t.any), () => taskEither.right('bar'))( - cache, - )(), - ).resolves.toStrictEqual(either.right('qux')) - }) - }) - - describe('delete', () => { - test('deleting missing item', async () => { - await expect(Cache.delete('foo')(cache)()).resolves.toStrictEqual( - either.right(false), - ) - }) - - test('deleting existing item', async () => { - map.set('foo', 'bar') - await expect(Cache.delete('foo')(cache)()).resolves.toStrictEqual( - either.right(true), - ) - expect(map.has('foo')).toBeFalsy() - }) - }) - - describe('clear', () => { - test('clearing cache', async () => { - map.set('foo', 'bar') - await expect(Cache.clear()(cache)()).resolves.toStrictEqual( - either.right(undefined), - ) - expect(map.size).toStrictEqual(0) - }) - }) -}) diff --git a/packages/cache-fp-ts/src/MapCache.ts b/packages/cache-fp-ts/src/MapCache.ts deleted file mode 100644 index a2dc93b..0000000 --- a/packages/cache-fp-ts/src/MapCache.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { CacheError } from '@imho/cache' -import { CodecError } from '@imho/codec' -import { Decoder } from '@imho/codec-fp-ts' -import { Log } from '@imho/log-fp-ts' -import { reader, taskEither } from 'fp-ts' -import { TaskEither } from 'fp-ts/TaskEither' -import { identity, pipe } from 'fp-ts/function' -import { Cache } from './Cache' - -const channel = 'MapCache' - -export const MapCache = (map = new Map()) => - pipe( - reader.ask(), - reader.map( - (log): Cache => - new (class MapCache implements Cache { - constructor( - private readonly map: Map, - private readonly log: Log, - ) {} - - has(key: string) { - return taskEither.right(this.map.has(key)) - } - - get( - key: string, - decoder: Decoder, - onMiss: () => TaskEither, - ) { - return pipe( - this.has(key), - taskEither.filterOrElse( - identity, - () => new CacheError(`Cannot find cache item "${key}"`), - ), - taskEither.map(() => this.map.get(key)), - taskEither.chainEitherKW((u) => decoder.decode(u)), - taskEither.tapTask(() => - this.log.debug('Cache item retrieved', { - channel, - key, - }), - ), - taskEither.orElseFirstTaskK((error) => - error instanceof CodecError - ? this.log.error('Cache item decoding failed', { - channel, - error, - key, - codec: decoder.name, - }) - : this.log.debug('Cache item not found', { - channel, - key, - }), - ), - taskEither.altW(() => - pipe( - onMiss(), - taskEither.tapIO((a) => () => this.map.set(key, a)), - taskEither.tapTask(() => - this.log.debug('Cache item refreshed', { - channel, - key, - }), - ), - ), - ), - ) - } - - delete(key: string) { - return pipe( - taskEither.fromIO(() => this.map.delete(key)), - taskEither.tapTask((found) => - this.log.debug( - found - ? 'Cache item deleted' - : 'Cache item not found for deletion', - { channel, key }, - ), - ), - ) - } - - clear() { - return pipe( - taskEither.fromIO(() => this.map.clear()), - taskEither.tapTask(() => - this.log.debug('Cache cleared', { channel }), - ), - ) - } - })(map, log), - ), - ) diff --git a/packages/cache-fp-ts/src/index.ts b/packages/cache-fp-ts/src/index.ts deleted file mode 100644 index d5277e0..0000000 --- a/packages/cache-fp-ts/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Cache' -export * from './MapCache' diff --git a/packages/cache-fp-ts/tsconfig.json b/packages/cache-fp-ts/tsconfig.json deleted file mode 100644 index 9d604d8..0000000 --- a/packages/cache-fp-ts/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../cache" }, - { "path": "../codec" }, - { "path": "../codec-fp-ts" }, - { "path": "../codec-fp-ts-io-ts" }, - { "path": "../effect-fp-ts" }, - { "path": "../log-fp-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/cache-raw-redis/CHANGELOG.md b/packages/cache-raw-redis/CHANGELOG.md deleted file mode 100644 index 642a6a7..0000000 --- a/packages/cache-raw-redis/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/cache-raw-redis@0.3.0...@imho/cache-raw-redis@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/cache-raw-redis - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/cache-raw-redis@0.2.0...@imho/cache-raw-redis@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **cache:** add Redis Cache implementation ([804d190](https://github.com/xzhavilla/imho/commit/804d19040de57074a8aa45edf6e945f9e80cc315)) diff --git a/packages/cache-raw-redis/README.md b/packages/cache-raw-redis/README.md deleted file mode 100644 index 1bfd8dd..0000000 --- a/packages/cache-raw-redis/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/cache-raw-redis - -[![npm](https://img.shields.io/npm/v/@imho/cache-raw-redis)](https://www.npmjs.com/package/@imho/cache-raw-redis) diff --git a/packages/cache-raw-redis/package.json b/packages/cache-raw-redis/package.json deleted file mode 100644 index 6320bc4..0000000 --- a/packages/cache-raw-redis/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@imho/cache-raw-redis", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/cache-fp-ts-redis": "^0.3.1" - }, - "peerDependencies": { - "@imho/cache-raw": "^0.2.0 || ^0.3.0", - "@imho/log-raw": "^0.2.0 || ^0.3.0", - "@redis/client": "^1.5.8" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/cache-raw-redis/src/RedisCache.ts b/packages/cache-raw-redis/src/RedisCache.ts deleted file mode 100644 index 2896a16..0000000 --- a/packages/cache-raw-redis/src/RedisCache.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as fpTs from '@imho/cache-fp-ts-redis' -import { FpTsToRawCache } from '@imho/cache-raw' -import { Log, RawToFpTsLog } from '@imho/log-raw' -import { - RedisClientType, - RedisFunctions, - RedisModules, - RedisScripts, -} from '@redis/client' - -export class RedisCache< - M extends RedisModules, - F extends RedisFunctions, - S extends RedisScripts, -> extends FpTsToRawCache { - constructor(redis: RedisClientType, log: Log) { - super(fpTs.RedisCache(redis)(new RawToFpTsLog(log))) - } -} diff --git a/packages/cache-raw-redis/src/index.ts b/packages/cache-raw-redis/src/index.ts deleted file mode 100644 index 611b555..0000000 --- a/packages/cache-raw-redis/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './RedisCache' diff --git a/packages/cache-raw-redis/tsconfig.json b/packages/cache-raw-redis/tsconfig.json deleted file mode 100644 index f2c4c47..0000000 --- a/packages/cache-raw-redis/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../../test" }, - { "path": "../cache-fp-ts-redis" }, - { "path": "../cache-raw" }, - { "path": "../codec-raw-io-ts" }, - { "path": "../log-raw" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/cache-raw/CHANGELOG.md b/packages/cache-raw/CHANGELOG.md deleted file mode 100644 index 840f11c..0000000 --- a/packages/cache-raw/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/cache-raw@0.3.0...@imho/cache-raw@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/cache-raw - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/cache-raw@0.2.0...@imho/cache-raw@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **cache:** add Cache module ([8b6a3e5](https://github.com/xzhavilla/imho/commit/8b6a3e557cc0759c0435c529b17e1c5b6a83d899)) diff --git a/packages/cache-raw/README.md b/packages/cache-raw/README.md deleted file mode 100644 index 6e61aee..0000000 --- a/packages/cache-raw/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/cache-raw - -[![npm](https://img.shields.io/npm/v/@imho/cache-raw)](https://www.npmjs.com/package/@imho/cache-raw) diff --git a/packages/cache-raw/package.json b/packages/cache-raw/package.json deleted file mode 100644 index 1edfd36..0000000 --- a/packages/cache-raw/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@imho/cache-raw", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "fp-ts": "^2.16.0" - }, - "peerDependencies": { - "@imho/cache": "^0.2.0 || ^0.3.0", - "@imho/cache-fp-ts": "^0.2.0 || ^0.3.0", - "@imho/codec-raw": "^0.2.0", - "@imho/effect-raw": "^0.2.0 || ^0.3.0", - "@imho/log-raw": "^0.2.0 || ^0.3.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/cache-raw/src/Cache.ts b/packages/cache-raw/src/Cache.ts deleted file mode 100644 index d0a5898..0000000 --- a/packages/cache-raw/src/Cache.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as _ from '@imho/cache' -import { Decoder } from '@imho/codec-raw' -import { Raw } from '@imho/effect-raw' - -export interface Cache extends Raw> { - get(key: string, decoder: Decoder, onMiss: () => Promise): Promise -} diff --git a/packages/cache-raw/src/FpTsToRawCache.ts b/packages/cache-raw/src/FpTsToRawCache.ts deleted file mode 100644 index e758e5b..0000000 --- a/packages/cache-raw/src/FpTsToRawCache.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as fpTs from '@imho/cache-fp-ts' -import { Decoder, RawToFpTsDecoder } from '@imho/codec-raw' -import { either, taskEither } from 'fp-ts' -import { Cache } from './Cache' - -export class FpTsToRawCache implements Cache { - constructor(private readonly cache: fpTs.Cache) {} - - async has(key: string) { - const found = await this.cache.has(key)() - if (either.isLeft(found)) { - throw found.left - } - - return found.right - } - - async get(key: string, decoder: Decoder, onMiss: () => Promise) { - const a = await this.cache.get(key, new RawToFpTsDecoder(decoder), () => - taskEither.tryCatch(onMiss, (cause) => - cause instanceof Error - ? cause - : new Error('Cannot fetch data', { cause }), - ), - )() - if (either.isLeft(a)) { - throw a.left - } - - return a.right - } - - async delete(key: string) { - const found = await this.cache.delete(key)() - if (either.isLeft(found)) { - throw found.left - } - - return found.right - } - - async clear() { - const cleared = await this.cache.clear()() - if (either.isLeft(cleared)) { - throw cleared.left - } - - return cleared.right - } -} diff --git a/packages/cache-raw/src/MapCache.test.ts b/packages/cache-raw/src/MapCache.test.ts deleted file mode 100644 index d9c56b1..0000000 --- a/packages/cache-raw/src/MapCache.test.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { IoTsCodec } from '@imho/codec-raw-io-ts' -import { VoidLog } from '@imho/log-raw' -import * as t from 'io-ts' -import { MapCache } from './MapCache' - -describe('MapCache', () => { - const map = new Map() - const cache = new MapCache(new VoidLog(), map) - - beforeEach(() => { - map.clear() - }) - - describe('has', () => { - test('checking for missing item', async () => { - await expect(cache.has('foo')).resolves.toBeFalsy() - }) - - test('checking for existing item', async () => { - map.set('foo', 'bar') - await expect(cache.has('foo')).resolves.toBeTruthy() - }) - }) - - describe('get', () => { - test('failing to fetch data', async () => { - class FooError extends Error {} - await expect( - cache.get('foo', new IoTsCodec(t.any), async () => { - throw new FooError() - }), - ).rejects.toBeInstanceOf(FooError) - }) - - test('failing to fetch data with no error', async () => { - await expect( - cache.get('foo', new IoTsCodec(t.any), () => Promise.reject()), - ).rejects.toBeInstanceOf(Error) - }) - - test('fetching data on missing item', async () => { - await expect( - cache.get('foo', new IoTsCodec(t.any), async () => 'bar'), - ).resolves.toStrictEqual('bar') - }) - - test('fetching data on invalid codec', async () => { - map.set('foo', 'qux') - await expect( - cache.get('foo', new IoTsCodec(t.never), async () => 'bar'), - ).resolves.toStrictEqual('bar') - }) - - test('getting existing item', async () => { - map.set('foo', 'qux') - await expect( - cache.get('foo', new IoTsCodec(t.any), async () => 'bar'), - ).resolves.toStrictEqual('qux') - }) - }) - - describe('delete', () => { - test('deleting missing item', async () => { - await expect(cache.delete('foo')).resolves.toBeFalsy() - }) - - test('deleting existing item', async () => { - map.set('foo', 'bar') - await expect(cache.delete('foo')).resolves.toBeTruthy() - expect(map.has('foo')).toBeFalsy() - }) - }) - - describe('clear', () => { - test('clearing cache', async () => { - map.set('foo', 'bar') - await expect(cache.clear()).resolves.toBeUndefined() - expect(map.size).toStrictEqual(0) - }) - }) -}) diff --git a/packages/cache-raw/src/MapCache.ts b/packages/cache-raw/src/MapCache.ts deleted file mode 100644 index cefb6bf..0000000 --- a/packages/cache-raw/src/MapCache.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as fpTs from '@imho/cache-fp-ts' -import { Log, RawToFpTsLog } from '@imho/log-raw' -import { FpTsToRawCache } from './FpTsToRawCache' - -export class MapCache extends FpTsToRawCache { - constructor(log: Log, map = new Map()) { - super(fpTs.MapCache(map)(new RawToFpTsLog(log))) - } -} diff --git a/packages/cache-raw/src/index.ts b/packages/cache-raw/src/index.ts deleted file mode 100644 index 16bf453..0000000 --- a/packages/cache-raw/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Cache' -export * from './FpTsToRawCache' -export * from './MapCache' diff --git a/packages/cache-raw/tsconfig.json b/packages/cache-raw/tsconfig.json deleted file mode 100644 index d6e04ef..0000000 --- a/packages/cache-raw/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../cache" }, - { "path": "../cache-fp-ts" }, - { "path": "../codec-raw" }, - { "path": "../codec-raw-io-ts" }, - { "path": "../effect-raw" }, - { "path": "../log-raw" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/cache-fp-ts-redis/CHANGELOG.md b/packages/cache-redis/CHANGELOG.md similarity index 100% rename from packages/cache-fp-ts-redis/CHANGELOG.md rename to packages/cache-redis/CHANGELOG.md diff --git a/packages/cache-redis/README.md b/packages/cache-redis/README.md new file mode 100644 index 0000000..c6012b8 --- /dev/null +++ b/packages/cache-redis/README.md @@ -0,0 +1,3 @@ +# @imho/cache-redis + +[![npm](https://img.shields.io/npm/v/@imho/cache-redis)](https://www.npmjs.com/package/@imho/cache-redis) diff --git a/packages/cache-fp-ts-redis/package.json b/packages/cache-redis/package.json similarity index 52% rename from packages/cache-fp-ts-redis/package.json rename to packages/cache-redis/package.json index df44193..bc27a62 100644 --- a/packages/cache-fp-ts-redis/package.json +++ b/packages/cache-redis/package.json @@ -1,16 +1,15 @@ { - "name": "@imho/cache-fp-ts-redis", + "name": "@imho/cache-redis", "version": "0.3.1", "description": "", "license": "MIT", "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "dist/src/index.js", + "types": "dist/src/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist/src", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,18 +17,16 @@ "prepack": "npm run build" }, "dependencies": { - "@imho/codec-fp-ts-io-ts": "^0.3.1", + "@imho/codec-io-ts": "*", "io-ts": "^2.2.20", "io-ts-types": "^0.5.19" }, "peerDependencies": { - "@imho/cache": "^0.2.0 || ^0.3.0", - "@imho/cache-fp-ts": "^0.2.0 || ^0.3.0", - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/codec-fp-ts": "^0.2.0", - "@imho/log-fp-ts": "^0.2.0 || ^0.3.0", + "@imho/cache": "*", + "@imho/codec": "*", + "@imho/log": "*", "@redis/client": "^1.5.8", - "fp-ts": "^2.16.0" + "@xzhayon/fx": "^0.4.0" }, "publishConfig": { "access": "public" diff --git a/packages/cache-fp-ts-redis/src/CacheItemNotFoundError.ts b/packages/cache-redis/src/CacheItemNotFoundError.ts similarity index 71% rename from packages/cache-fp-ts-redis/src/CacheItemNotFoundError.ts rename to packages/cache-redis/src/CacheItemNotFoundError.ts index 35a3fb6..49bc0d3 100644 --- a/packages/cache-fp-ts-redis/src/CacheItemNotFoundError.ts +++ b/packages/cache-redis/src/CacheItemNotFoundError.ts @@ -2,6 +2,6 @@ import { CacheError } from '@imho/cache' export const CacheItemNotFoundErrorURI = Symbol() export class CacheItemNotFoundError extends CacheError { - private readonly [CacheItemNotFoundErrorURI]!: typeof CacheItemNotFoundErrorURI + readonly [CacheItemNotFoundErrorURI]!: typeof CacheItemNotFoundErrorURI readonly name: string = 'CacheItemNotFoundError' } diff --git a/packages/cache-redis/src/FxRedisCache.test.ts b/packages/cache-redis/src/FxRedisCache.test.ts new file mode 100644 index 0000000..71af885 --- /dev/null +++ b/packages/cache-redis/src/FxRedisCache.test.ts @@ -0,0 +1,153 @@ +import { Cache } from '@imho/cache' +import { IoTsCodec } from '@imho/codec-io-ts' +import { FxVoidLog, Log } from '@imho/log' +import { RedisClientType, RedisFlushModes } from '@redis/client' +import { layer, perform, run } from '@xzhayon/fx' +import * as t from 'io-ts' +import { use } from '../test/Redis' +import { RedisMock } from '../test/RedisMock' +import { FxRedisCache } from './FxRedisCache' + +describe('FxRedisCache', () => { + const redis = new RedisMock() as any as RedisClientType + const _layer = layer() + .with(Cache, FxRedisCache(redis)) + .with(Log, FxVoidLog()) + .do() + + beforeEach(async () => { + await use(redis, (redis) => redis.flushDb(RedisFlushModes.ASYNC)) + await redis.quit() + }) + + afterAll(async () => { + await redis.quit() + }) + + test('connecting to Redis', async () => { + function* f() { + return yield* perform(Cache.has('foo')) + } + + await expect(run(f(), _layer)).resolves.not.toThrow() + }) + + test('using an already open connection', async () => { + function* f() { + yield* perform(Cache.clear()) + + return yield* perform(Cache.has('foo')) + } + + await expect(run(f(), _layer)).resolves.not.toThrow() + }) + + describe('has', () => { + test('checking for missing item', async () => { + function* f() { + return yield* perform(Cache.has('foo')) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual(false) + }) + + test('checking for existing item', async () => { + await use(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) + function* f() { + return yield* perform(Cache.has('foo')) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual(true) + }) + }) + + describe('get', () => { + test('failing to fetch data', async () => { + class FooError extends Error {} + + function* f() { + return yield* perform( + Cache.get('foo', new IoTsCodec(t.any), () => { + throw new FooError() + }), + ) + } + + await expect(run(f(), _layer)).rejects.toBeInstanceOf(FooError) + }) + + test('fetching data on missing item', async () => { + function* f() { + return yield* perform( + Cache.get('foo', new IoTsCodec(t.any), function* () { + return 'bar' + }), + ) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual('bar') + }) + + test('fetching data on invalid codec', async () => { + await use(redis, (redis) => redis.set('foo', JSON.stringify(42))) + function* f() { + return yield* perform( + Cache.get('foo', new IoTsCodec(t.string), function* () { + return 'bar' + }), + ) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual('bar') + }) + + test('getting existing item', async () => { + await use(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + function* f() { + return yield* perform( + Cache.get('foo', new IoTsCodec(t.any), function* () { + return 'bar' + }), + ) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual('qux') + }) + }) + + describe('delete', () => { + test('deleting missing item', async () => { + function* f() { + return yield* perform(Cache.delete('foo')) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual(false) + }) + + test('deleting existing item', async () => { + await use(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + function* f() { + return yield* perform(Cache.delete('foo')) + } + + await expect(run(f(), _layer)).resolves.toStrictEqual(true) + await expect( + use(redis, (redis) => redis.exists('foo')), + ).resolves.toStrictEqual(0) + }) + }) + + describe('clear', () => { + test('clearing cache', async () => { + await use(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) + function* f() { + return yield* perform(Cache.clear()) + } + + await expect(run(f(), _layer)).resolves.toBeUndefined() + await expect( + use(redis, (redis) => redis.dbSize()), + ).resolves.toStrictEqual(0) + }) + }) +}) diff --git a/packages/cache-redis/src/FxRedisCache.ts b/packages/cache-redis/src/FxRedisCache.ts new file mode 100644 index 0000000..4341268 --- /dev/null +++ b/packages/cache-redis/src/FxRedisCache.ts @@ -0,0 +1,160 @@ +import { CacheError, FxCache } from '@imho/cache' +import { CodecError, Decoder } from '@imho/codec' +import { IoTsCodec } from '@imho/codec-io-ts' +import { Log } from '@imho/log' +import { + RedisClientType, + RedisFlushModes, + RedisFunctions, + RedisModules, + RedisScripts, +} from '@redis/client' +import { Handler, perform } from '@xzhayon/fx' +import * as t from 'io-ts' +import * as tt from 'io-ts-types' +import { CacheItemNotFoundError } from './CacheItemNotFoundError' + +const source = 'FxRedisCache' + +export function FxRedisCache< + M extends RedisModules = Record, + F extends RedisFunctions = Record, + S extends RedisScripts = Record, +>(redis: RedisClientType) { + async function* connect() { + if (redis.isReady) { + return + } + + try { + await redis.connect() + yield* perform(Log.debug('Connection opened', { source })) + + return + } catch (cause) { + const error = new CacheError('Cannot connect to Redis', { cause }) + yield* perform(Log.error('Connection failed', { error, source })) + + throw error + } + } + + async function* has(key: string) { + yield* connect() + + try { + return (await redis.exists(key)) === 1 + } catch (cause) { + const error = new CacheError(`Cannot check for item "${key}" on Redis`, { + cause, + }) + yield* perform(Log.error('Cache item not found', { error, key, source })) + + throw error + } + } + + return { + has, + async *get>( + key: string, + decoder: Decoder, + onMiss: () => G, + ) { + try { + if (!(yield* has(key))) { + throw new CacheItemNotFoundError(`Cannot find cache item "${key}"`) + } + + const value = decoder.decode( + new IoTsCodec(t.string.pipe(tt.JsonFromString)).decode( + await redis.get(key), + ), + ) + yield* perform(Log.debug('Cache item retrieved', { key, source })) + + return value + } catch (error) { + if (error instanceof CacheItemNotFoundError) { + yield* perform(Log.debug('Cache item not found', { source })) + } else if (error instanceof CodecError) { + yield* perform( + Log.error('Cache item decoding failed', { + error, + key, + codec: decoder.name, + source, + }), + ) + } else { + yield* perform( + Log.error('Cache item not found', { + error: new CacheError(`Cannot get item "${key}" from Redis`, { + cause: error, + }), + key, + source, + }), + ) + } + } + + const value = yield* onMiss() + + try { + await redis.set(key, JSON.stringify(value)) + yield* perform(Log.debug('Cache item saved', { key, source })) + + return value + } catch (cause) { + const error = new CacheError(`Cannot save item "${key}" to Redis`, { + cause, + }) + yield* perform( + Log.error('Cache item not saved', { error, key, source }), + ) + + throw error + } + }, + async *delete(key: string) { + yield* connect() + + try { + const found = (await redis.del(key)) === 1 + yield* perform( + Log.debug( + found ? 'Cache item deleted' : 'Cache item not found for deletion', + { key, source }, + ), + ) + + return found + } catch (cause) { + const error = new CacheError(`Cannot delete item "${key}" from Redis`, { + cause, + }) + yield* perform( + Log.error('Cache item not deleted', { error, key, source }), + ) + + throw error + } + }, + async *clear() { + yield* connect() + + try { + await redis.flushDb(RedisFlushModes.ASYNC) + yield* perform(Log.debug('Cache cleared', { source })) + + return + } catch (cause) { + const error = new CacheError('Cannot flush Redis database', { cause }) + yield* perform(Log.error('Cache not cleared', { error, source })) + + throw error + } + }, + } satisfies Handler +} diff --git a/packages/cache-raw-redis/src/RedisCache.test.ts b/packages/cache-redis/src/RedisCache.test.ts similarity index 56% rename from packages/cache-raw-redis/src/RedisCache.test.ts rename to packages/cache-redis/src/RedisCache.test.ts index 9c3a440..87023d6 100644 --- a/packages/cache-raw-redis/src/RedisCache.test.ts +++ b/packages/cache-redis/src/RedisCache.test.ts @@ -1,16 +1,17 @@ -import { IoTsCodec } from '@imho/codec-raw-io-ts' -import { VoidLog } from '@imho/log-raw' -import { RedisFlushModes, createClient } from '@redis/client' +import { IoTsCodec } from '@imho/codec-io-ts' +import { VoidLog } from '@imho/log' +import { RedisClientType, RedisFlushModes } from '@redis/client' import * as t from 'io-ts' -import { mapRedis } from '../../../test/redis' +import { use } from '../test/Redis' +import { RedisMock } from '../test/RedisMock' import { RedisCache } from './RedisCache' describe('RedisCache', () => { - const redis = createClient({ url: process.env.REDIS_URL }) + const redis = new RedisMock() as any as RedisClientType const cache = new RedisCache(redis, new VoidLog()) beforeEach(async () => { - await mapRedis(redis, (redis) => redis.flushDb(RedisFlushModes.ASYNC)) + await use(redis, (redis) => redis.flushDb(RedisFlushModes.ASYNC)) await redis.quit() }) @@ -23,37 +24,34 @@ describe('RedisCache', () => { }) test('using an already open connection', async () => { - await expect(cache.has('foo')).resolves.not.toThrow() + await cache.clear() + await expect(cache.has('foo')).resolves.not.toThrow() }) describe('has', () => { test('checking for missing item', async () => { - await expect(cache.has('foo')).resolves.toBeFalsy() + await expect(cache.has('foo')).resolves.toStrictEqual(false) }) test('checking for existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) - await expect(cache.has('foo')).resolves.toBeTruthy() + await use(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) + + await expect(cache.has('foo')).resolves.toStrictEqual(true) }) }) describe('get', () => { test('failing to fetch data', async () => { class FooError extends Error {} + await expect( - cache.get('foo', new IoTsCodec(t.any), async () => { + cache.get('foo', new IoTsCodec(t.any), () => { throw new FooError() }), ).rejects.toBeInstanceOf(FooError) }) - test('failing to fetch data with no error', async () => { - await expect( - cache.get('foo', new IoTsCodec(t.any), () => Promise.reject()), - ).rejects.toBeInstanceOf(Error) - }) - test('fetching data on missing item', async () => { await expect( cache.get('foo', new IoTsCodec(t.any), async () => 'bar'), @@ -61,14 +59,16 @@ describe('RedisCache', () => { }) test('fetching data on invalid codec', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + await use(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + await expect( cache.get('foo', new IoTsCodec(t.never), async () => 'bar'), ).resolves.toStrictEqual('bar') }) test('getting existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + await use(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + await expect( cache.get('foo', new IoTsCodec(t.any), async () => 'bar'), ).resolves.toStrictEqual('qux') @@ -77,24 +77,26 @@ describe('RedisCache', () => { describe('delete', () => { test('deleting missing item', async () => { - await expect(cache.delete('foo')).resolves.toBeFalsy() + await expect(cache.delete('foo')).resolves.toStrictEqual(false) }) test('deleting existing item', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) - await expect(cache.delete('foo')).resolves.toBeTruthy() + await use(redis, (redis) => redis.set('foo', JSON.stringify('qux'))) + + await expect(cache.delete('foo')).resolves.toStrictEqual(true) await expect( - mapRedis(redis, (redis) => redis.exists('foo')), + use(redis, (redis) => redis.exists('foo')), ).resolves.toStrictEqual(0) }) }) describe('clear', () => { test('clearing cache', async () => { - await mapRedis(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) + await use(redis, (redis) => redis.set('foo', JSON.stringify('bar'))) + await expect(cache.clear()).resolves.toBeUndefined() await expect( - mapRedis(redis, (redis) => redis.dbSize()), + use(redis, (redis) => redis.dbSize()), ).resolves.toStrictEqual(0) }) }) diff --git a/packages/cache-redis/src/RedisCache.ts b/packages/cache-redis/src/RedisCache.ts new file mode 100644 index 0000000..6146fb5 --- /dev/null +++ b/packages/cache-redis/src/RedisCache.ts @@ -0,0 +1,150 @@ +import { Cache, CacheError } from '@imho/cache' +import { CodecError, Decoder } from '@imho/codec' +import { IoTsCodec } from '@imho/codec-io-ts' +import { Log } from '@imho/log' +import { + RedisClientType, + RedisFlushModes, + RedisFunctions, + RedisModules, + RedisScripts, +} from '@redis/client' +import * as t from 'io-ts' +import * as tt from 'io-ts-types' +import { CacheItemNotFoundError } from './CacheItemNotFoundError' + +const source = 'RedisCache' + +export class RedisCache< + M extends RedisModules = Record, + F extends RedisFunctions = Record, + S extends RedisScripts = Record, +> implements Cache +{ + constructor( + private readonly redis: RedisClientType, + private readonly log: Log, + ) {} + + async has(key: string) { + await this.connect() + + try { + return (await this.redis.exists(key)) === 1 + } catch (cause) { + const error = new CacheError(`Cannot check for item "${key}" on Redis`, { + cause, + }) + await this.log.error('Cache item not found', { error, key, source }) + + throw error + } + } + + async get(key: string, decoder: Decoder, onMiss: () => Promise) { + try { + if (!(await this.has(key))) { + throw new CacheItemNotFoundError(`Cannot find cache item "${key}"`) + } + + const value = decoder.decode( + new IoTsCodec(t.string.pipe(tt.JsonFromString)).decode( + await this.redis.get(key), + ), + ) + await this.log.debug('Cache item retrieved', { key, source }) + + return value + } catch (error) { + if (error instanceof CacheItemNotFoundError) { + await this.log.debug('Cache item not found', { source }) + } else if (error instanceof CodecError) { + await this.log.error('Cache item decoding failed', { + error, + key, + codec: decoder.name, + source, + }) + } else { + await this.log.error('Cache item not found', { + error: new CacheError(`Cannot get item "${key}" from Redis`, { + cause: error, + }), + key, + source, + }) + } + } + + const value = await onMiss() + + try { + await this.redis.set(key, JSON.stringify(value)) + await this.log.debug('Cache item saved', { key, source }) + + return value + } catch (cause) { + const error = new CacheError(`Cannot save item "${key}" to Redis`, { + cause, + }) + await this.log.error('Cache item not saved', { error, key, source }) + + throw error + } + } + + async delete(key: string) { + await this.connect() + + try { + const found = (await this.redis.del(key)) === 1 + await this.log.debug( + found ? 'Cache item deleted' : 'Cache item not found for deletion', + { key, source }, + ) + + return found + } catch (cause) { + const error = new CacheError(`Cannot delete item "${key}" from Redis`, { + cause, + }) + await this.log.error('Cache item not deleted', { error, key, source }) + + throw error + } + } + + async clear() { + await this.connect() + + try { + await this.redis.flushDb(RedisFlushModes.ASYNC) + await this.log.debug('Cache cleared', { source }) + + return + } catch (cause) { + const error = new CacheError('Cannot flush Redis database', { cause }) + await this.log.error('Cache not cleared', { error, source }) + + throw error + } + } + + private async connect() { + if (this.redis.isReady) { + return + } + + try { + await this.redis.connect() + await this.log.debug('Connection opened', { source }) + + return + } catch (cause) { + const error = new CacheError('Cannot connect to Redis', { cause }) + await this.log.error('Connection failed', { error, source }) + + throw error + } + } +} diff --git a/packages/cache-redis/src/index.ts b/packages/cache-redis/src/index.ts new file mode 100644 index 0000000..46ba0b7 --- /dev/null +++ b/packages/cache-redis/src/index.ts @@ -0,0 +1,2 @@ +export * from './FxRedisCache' +export * from './RedisCache' diff --git a/test/redis.ts b/packages/cache-redis/test/Redis.ts similarity index 90% rename from test/redis.ts rename to packages/cache-redis/test/Redis.ts index b972746..2cb31f8 100644 --- a/test/redis.ts +++ b/packages/cache-redis/test/Redis.ts @@ -5,7 +5,7 @@ import { RedisScripts, } from '@redis/client' -export const mapRedis = async < +export async function use< M extends RedisModules, F extends RedisFunctions, S extends RedisScripts, @@ -13,7 +13,7 @@ export const mapRedis = async < >( redis: RedisClientType, f: (redis: RedisClientType) => Promise, -) => { +) { if (!redis.isReady) { await redis.connect() } diff --git a/packages/cache-redis/test/RedisMock.ts b/packages/cache-redis/test/RedisMock.ts new file mode 100644 index 0000000..0b505ef --- /dev/null +++ b/packages/cache-redis/test/RedisMock.ts @@ -0,0 +1,47 @@ +export class RedisMock { + private ready = false + + constructor(private values: Record = {}) {} + + get isReady() { + return this.ready + } + + async connect() { + this.ready = true + } + + async quit() { + this.ready = false + } + + async dbSize() { + return Object.keys(this.values).length + } + + async exists(key: string) { + return key in this.values ? 1 : 0 + } + + async get(key: string) { + return this.values[key] ?? null + } + + async set(key: string, value: string) { + this.values[key] = value + } + + async del(key: string) { + if ((await this.exists(key)) === 0) { + return 0 + } + + delete this.values[key] + + return 1 + } + + async flushDb() { + this.values = {} + } +} diff --git a/packages/cache-redis/tsconfig.json b/packages/cache-redis/tsconfig.json new file mode 100644 index 0000000..294d979 --- /dev/null +++ b/packages/cache-redis/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.build.json", + "references": [ + { "path": "../cache" }, + { "path": "../codec" }, + { "path": "../codec-io-ts" }, + { "path": "../log" } + ], + "compilerOptions": { "outDir": "dist" } +} diff --git a/packages/cache/package.json b/packages/cache/package.json index 857b3dd..5b40e27 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -7,10 +7,9 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,8 +17,8 @@ "prepack": "npm run build" }, "peerDependencies": { - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/effect": "^0.2.0" + "@imho/codec": "*", + "@xzhayon/fx": "^0.4.0" }, "publishConfig": { "access": "public" diff --git a/packages/cache/src/Cache.ts b/packages/cache/src/Cache.ts index a2dc747..eb68631 100644 --- a/packages/cache/src/Cache.ts +++ b/packages/cache/src/Cache.ts @@ -1,14 +1,31 @@ -import { CodecError, Decoder } from '@imho/codec' -import { Either, Task } from '@imho/effect' -import { CacheError } from './CacheError' +import { Decoder } from '@imho/codec' +import * as fx from '@xzhayon/fx' export interface Cache { - has(key: string): Task> - get( + has(key: string): Promise + get(key: string, decoder: Decoder, onMiss: () => Promise): Promise + delete(key: string): Promise + clear(): Promise +} + +export interface FxCache extends Omit { + get>( + key: string, + decoder: Decoder, + onMiss: () => G, + ): Generator, A> +} + +export const tag = fx.tag('Cache') + +const { get } = fx.structA(tag)('get') + +export const Cache = { + tag, + get: >( key: string, decoder: Decoder, - onMiss: () => Task>, - ): Task> - delete(key: string): Task> - clear(): Task> + onMiss: () => G, + ) => get((f) => f(key, decoder, onMiss)), + ...fx.struct(tag)('has', 'delete', 'clear'), } diff --git a/packages/cache/src/CacheError.ts b/packages/cache/src/CacheError.ts index 97a737f..51f40fc 100644 --- a/packages/cache/src/CacheError.ts +++ b/packages/cache/src/CacheError.ts @@ -1,5 +1,5 @@ export const CacheErrorURI = Symbol() export class CacheError extends Error { - private readonly [CacheErrorURI]!: typeof CacheErrorURI + readonly [CacheErrorURI]!: typeof CacheErrorURI readonly name: string = 'CacheError' } diff --git a/packages/cache/tsconfig.json b/packages/cache/tsconfig.json index 6193843..c4e67ea 100644 --- a/packages/cache/tsconfig.json +++ b/packages/cache/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../codec" }, { "path": "../effect" }], + "references": [{ "path": "../codec" }], "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/clock-effect-ts/CHANGELOG.md b/packages/clock-effect-ts/CHANGELOG.md deleted file mode 100644 index 3abd5bd..0000000 --- a/packages/clock-effect-ts/CHANGELOG.md +++ /dev/null @@ -1,30 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.2](https://github.com/xzhavilla/imho/compare/@imho/clock-effect-ts@0.1.1...@imho/clock-effect-ts@0.1.2) (2023-07-28) - -**Note:** Version bump only for package @imho/clock-effect-ts - - - - - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/clock-effect-ts@0.1.0...@imho/clock-effect-ts@0.1.1) (2023-07-28) - - -### Bug Fixes - -* **clock:** expose transformers to fp-ts Clock ([#6](https://github.com/xzhavilla/imho/issues/6)) ([31c4626](https://github.com/xzhavilla/imho/commit/31c462624eb8347848874ca38b7e95fb9899b767)) - - - - - -# 0.1.0 (2023-07-25) - - -### Features - -* **clock:** add Clock module ([#4](https://github.com/xzhavilla/imho/issues/4)) ([457f033](https://github.com/xzhavilla/imho/commit/457f033437002ed1f92852d97eece3f66d648170)) diff --git a/packages/clock-effect-ts/README.md b/packages/clock-effect-ts/README.md deleted file mode 100644 index aee62bc..0000000 --- a/packages/clock-effect-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/clock-effect-ts - -[![npm](https://img.shields.io/npm/v/@imho/clock-effect-ts)](https://www.npmjs.com/package/@imho/clock-effect-ts) diff --git a/packages/clock-effect-ts/package.json b/packages/clock-effect-ts/package.json deleted file mode 100644 index b4fd289..0000000 --- a/packages/clock-effect-ts/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "@imho/clock-effect-ts", - "version": "0.1.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/clock": "^0.1.0", - "@imho/clock-fp-ts": "^0.1.0", - "@imho/effect-effect-ts": "^0.4.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/clock-effect-ts/src/Clock.ts b/packages/clock-effect-ts/src/Clock.ts deleted file mode 100644 index 16ad5f1..0000000 --- a/packages/clock-effect-ts/src/Clock.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Effect, Has } from '@effect-ts/core' -import * as _ from '@imho/clock' -import { EffectTs } from '@imho/effect-effect-ts' - -export interface Clock extends EffectTs<_.Clock> {} - -export const HasClock = Has.tag() - -export const Clock = { - now: () => - Effect.accessServiceM(HasClock)((clock) => Effect.fromIO(clock.now())), -} diff --git a/packages/clock-effect-ts/src/DateClock.test.ts b/packages/clock-effect-ts/src/DateClock.test.ts deleted file mode 100644 index 06f6f79..0000000 --- a/packages/clock-effect-ts/src/DateClock.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import { Clock, HasClock } from './Clock' -import { DateClock } from './DateClock' - -describe('DateClock', () => { - describe('now', () => { - test('returning current timestamp', async () => { - await expect( - pipe( - Clock.now(), - Effect.provideService(HasClock)(new DateClock()), - Effect.runPromise, - ), - ).resolves.toBeCloseTo(Date.now(), -1) - }) - }) -}) diff --git a/packages/clock-effect-ts/src/DateClock.ts b/packages/clock-effect-ts/src/DateClock.ts deleted file mode 100644 index 145afe8..0000000 --- a/packages/clock-effect-ts/src/DateClock.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as fpTs from '@imho/clock-fp-ts' -import { FpTsToEffectTsClock } from './FpTsToEffectTsClock' - -export class DateClock extends FpTsToEffectTsClock { - constructor() { - super(new fpTs.DateClock()) - } -} diff --git a/packages/clock-effect-ts/src/EffectTsToFpTsClock.ts b/packages/clock-effect-ts/src/EffectTsToFpTsClock.ts deleted file mode 100644 index 7429dcb..0000000 --- a/packages/clock-effect-ts/src/EffectTsToFpTsClock.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IO } from '@effect-ts/core' -import * as fpTs from '@imho/clock-fp-ts' -import { Clock } from './Clock' - -export class EffectTsToFpTsClock implements fpTs.Clock { - constructor(private readonly clock: Clock) {} - - now() { - return () => IO.run(this.clock.now()) - } -} diff --git a/packages/clock-effect-ts/src/FpTsToEffectTsClock.ts b/packages/clock-effect-ts/src/FpTsToEffectTsClock.ts deleted file mode 100644 index fb482e0..0000000 --- a/packages/clock-effect-ts/src/FpTsToEffectTsClock.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IO } from '@effect-ts/core' -import * as fpTs from '@imho/clock-fp-ts' -import { Clock } from './Clock' - -export class FpTsToEffectTsClock implements Clock { - constructor(private readonly clock: fpTs.Clock) {} - - now() { - return IO.succeedWith(this.clock.now()) - } -} diff --git a/packages/clock-effect-ts/src/PerformanceClock.test.ts b/packages/clock-effect-ts/src/PerformanceClock.test.ts deleted file mode 100644 index 7858cb5..0000000 --- a/packages/clock-effect-ts/src/PerformanceClock.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import { Clock, HasClock } from './Clock' -import { PerformanceClock } from './PerformanceClock' - -describe('PerformanceClock', () => { - describe('now', () => { - test('returning current timestamp', async () => { - await expect( - pipe( - Clock.now(), - Effect.provideService(HasClock)(new PerformanceClock()), - Effect.runPromise, - ), - ).resolves.toBeCloseTo(performance.timeOrigin + performance.now(), -1) - }) - }) -}) diff --git a/packages/clock-effect-ts/src/PerformanceClock.ts b/packages/clock-effect-ts/src/PerformanceClock.ts deleted file mode 100644 index 3fdf4f0..0000000 --- a/packages/clock-effect-ts/src/PerformanceClock.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as fpTs from '@imho/clock-fp-ts' -import { FpTsToEffectTsClock } from './FpTsToEffectTsClock' - -export class PerformanceClock extends FpTsToEffectTsClock { - constructor() { - super(new fpTs.PerformanceClock()) - } -} diff --git a/packages/clock-effect-ts/src/index.ts b/packages/clock-effect-ts/src/index.ts deleted file mode 100644 index b97bcab..0000000 --- a/packages/clock-effect-ts/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './Clock' -export * from './DateClock' -export * from './EffectTsToFpTsClock' -export * from './FpTsToEffectTsClock' -export * from './PerformanceClock' diff --git a/packages/clock-effect-ts/tsconfig.json b/packages/clock-effect-ts/tsconfig.json deleted file mode 100644 index 5f6486c..0000000 --- a/packages/clock-effect-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../clock" }, - { "path": "../clock-fp-ts" }, - { "path": "../effect-effect-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/clock-fp-ts/CHANGELOG.md b/packages/clock-fp-ts/CHANGELOG.md deleted file mode 100644 index 4b6d750..0000000 --- a/packages/clock-fp-ts/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/clock-fp-ts@0.1.0...@imho/clock-fp-ts@0.1.1) (2023-07-28) - -**Note:** Version bump only for package @imho/clock-fp-ts - - - - - -# 0.1.0 (2023-07-25) - - -### Features - -* **clock:** add Clock module ([#4](https://github.com/xzhavilla/imho/issues/4)) ([457f033](https://github.com/xzhavilla/imho/commit/457f033437002ed1f92852d97eece3f66d648170)) diff --git a/packages/clock-fp-ts/README.md b/packages/clock-fp-ts/README.md deleted file mode 100644 index 0e1b4bb..0000000 --- a/packages/clock-fp-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/clock-fp-ts - -[![npm](https://img.shields.io/npm/v/@imho/clock-fp-ts)](https://www.npmjs.com/package/@imho/clock-fp-ts) diff --git a/packages/clock-fp-ts/package.json b/packages/clock-fp-ts/package.json deleted file mode 100644 index ce3b204..0000000 --- a/packages/clock-fp-ts/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@imho/clock-fp-ts", - "version": "0.1.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/clock": "^0.1.0", - "@imho/effect-fp-ts": "^0.3.2", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/clock-fp-ts/src/Clock.ts b/packages/clock-fp-ts/src/Clock.ts deleted file mode 100644 index 855a463..0000000 --- a/packages/clock-fp-ts/src/Clock.ts +++ /dev/null @@ -1,14 +0,0 @@ -import * as _ from '@imho/clock' -import { FpTs } from '@imho/effect-fp-ts' -import { readerIO } from 'fp-ts' -import { pipe } from 'fp-ts/function' - -export interface Clock extends FpTs<_.Clock> {} - -export const Clock = { - now: () => - pipe( - readerIO.ask(), - readerIO.chainIOK((clock) => clock.now()), - ), -} diff --git a/packages/clock-fp-ts/src/DateClock.test.ts b/packages/clock-fp-ts/src/DateClock.test.ts deleted file mode 100644 index 63e804a..0000000 --- a/packages/clock-fp-ts/src/DateClock.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { pipe } from 'fp-ts/function' -import { Clock } from './Clock' -import { DateClock } from './DateClock' - -describe('DateClock', () => { - describe('now', () => { - test('returning current timestamp', () => { - expect(pipe(Clock.now()(new DateClock())())).toBeCloseTo(Date.now(), -1) - }) - }) -}) diff --git a/packages/clock-fp-ts/src/DateClock.ts b/packages/clock-fp-ts/src/DateClock.ts deleted file mode 100644 index a220867..0000000 --- a/packages/clock-fp-ts/src/DateClock.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Clock } from './Clock' - -export class DateClock implements Clock { - now() { - return () => Date.now() - } -} diff --git a/packages/clock-fp-ts/src/PerformanceClock.test.ts b/packages/clock-fp-ts/src/PerformanceClock.test.ts deleted file mode 100644 index 20aac2e..0000000 --- a/packages/clock-fp-ts/src/PerformanceClock.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { pipe } from 'fp-ts/function' -import { Clock } from './Clock' -import { PerformanceClock } from './PerformanceClock' - -describe('PerformanceClock', () => { - describe('now', () => { - test('returning current timestamp', () => { - expect(pipe(Clock.now()(new PerformanceClock())())).toBeCloseTo( - performance.timeOrigin + performance.now(), - -1, - ) - }) - }) -}) diff --git a/packages/clock-fp-ts/src/PerformanceClock.ts b/packages/clock-fp-ts/src/PerformanceClock.ts deleted file mode 100644 index 15ab3fa..0000000 --- a/packages/clock-fp-ts/src/PerformanceClock.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Clock } from './Clock' - -export class PerformanceClock implements Clock { - now() { - return () => performance.timeOrigin + performance.now() - } -} diff --git a/packages/clock-fp-ts/src/index.ts b/packages/clock-fp-ts/src/index.ts deleted file mode 100644 index 02823cf..0000000 --- a/packages/clock-fp-ts/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Clock' -export * from './DateClock' -export * from './PerformanceClock' diff --git a/packages/clock-fp-ts/tsconfig.json b/packages/clock-fp-ts/tsconfig.json deleted file mode 100644 index e05bfae..0000000 --- a/packages/clock-fp-ts/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../clock" }, { "path": "../effect-fp-ts" }], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/clock-raw/CHANGELOG.md b/packages/clock-raw/CHANGELOG.md deleted file mode 100644 index 7a990d6..0000000 --- a/packages/clock-raw/CHANGELOG.md +++ /dev/null @@ -1,30 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.2](https://github.com/xzhavilla/imho/compare/@imho/clock-raw@0.1.1...@imho/clock-raw@0.1.2) (2023-07-28) - -**Note:** Version bump only for package @imho/clock-raw - - - - - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/clock-raw@0.1.0...@imho/clock-raw@0.1.1) (2023-07-28) - - -### Bug Fixes - -* **clock:** expose transformers to fp-ts Clock ([#6](https://github.com/xzhavilla/imho/issues/6)) ([31c4626](https://github.com/xzhavilla/imho/commit/31c462624eb8347848874ca38b7e95fb9899b767)) - - - - - -# 0.1.0 (2023-07-25) - - -### Features - -* **clock:** add Clock module ([#4](https://github.com/xzhavilla/imho/issues/4)) ([457f033](https://github.com/xzhavilla/imho/commit/457f033437002ed1f92852d97eece3f66d648170)) diff --git a/packages/clock-raw/README.md b/packages/clock-raw/README.md deleted file mode 100644 index 36d235e..0000000 --- a/packages/clock-raw/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/clock-raw - -[![npm](https://img.shields.io/npm/v/@imho/clock-raw)](https://www.npmjs.com/package/@imho/clock-raw) diff --git a/packages/clock-raw/package.json b/packages/clock-raw/package.json deleted file mode 100644 index c45ca98..0000000 --- a/packages/clock-raw/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@imho/clock-raw", - "version": "0.1.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/clock": "^0.1.0", - "@imho/clock-fp-ts": "^0.1.0", - "@imho/effect-raw": "^0.3.2" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/clock-raw/src/Clock.ts b/packages/clock-raw/src/Clock.ts deleted file mode 100644 index 2f64949..0000000 --- a/packages/clock-raw/src/Clock.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as _ from '@imho/clock' -import { Raw } from '@imho/effect-raw' - -export interface Clock extends Raw<_.Clock> {} diff --git a/packages/clock-raw/src/DateClock.test.ts b/packages/clock-raw/src/DateClock.test.ts deleted file mode 100644 index 2cb8f61..0000000 --- a/packages/clock-raw/src/DateClock.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { DateClock } from './DateClock' - -describe('DateClock', () => { - describe('now', () => { - test('returning current timestamp', () => { - expect(new DateClock().now()).toBeCloseTo(Date.now(), -1) - }) - }) -}) diff --git a/packages/clock-raw/src/DateClock.ts b/packages/clock-raw/src/DateClock.ts deleted file mode 100644 index 1e27070..0000000 --- a/packages/clock-raw/src/DateClock.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as fpTs from '@imho/clock-fp-ts' -import { FpTsToRawClock } from './FpTsToRawClock' - -export class DateClock extends FpTsToRawClock { - constructor() { - super(new fpTs.DateClock()) - } -} diff --git a/packages/clock-raw/src/FpTsToRawClock.ts b/packages/clock-raw/src/FpTsToRawClock.ts deleted file mode 100644 index a2d9ad3..0000000 --- a/packages/clock-raw/src/FpTsToRawClock.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as fpTs from '@imho/clock-fp-ts' -import { Clock } from './Clock' - -export class FpTsToRawClock implements Clock { - constructor(private readonly clock: fpTs.Clock) {} - - now() { - return this.clock.now()() - } -} diff --git a/packages/clock-raw/src/PerformanceClock.test.ts b/packages/clock-raw/src/PerformanceClock.test.ts deleted file mode 100644 index b1fe40e..0000000 --- a/packages/clock-raw/src/PerformanceClock.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PerformanceClock } from './PerformanceClock' - -describe('PerformanceClock', () => { - describe('now', () => { - test('returning current timestamp', () => { - expect(new PerformanceClock().now()).toBeCloseTo( - performance.timeOrigin + performance.now(), - -1, - ) - }) - }) -}) diff --git a/packages/clock-raw/src/PerformanceClock.ts b/packages/clock-raw/src/PerformanceClock.ts deleted file mode 100644 index 9a1763d..0000000 --- a/packages/clock-raw/src/PerformanceClock.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as fpTs from '@imho/clock-fp-ts' -import { FpTsToRawClock } from './FpTsToRawClock' - -export class PerformanceClock extends FpTsToRawClock { - constructor() { - super(new fpTs.PerformanceClock()) - } -} diff --git a/packages/clock-raw/src/RawToFpTsClock.ts b/packages/clock-raw/src/RawToFpTsClock.ts deleted file mode 100644 index b6c277b..0000000 --- a/packages/clock-raw/src/RawToFpTsClock.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as fpTs from '@imho/clock-fp-ts' -import { Clock } from './Clock' - -export class RawToFpTsClock implements fpTs.Clock { - constructor(private readonly clock: Clock) {} - - now() { - return () => this.clock.now() - } -} diff --git a/packages/clock-raw/src/index.ts b/packages/clock-raw/src/index.ts deleted file mode 100644 index 8d4a304..0000000 --- a/packages/clock-raw/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './Clock' -export * from './DateClock' -export * from './FpTsToRawClock' -export * from './PerformanceClock' -export * from './RawToFpTsClock' diff --git a/packages/clock-raw/tsconfig.json b/packages/clock-raw/tsconfig.json deleted file mode 100644 index bf6d80a..0000000 --- a/packages/clock-raw/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../clock" }, - { "path": "../clock-fp-ts" }, - { "path": "../effect-raw" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/clock/package.json b/packages/clock/package.json index f6c4038..96ee0bd 100644 --- a/packages/clock/package.json +++ b/packages/clock/package.json @@ -7,10 +7,9 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,7 +17,7 @@ "prepack": "npm run build" }, "peerDependencies": { - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.2.1 || ^0.3.0 || ^0.4.0" }, "publishConfig": { "access": "public" diff --git a/packages/clock/src/Clock.ts b/packages/clock/src/Clock.ts index 54f06fc..7b06354 100644 --- a/packages/clock/src/Clock.ts +++ b/packages/clock/src/Clock.ts @@ -1,5 +1,10 @@ -import { IO } from '@imho/effect' +import * as fx from '@xzhayon/fx' export interface Clock { - now(): IO + readonly [fx.URI]?: unique symbol + now(): Date } + +export const tag = fx.tag('Clock') + +export const Clock = { tag, ...fx.struct(tag)('now') } diff --git a/packages/clock/src/date/DateClock.ts b/packages/clock/src/date/DateClock.ts new file mode 100644 index 0000000..a075ded --- /dev/null +++ b/packages/clock/src/date/DateClock.ts @@ -0,0 +1,7 @@ +import { Clock } from '../Clock' + +export class DateClock implements Clock { + now() { + return new Date() + } +} diff --git a/packages/clock/src/date/FxDateClock.test.ts b/packages/clock/src/date/FxDateClock.test.ts new file mode 100644 index 0000000..1e64508 --- /dev/null +++ b/packages/clock/src/date/FxDateClock.test.ts @@ -0,0 +1,17 @@ +import { layer, perform, run } from '@xzhayon/fx' +import { Clock } from '../Clock' +import { FxDateClock } from './FxDateClock' + +describe('FxDateClock', () => { + describe('now', () => { + test('returning current timestamp', async () => { + function* f() { + return (yield* perform(Clock.now())).valueOf() + } + + await expect( + run(f(), layer().with(Clock, FxDateClock())), + ).resolves.toBeCloseTo(Date.now(), -1) + }) + }) +}) diff --git a/packages/clock/src/date/FxDateClock.ts b/packages/clock/src/date/FxDateClock.ts new file mode 100644 index 0000000..18fcb7a --- /dev/null +++ b/packages/clock/src/date/FxDateClock.ts @@ -0,0 +1,7 @@ +import { Handler } from '@xzhayon/fx' +import { Clock } from '../Clock' +import { DateClock } from './DateClock' + +export function FxDateClock() { + return new DateClock() satisfies Handler +} diff --git a/packages/clock/src/index.ts b/packages/clock/src/index.ts index 9b8b971..52a97c2 100644 --- a/packages/clock/src/index.ts +++ b/packages/clock/src/index.ts @@ -1 +1,5 @@ export * from './Clock' +export * from './date/DateClock' +export * from './date/FxDateClock' +export * from './performance/FxPerformanceClock' +export * from './performance/PerformanceClock' diff --git a/packages/clock/src/performance/FxPerformanceClock.test.ts b/packages/clock/src/performance/FxPerformanceClock.test.ts new file mode 100644 index 0000000..37c1453 --- /dev/null +++ b/packages/clock/src/performance/FxPerformanceClock.test.ts @@ -0,0 +1,17 @@ +import { layer, perform, run } from '@xzhayon/fx' +import { Clock } from '../Clock' +import { FxPerformanceClock } from './FxPerformanceClock' + +describe('FxPerformanceClock', () => { + describe('now', () => { + test('returning current timestamp', async () => { + function* f() { + return (yield* perform(Clock.now())).valueOf() + } + + await expect( + run(f(), layer().with(Clock, FxPerformanceClock())), + ).resolves.toBeCloseTo(performance.timeOrigin + performance.now(), -1) + }) + }) +}) diff --git a/packages/clock/src/performance/FxPerformanceClock.ts b/packages/clock/src/performance/FxPerformanceClock.ts new file mode 100644 index 0000000..cd54049 --- /dev/null +++ b/packages/clock/src/performance/FxPerformanceClock.ts @@ -0,0 +1,7 @@ +import { Handler } from '@xzhayon/fx' +import { Clock } from '../Clock' +import { PerformanceClock } from './PerformanceClock' + +export function FxPerformanceClock() { + return new PerformanceClock() satisfies Handler +} diff --git a/packages/clock/src/performance/PerformanceClock.ts b/packages/clock/src/performance/PerformanceClock.ts new file mode 100644 index 0000000..2a8e3c4 --- /dev/null +++ b/packages/clock/src/performance/PerformanceClock.ts @@ -0,0 +1,7 @@ +import { Clock } from '../Clock' + +export class PerformanceClock implements Clock { + now() { + return new Date(performance.timeOrigin + performance.now()) + } +} diff --git a/packages/clock/tsconfig.json b/packages/clock/tsconfig.json index 41b3dc9..fe0dc1e 100644 --- a/packages/clock/tsconfig.json +++ b/packages/clock/tsconfig.json @@ -1,9 +1,4 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } + "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/codec-effect-ts-io-ts/CHANGELOG.md b/packages/codec-effect-ts-io-ts/CHANGELOG.md deleted file mode 100644 index 6f8585f..0000000 --- a/packages/codec-effect-ts-io-ts/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/codec-effect-ts-io-ts@0.3.0...@imho/codec-effect-ts-io-ts@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/codec-effect-ts-io-ts - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/codec-effect-ts-io-ts@0.2.0...@imho/codec-effect-ts-io-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **codec:** add io-ts Codec implementation ([28ab0bc](https://github.com/xzhavilla/imho/commit/28ab0bc5ea424f809d38c78317d76b0b6770eb9b)) diff --git a/packages/codec-effect-ts-io-ts/README.md b/packages/codec-effect-ts-io-ts/README.md deleted file mode 100644 index d12f675..0000000 --- a/packages/codec-effect-ts-io-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/codec-effect-ts-io-ts - -[![npm](https://img.shields.io/npm/v/@imho/codec-effect-ts-io-ts)](https://www.npmjs.com/package/@imho/codec-effect-ts-io-ts) diff --git a/packages/codec-effect-ts-io-ts/package.json b/packages/codec-effect-ts-io-ts/package.json deleted file mode 100644 index ac95aa2..0000000 --- a/packages/codec-effect-ts-io-ts/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@imho/codec-effect-ts-io-ts", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/codec-fp-ts-io-ts": "^0.3.1" - }, - "peerDependencies": { - "@imho/codec-effect-ts": "^0.2.0", - "io-ts": "^2.2.20" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/codec-effect-ts-io-ts/src/IoTsCodec.test.ts b/packages/codec-effect-ts-io-ts/src/IoTsCodec.test.ts deleted file mode 100644 index a05643d..0000000 --- a/packages/codec-effect-ts-io-ts/src/IoTsCodec.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { CodecError } from '@imho/codec' -import * as t from 'io-ts' -import { IoTsCodec } from './IoTsCodec' - -describe('IoTsCodec', () => { - describe('name', () => { - test.each([ - { type: t.boolean }, - { type: t.array(t.boolean) }, - { type: t.record(t.string, t.number) }, - { type: t.tuple([t.number, t.string]) }, - { type: t.type({ number: t.number, string: t.string }) }, - { type: t.union([t.number, t.string]) }, - { - type: t.intersection([ - t.type({ boolean: t.boolean, number: t.number }), - t.type({ number: t.number, string: t.string }), - ]), - }, - ])('forwarding codec name ($type.name)', ({ type }: { type: t.Any }) => { - expect(new IoTsCodec(type).name).toStrictEqual(type.name) - }) - }) - - describe('decode', () => { - test('failing with a CodecError', () => { - expect( - (new IoTsCodec(t.never).decode(undefined) as any).left, - ).toBeInstanceOf(CodecError) - }) - - test.each([ - { type: t.boolean, input: false }, - { type: t.array(t.boolean), input: [false] }, - { type: t.record(t.string, t.number), input: { '': 0 } }, - { type: t.tuple([t.number, t.string]), input: [0, ''] }, - { - type: t.type({ number: t.number, string: t.string }), - input: { number: 0, string: '' }, - }, - { type: t.union([t.number, t.string]), input: 0 }, - { - type: t.intersection([ - t.type({ boolean: t.boolean, number: t.number }), - t.type({ number: t.number, string: t.string }), - ]), - input: { boolean: false, number: 0, string: '' }, - }, - ])( - 'forwarding codec result ($type.name)', - ({ type, input }: { type: t.Any; input: unknown }) => { - expect((new IoTsCodec(type).decode(input) as any).right).toStrictEqual( - (type.decode(input) as any).right, - ) - }, - ) - }) -}) diff --git a/packages/codec-effect-ts-io-ts/src/IoTsCodec.ts b/packages/codec-effect-ts-io-ts/src/IoTsCodec.ts deleted file mode 100644 index 5167387..0000000 --- a/packages/codec-effect-ts-io-ts/src/IoTsCodec.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FpTsToEffectTsCodec } from '@imho/codec-effect-ts' -import * as fpTs from '@imho/codec-fp-ts-io-ts' -import * as t from 'io-ts' - -export class IoTsCodec extends FpTsToEffectTsCodec< - A, - O, - I -> { - constructor(type: t.Type) { - super(new fpTs.IoTsCodec(type)) - } -} diff --git a/packages/codec-effect-ts-io-ts/tsconfig.json b/packages/codec-effect-ts-io-ts/tsconfig.json deleted file mode 100644 index a4b9fd7..0000000 --- a/packages/codec-effect-ts-io-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../codec" }, - { "path": "../codec-fp-ts-io-ts" }, - { "path": "../codec-effect-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/codec-effect-ts/CHANGELOG.md b/packages/codec-effect-ts/CHANGELOG.md deleted file mode 100644 index 05d2011..0000000 --- a/packages/codec-effect-ts/CHANGELOG.md +++ /dev/null @@ -1,30 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.2.2](https://github.com/xzhavilla/imho/compare/@imho/codec-effect-ts@0.2.1...@imho/codec-effect-ts@0.2.2) (2023-07-28) - -**Note:** Version bump only for package @imho/codec-effect-ts - - - - - -## [0.2.1](https://github.com/xzhavilla/imho/compare/@imho/codec-effect-ts@0.2.0...@imho/codec-effect-ts@0.2.1) (2023-07-22) - - -### Bug Fixes - -* update peer dependencies ([4d1f988](https://github.com/xzhavilla/imho/commit/4d1f9885679e64a1eaed79021ca447952cc9b600)) - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **codec:** add Codec module ([3824c2b](https://github.com/xzhavilla/imho/commit/3824c2bc7c4ac243641aff11385872c22d611ba1)) diff --git a/packages/codec-effect-ts/README.md b/packages/codec-effect-ts/README.md deleted file mode 100644 index 8aae7de..0000000 --- a/packages/codec-effect-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/codec-effect-ts - -[![npm](https://img.shields.io/npm/v/@imho/codec-effect-ts)](https://www.npmjs.com/package/@imho/codec-effect-ts) diff --git a/packages/codec-effect-ts/package.json b/packages/codec-effect-ts/package.json deleted file mode 100644 index 26ce193..0000000 --- a/packages/codec-effect-ts/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "@imho/codec-effect-ts", - "version": "0.2.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/codec-fp-ts": "^0.2.0", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/codec-effect-ts/src/Codec.ts b/packages/codec-effect-ts/src/Codec.ts deleted file mode 100644 index 0ff1202..0000000 --- a/packages/codec-effect-ts/src/Codec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Either } from '@effect-ts/core/Either' -import * as _ from '@imho/codec' -import { CodecError } from '@imho/codec' - -export interface Decoder - extends Omit<_.Decoder, 'decode'> { - decode(i: I): Either -} - -export interface Encoder extends _.Encoder {} - -export interface Codec - extends Decoder, - Encoder, - Pick<_.Codec, 'is'> {} diff --git a/packages/codec-effect-ts/src/EffectTsToFpTsCodec.ts b/packages/codec-effect-ts/src/EffectTsToFpTsCodec.ts deleted file mode 100644 index ebecd82..0000000 --- a/packages/codec-effect-ts/src/EffectTsToFpTsCodec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Either, pipe } from '@effect-ts/core' -import * as fpTs from '@imho/codec-fp-ts' -import { either } from 'fp-ts' -import { Codec, Decoder, Encoder } from './Codec' - -export class EffectTsToFpTsDecoder - implements fpTs.Decoder -{ - constructor(private readonly decoder: Decoder) {} - - get name() { - return this.decoder.name - } - - decode(i: I) { - return pipe(this.decoder.decode(i), Either.fold(either.left, either.right)) - } -} - -export class EffectTsToFpTsEncoder implements fpTs.Encoder { - constructor(private readonly encoder: Encoder) {} - - encode(a: A) { - return this.encoder.encode(a) - } -} - -export class EffectTsToFpTsCodec - implements fpTs.Codec -{ - private readonly decoder: EffectTsToFpTsDecoder - private readonly encoder: EffectTsToFpTsEncoder - - constructor(private readonly codec: Codec) { - this.decoder = new EffectTsToFpTsDecoder(codec) - this.encoder = new EffectTsToFpTsEncoder(codec) - } - - get name() { - return this.decoder.name - } - - is(u: unknown): u is A { - return this.codec.is(u) - } - - decode(i: I) { - return this.decoder.decode(i) - } - - encode(a: A) { - return this.encoder.encode(a) - } -} diff --git a/packages/codec-effect-ts/src/FpTsToEffectTsCodec.ts b/packages/codec-effect-ts/src/FpTsToEffectTsCodec.ts deleted file mode 100644 index 7616ca0..0000000 --- a/packages/codec-effect-ts/src/FpTsToEffectTsCodec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Either } from '@effect-ts/core' -import { CodecError } from '@imho/codec' -import * as fpTs from '@imho/codec-fp-ts' -import { either } from 'fp-ts' -import { pipe } from 'fp-ts/function' -import { Codec } from './Codec' - -export class FpTsToEffectTsCodec - implements Codec -{ - constructor(private readonly codec: fpTs.Codec) {} - - get name() { - return this.codec.name - } - - is(u: unknown): u is A { - return this.codec.is(u) - } - - decode(i: I) { - return pipe( - this.codec.decode(i), - either.match(Either.left, (a) => Either.rightW(a)), - ) - } - - encode(a: A) { - return this.codec.encode(a) - } -} diff --git a/packages/codec-effect-ts/src/index.ts b/packages/codec-effect-ts/src/index.ts deleted file mode 100644 index a797e7e..0000000 --- a/packages/codec-effect-ts/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Codec' -export * from './EffectTsToFpTsCodec' -export * from './FpTsToEffectTsCodec' diff --git a/packages/codec-effect-ts/tsconfig.json b/packages/codec-effect-ts/tsconfig.json deleted file mode 100644 index 0710c6b..0000000 --- a/packages/codec-effect-ts/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../codec" }, { "path": "../codec-fp-ts" }], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/codec-fp-ts-io-ts/README.md b/packages/codec-fp-ts-io-ts/README.md deleted file mode 100644 index 49e4ef0..0000000 --- a/packages/codec-fp-ts-io-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/codec-fp-ts-io-ts - -[![npm](https://img.shields.io/npm/v/@imho/codec-fp-ts-io-ts)](https://www.npmjs.com/package/@imho/codec-fp-ts-io-ts) diff --git a/packages/codec-fp-ts-io-ts/package.json b/packages/codec-fp-ts-io-ts/package.json deleted file mode 100644 index 28b0879..0000000 --- a/packages/codec-fp-ts-io-ts/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "@imho/codec-fp-ts-io-ts", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/codec-fp-ts": "^0.2.0", - "fp-ts": "^2.16.0", - "io-ts": "^2.2.20" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/codec-fp-ts-io-ts/src/IoTsCodec.test.ts b/packages/codec-fp-ts-io-ts/src/IoTsCodec.test.ts deleted file mode 100644 index 3bff5e3..0000000 --- a/packages/codec-fp-ts-io-ts/src/IoTsCodec.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { CodecError } from '@imho/codec' -import * as t from 'io-ts' -import { IoTsCodec } from './IoTsCodec' - -describe('IoTsCodec', () => { - describe('name', () => { - test.each([ - { type: t.boolean }, - { type: t.array(t.boolean) }, - { type: t.record(t.string, t.number) }, - { type: t.tuple([t.number, t.string]) }, - { type: t.type({ number: t.number, string: t.string }) }, - { type: t.union([t.number, t.string]) }, - { - type: t.intersection([ - t.type({ boolean: t.boolean, number: t.number }), - t.type({ number: t.number, string: t.string }), - ]), - }, - ])('forwarding codec name ($type.name)', ({ type }: { type: t.Any }) => { - expect(new IoTsCodec(type).name).toStrictEqual(type.name) - }) - }) - - describe('decode', () => { - test('failing with a CodecError', () => { - expect( - (new IoTsCodec(t.never).decode(undefined) as any).left, - ).toBeInstanceOf(CodecError) - }) - - test.each([ - { type: t.boolean, input: false }, - { type: t.array(t.boolean), input: [false] }, - { type: t.record(t.string, t.number), input: { '': 0 } }, - { type: t.tuple([t.number, t.string]), input: [0, ''] }, - { - type: t.type({ number: t.number, string: t.string }), - input: { number: 0, string: '' }, - }, - { type: t.union([t.number, t.string]), input: 0 }, - { - type: t.intersection([ - t.type({ boolean: t.boolean, number: t.number }), - t.type({ number: t.number, string: t.string }), - ]), - input: { boolean: false, number: 0, string: '' }, - }, - ])( - 'forwarding codec result ($type.name)', - ({ type, input }: { type: t.Any; input: unknown }) => { - expect(new IoTsCodec(type).decode(input)).toStrictEqual( - type.decode(input), - ) - }, - ) - }) -}) diff --git a/packages/codec-fp-ts-io-ts/src/index.ts b/packages/codec-fp-ts-io-ts/src/index.ts deleted file mode 100644 index f384560..0000000 --- a/packages/codec-fp-ts-io-ts/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './IoTsCodec' diff --git a/packages/codec-fp-ts-io-ts/tsconfig.json b/packages/codec-fp-ts-io-ts/tsconfig.json deleted file mode 100644 index 0710c6b..0000000 --- a/packages/codec-fp-ts-io-ts/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../codec" }, { "path": "../codec-fp-ts" }], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/codec-fp-ts/CHANGELOG.md b/packages/codec-fp-ts/CHANGELOG.md deleted file mode 100644 index 740f99d..0000000 --- a/packages/codec-fp-ts/CHANGELOG.md +++ /dev/null @@ -1,30 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.2.2](https://github.com/xzhavilla/imho/compare/@imho/codec-fp-ts@0.2.1...@imho/codec-fp-ts@0.2.2) (2023-07-28) - -**Note:** Version bump only for package @imho/codec-fp-ts - - - - - -## [0.2.1](https://github.com/xzhavilla/imho/compare/@imho/codec-fp-ts@0.2.0...@imho/codec-fp-ts@0.2.1) (2023-07-22) - - -### Bug Fixes - -* update peer dependencies ([4d1f988](https://github.com/xzhavilla/imho/commit/4d1f9885679e64a1eaed79021ca447952cc9b600)) - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **codec:** add Codec module ([3824c2b](https://github.com/xzhavilla/imho/commit/3824c2bc7c4ac243641aff11385872c22d611ba1)) diff --git a/packages/codec-fp-ts/README.md b/packages/codec-fp-ts/README.md deleted file mode 100644 index 6ca80ad..0000000 --- a/packages/codec-fp-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/codec-fp-ts - -[![npm](https://img.shields.io/npm/v/@imho/codec-fp-ts)](https://www.npmjs.com/package/@imho/codec-fp-ts) diff --git a/packages/codec-fp-ts/package.json b/packages/codec-fp-ts/package.json deleted file mode 100644 index d750ecf..0000000 --- a/packages/codec-fp-ts/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@imho/codec-fp-ts", - "version": "0.2.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/codec": "^0.2.0 || ^0.3.0", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/codec-fp-ts/src/Codec.ts b/packages/codec-fp-ts/src/Codec.ts deleted file mode 100644 index 66b2897..0000000 --- a/packages/codec-fp-ts/src/Codec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as _ from '@imho/codec' -import { CodecError } from '@imho/codec' -import { Either } from 'fp-ts/Either' - -export interface Decoder - extends Omit<_.Decoder, 'decode'> { - decode(i: I): Either -} - -export interface Encoder extends _.Encoder {} - -export interface Codec - extends Decoder, - Encoder, - Pick<_.Codec, 'is'> {} diff --git a/packages/codec-fp-ts/src/index.ts b/packages/codec-fp-ts/src/index.ts deleted file mode 100644 index 27f37c7..0000000 --- a/packages/codec-fp-ts/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Codec' diff --git a/packages/codec-fp-ts/tsconfig.json b/packages/codec-fp-ts/tsconfig.json deleted file mode 100644 index 3f40bfd..0000000 --- a/packages/codec-fp-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../codec" }], - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } -} diff --git a/packages/codec-fp-ts-io-ts/CHANGELOG.md b/packages/codec-io-ts/CHANGELOG.md similarity index 100% rename from packages/codec-fp-ts-io-ts/CHANGELOG.md rename to packages/codec-io-ts/CHANGELOG.md diff --git a/packages/codec-io-ts/README.md b/packages/codec-io-ts/README.md new file mode 100644 index 0000000..9ec6d81 --- /dev/null +++ b/packages/codec-io-ts/README.md @@ -0,0 +1,3 @@ +# @imho/codec-io-ts + +[![npm](https://img.shields.io/npm/v/@imho/codec-io-ts)](https://www.npmjs.com/package/@imho/codec-io-ts) diff --git a/packages/log-fp-ts-pino/package.json b/packages/codec-io-ts/package.json similarity index 74% rename from packages/log-fp-ts-pino/package.json rename to packages/codec-io-ts/package.json index 81bb440..bcdb938 100644 --- a/packages/log-fp-ts-pino/package.json +++ b/packages/codec-io-ts/package.json @@ -1,5 +1,5 @@ { - "name": "@imho/log-fp-ts-pino", + "name": "@imho/codec-io-ts", "version": "0.3.1", "description": "", "license": "MIT", @@ -7,10 +7,9 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,9 +17,9 @@ "prepack": "npm run build" }, "peerDependencies": { - "@imho/log-fp-ts": "^0.2.0 || ^0.3.0", + "@imho/codec": "*", "fp-ts": "^2.16.0", - "pino": "^8.14.1" + "io-ts": "^2.2.20" }, "publishConfig": { "access": "public" diff --git a/packages/codec-raw-io-ts/src/IoTsCodec.test.ts b/packages/codec-io-ts/src/IoTsCodec.test.ts similarity index 92% rename from packages/codec-raw-io-ts/src/IoTsCodec.test.ts rename to packages/codec-io-ts/src/IoTsCodec.test.ts index a77b50e..d419b6e 100644 --- a/packages/codec-raw-io-ts/src/IoTsCodec.test.ts +++ b/packages/codec-io-ts/src/IoTsCodec.test.ts @@ -24,9 +24,7 @@ describe('IoTsCodec', () => { describe('decode', () => { test('failing with a CodecError', () => { - expect(() => { - new IoTsCodec(t.never).decode(undefined) - }).toThrow(CodecError) + expect(() => new IoTsCodec(t.never).decode(undefined)).toThrow(CodecError) }) test.each([ @@ -47,7 +45,7 @@ describe('IoTsCodec', () => { input: { boolean: false, number: 0, string: '' }, }, ])( - 'forwarding codec result ($type.name)', + 'forwarding decoder result ($type.name)', ({ type, input }: { type: t.Any; input: unknown }) => { expect(new IoTsCodec(type).decode(input)).toStrictEqual( (type.decode(input) as any).right, diff --git a/packages/codec-fp-ts-io-ts/src/IoTsCodec.ts b/packages/codec-io-ts/src/IoTsCodec.ts similarity index 51% rename from packages/codec-fp-ts-io-ts/src/IoTsCodec.ts rename to packages/codec-io-ts/src/IoTsCodec.ts index 6433bfe..06bdb2d 100644 --- a/packages/codec-fp-ts-io-ts/src/IoTsCodec.ts +++ b/packages/codec-io-ts/src/IoTsCodec.ts @@ -1,7 +1,5 @@ -import { CodecError } from '@imho/codec' -import { Codec } from '@imho/codec-fp-ts' +import { Codec, CodecError } from '@imho/codec' import { either } from 'fp-ts' -import { pipe } from 'fp-ts/function' import * as t from 'io-ts' import { failure } from 'io-ts/PathReporter' @@ -17,16 +15,16 @@ export class IoTsCodec implements Codec { } decode(i: I) { - return pipe( - this.type.decode(i), - either.mapLeft( - (errors) => - new CodecError( - errors.map((error) => new Error(failure([error])[0])), - `Cannot decode input with codec "${this.name}"`, - ), - ), - ) + const a = this.type.decode(i) + if (either.isLeft(a)) { + throw new CodecError( + a.left.map((error) => new Error(failure([error])[0])), + `Cannot decode input with codec "${this.name}"`, + { cause: a.left }, + ) + } + + return a.right } encode(a: A) { diff --git a/packages/codec-effect-ts-io-ts/src/index.ts b/packages/codec-io-ts/src/index.ts similarity index 100% rename from packages/codec-effect-ts-io-ts/src/index.ts rename to packages/codec-io-ts/src/index.ts diff --git a/packages/log-fp-ts-pino/tsconfig.json b/packages/codec-io-ts/tsconfig.json similarity index 69% rename from packages/log-fp-ts-pino/tsconfig.json rename to packages/codec-io-ts/tsconfig.json index 8a69926..c4e67ea 100644 --- a/packages/log-fp-ts-pino/tsconfig.json +++ b/packages/codec-io-ts/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../log-fp-ts" }], + "references": [{ "path": "../codec" }], "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/codec-raw-io-ts/CHANGELOG.md b/packages/codec-raw-io-ts/CHANGELOG.md deleted file mode 100644 index 4e97a8f..0000000 --- a/packages/codec-raw-io-ts/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/codec-raw-io-ts@0.3.0...@imho/codec-raw-io-ts@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/codec-raw-io-ts - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/codec-raw-io-ts@0.2.0...@imho/codec-raw-io-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **codec:** add io-ts Codec implementation ([28ab0bc](https://github.com/xzhavilla/imho/commit/28ab0bc5ea424f809d38c78317d76b0b6770eb9b)) diff --git a/packages/codec-raw-io-ts/README.md b/packages/codec-raw-io-ts/README.md deleted file mode 100644 index 6073b88..0000000 --- a/packages/codec-raw-io-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/codec-raw-io-ts - -[![npm](https://img.shields.io/npm/v/@imho/codec-raw-io-ts)](https://www.npmjs.com/package/@imho/codec-raw-io-ts) diff --git a/packages/codec-raw-io-ts/package.json b/packages/codec-raw-io-ts/package.json deleted file mode 100644 index b35f97e..0000000 --- a/packages/codec-raw-io-ts/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@imho/codec-raw-io-ts", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/codec-fp-ts-io-ts": "^0.3.1" - }, - "peerDependencies": { - "@imho/codec-raw": "^0.2.0", - "io-ts": "^2.2.20" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/codec-raw-io-ts/src/IoTsCodec.ts b/packages/codec-raw-io-ts/src/IoTsCodec.ts deleted file mode 100644 index 76e28cd..0000000 --- a/packages/codec-raw-io-ts/src/IoTsCodec.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as fpTs from '@imho/codec-fp-ts-io-ts' -import { FpTsToRawCodec } from '@imho/codec-raw' -import * as t from 'io-ts' - -export class IoTsCodec extends FpTsToRawCodec { - constructor(type: t.Type) { - super(new fpTs.IoTsCodec(type)) - } -} diff --git a/packages/codec-raw-io-ts/src/index.ts b/packages/codec-raw-io-ts/src/index.ts deleted file mode 100644 index f384560..0000000 --- a/packages/codec-raw-io-ts/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './IoTsCodec' diff --git a/packages/codec-raw-io-ts/tsconfig.json b/packages/codec-raw-io-ts/tsconfig.json deleted file mode 100644 index 8ceceed..0000000 --- a/packages/codec-raw-io-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../codec" }, - { "path": "../codec-fp-ts-io-ts" }, - { "path": "../codec-raw" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/codec-raw/CHANGELOG.md b/packages/codec-raw/CHANGELOG.md deleted file mode 100644 index 8bbbb9d..0000000 --- a/packages/codec-raw/CHANGELOG.md +++ /dev/null @@ -1,30 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.2.2](https://github.com/xzhavilla/imho/compare/@imho/codec-raw@0.2.1...@imho/codec-raw@0.2.2) (2023-07-28) - -**Note:** Version bump only for package @imho/codec-raw - - - - - -## [0.2.1](https://github.com/xzhavilla/imho/compare/@imho/codec-raw@0.2.0...@imho/codec-raw@0.2.1) (2023-07-22) - - -### Bug Fixes - -* update peer dependencies ([4d1f988](https://github.com/xzhavilla/imho/commit/4d1f9885679e64a1eaed79021ca447952cc9b600)) - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **codec:** add Codec module ([3824c2b](https://github.com/xzhavilla/imho/commit/3824c2bc7c4ac243641aff11385872c22d611ba1)) diff --git a/packages/codec-raw/README.md b/packages/codec-raw/README.md deleted file mode 100644 index aaccdb7..0000000 --- a/packages/codec-raw/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/codec-raw - -[![npm](https://img.shields.io/npm/v/@imho/codec-raw)](https://www.npmjs.com/package/@imho/codec-raw) diff --git a/packages/codec-raw/package.json b/packages/codec-raw/package.json deleted file mode 100644 index 2b83262..0000000 --- a/packages/codec-raw/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@imho/codec-raw", - "version": "0.2.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/codec": "^0.2.0 || ^0.3.0", - "@imho/codec-fp-ts": "^0.2.0", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/codec-raw/src/Codec.ts b/packages/codec-raw/src/Codec.ts deleted file mode 100644 index 19188f3..0000000 --- a/packages/codec-raw/src/Codec.ts +++ /dev/null @@ -1,13 +0,0 @@ -import * as _ from '@imho/codec' - -export interface Decoder - extends Omit<_.Decoder, 'decode'> { - decode(i: I): A | never -} - -export interface Encoder extends _.Encoder {} - -export interface Codec - extends Decoder, - Encoder, - Pick<_.Codec, 'is'> {} diff --git a/packages/codec-raw/src/FpTsToRawCodec.ts b/packages/codec-raw/src/FpTsToRawCodec.ts deleted file mode 100644 index 2fff20f..0000000 --- a/packages/codec-raw/src/FpTsToRawCodec.ts +++ /dev/null @@ -1,28 +0,0 @@ -import * as fpTs from '@imho/codec-fp-ts' -import { either } from 'fp-ts' -import { Codec } from './Codec' - -export class FpTsToRawCodec implements Codec { - constructor(private readonly codec: fpTs.Codec) {} - - get name() { - return this.codec.name - } - - is(u: unknown): u is A { - return this.codec.is(u) - } - - decode(i: I) { - const a = this.codec.decode(i) - if (either.isLeft(a)) { - throw a.left - } - - return a.right - } - - encode(a: A) { - return this.codec.encode(a) - } -} diff --git a/packages/codec-raw/src/RawToFpTsCodec.ts b/packages/codec-raw/src/RawToFpTsCodec.ts deleted file mode 100644 index 693e84d..0000000 --- a/packages/codec-raw/src/RawToFpTsCodec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { CodecError } from '@imho/codec' -import * as fpTs from '@imho/codec-fp-ts' -import { either } from 'fp-ts' -import { Codec, Decoder, Encoder } from './Codec' - -export class RawToFpTsDecoder implements fpTs.Decoder { - constructor(private readonly decoder: Decoder) {} - - get name() { - return this.decoder.name - } - - decode(i: I) { - return either.tryCatch( - () => this.decoder.decode(i), - (cause) => - cause instanceof CodecError - ? cause - : new CodecError( - [], - `Cannot decode input with codec "${this.name}"`, - { cause }, - ), - ) - } -} - -export class RawToFpTsEncoder implements fpTs.Encoder { - constructor(private readonly encoder: Encoder) {} - - encode(a: A) { - return this.encoder.encode(a) - } -} - -export class RawToFpTsCodec - implements fpTs.Codec -{ - private readonly decoder: RawToFpTsDecoder - private readonly encoder: RawToFpTsEncoder - - constructor(private readonly codec: Codec) { - this.decoder = new RawToFpTsDecoder(codec) - this.encoder = new RawToFpTsEncoder(codec) - } - - get name() { - return this.decoder.name - } - - is(u: unknown): u is A { - return this.codec.is(u) - } - - decode(i: I) { - return this.decoder.decode(i) - } - - encode(a: A) { - return this.encoder.encode(a) - } -} diff --git a/packages/codec-raw/src/index.ts b/packages/codec-raw/src/index.ts deleted file mode 100644 index f3cfafd..0000000 --- a/packages/codec-raw/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './Codec' -export * from './FpTsToRawCodec' -export * from './RawToFpTsCodec' diff --git a/packages/codec-raw/tsconfig.json b/packages/codec-raw/tsconfig.json deleted file mode 100644 index 0710c6b..0000000 --- a/packages/codec-raw/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../codec" }, { "path": "../codec-fp-ts" }], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/codec/package.json b/packages/codec/package.json index 542c16e..92226f4 100644 --- a/packages/codec/package.json +++ b/packages/codec/package.json @@ -7,19 +7,15 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", "clean": "rm -rf dist *.tsbuildinfo", "prepack": "npm run build" }, - "peerDependencies": { - "@imho/effect": "^0.2.0" - }, "publishConfig": { "access": "public" } diff --git a/packages/codec/src/Codec.ts b/packages/codec/src/Codec.ts index 997a4b1..3210eb8 100644 --- a/packages/codec/src/Codec.ts +++ b/packages/codec/src/Codec.ts @@ -1,14 +1,5 @@ -import { Either } from '@imho/effect' -import { CodecError } from './CodecError' - -export interface Decoder { - readonly name: string - decode(i: I): Either -} - -export interface Encoder { - encode(a: A): O -} +import { Decoder } from './Decoder' +import { Encoder } from './Encoder' export interface Codec extends Decoder, diff --git a/packages/codec/src/CodecError.ts b/packages/codec/src/CodecError.ts index 4e378e6..c51e531 100644 --- a/packages/codec/src/CodecError.ts +++ b/packages/codec/src/CodecError.ts @@ -1,5 +1,5 @@ export const CodecErrorURI = Symbol() export class CodecError extends AggregateError { - private readonly [CodecErrorURI]!: typeof CodecErrorURI + readonly [CodecErrorURI]!: typeof CodecErrorURI readonly name: string = 'CodecError' } diff --git a/packages/codec/src/Decoder.ts b/packages/codec/src/Decoder.ts new file mode 100644 index 0000000..f5a6127 --- /dev/null +++ b/packages/codec/src/Decoder.ts @@ -0,0 +1,4 @@ +export interface Decoder { + readonly name: string + decode(i: I): A +} diff --git a/packages/codec/src/Encoder.ts b/packages/codec/src/Encoder.ts new file mode 100644 index 0000000..10e0bcd --- /dev/null +++ b/packages/codec/src/Encoder.ts @@ -0,0 +1,3 @@ +export interface Encoder { + encode(a: A): O +} diff --git a/packages/codec/src/index.ts b/packages/codec/src/index.ts index 561d7c7..91bdac9 100644 --- a/packages/codec/src/index.ts +++ b/packages/codec/src/index.ts @@ -1,2 +1,4 @@ export * from './Codec' export * from './CodecError' +export * from './Decoder' +export * from './Encoder' diff --git a/packages/codec/tsconfig.json b/packages/codec/tsconfig.json index e84f0a5..fe0dc1e 100644 --- a/packages/codec/tsconfig.json +++ b/packages/codec/tsconfig.json @@ -1,5 +1,4 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/effect-effect-ts/CHANGELOG.md b/packages/effect-effect-ts/CHANGELOG.md deleted file mode 100644 index 9e61fc2..0000000 --- a/packages/effect-effect-ts/CHANGELOG.md +++ /dev/null @@ -1,75 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.4.1](https://github.com/xzhavilla/imho/compare/@imho/effect-effect-ts@0.4.0...@imho/effect-effect-ts@0.4.1) (2023-07-28) - -**Note:** Version bump only for package @imho/effect-effect-ts - - - - - -# [0.4.0](https://github.com/xzhavilla/imho/compare/@imho/effect-effect-ts@0.3.2...@imho/effect-effect-ts@0.4.0) (2023-07-24) - - -### Features - -* **effect:** make Effect-TS `IO` synchronous ([#3](https://github.com/xzhavilla/imho/issues/3)) ([a7ab33e](https://github.com/xzhavilla/imho/commit/a7ab33ee4d42f0855128b1f6198207cfd239f417)) - - -### BREAKING CHANGES - -* **effect:** `IO`-derived effects need to be wrapped to be used in `Effect` ecosystem - - - - - -## [0.3.2](https://github.com/xzhavilla/imho/compare/@imho/effect-effect-ts@0.3.1...@imho/effect-effect-ts@0.3.2) (2023-07-24) - - -### Bug Fixes - -* **effect:** avoid forcing `readonly` property ([#2](https://github.com/xzhavilla/imho/issues/2)) ([e4c96d8](https://github.com/xzhavilla/imho/commit/e4c96d8770e99ecc7d77c5da7d5b13bfe6127ea3)) - - - - - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/effect-effect-ts@0.3.0...@imho/effect-effect-ts@0.3.1) (2023-07-24) - - -### Bug Fixes - -* **effect:** avoid transforming Error types ([#1](https://github.com/xzhavilla/imho/issues/1)) ([cabefc4](https://github.com/xzhavilla/imho/commit/cabefc438eaa31dc9da47ce7d5539f2e17606764)) - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/effect-effect-ts@0.2.0...@imho/effect-effect-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **effect:** add Effect module ([e7aa396](https://github.com/xzhavilla/imho/commit/e7aa3960ca0c65467140a68fc40475f9e5e1fe70)) diff --git a/packages/effect-effect-ts/README.md b/packages/effect-effect-ts/README.md deleted file mode 100644 index 213a0ae..0000000 --- a/packages/effect-effect-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/effect-effect-ts - -[![npm](https://img.shields.io/npm/v/@imho/effect-effect-ts)](https://www.npmjs.com/package/@imho/effect-effect-ts) diff --git a/packages/effect-effect-ts/package.json b/packages/effect-effect-ts/package.json deleted file mode 100644 index f48de7e..0000000 --- a/packages/effect-effect-ts/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@imho/effect-effect-ts", - "version": "0.4.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/effect": "^0.2.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/effect-effect-ts/src/index.ts b/packages/effect-effect-ts/src/index.ts deleted file mode 100644 index 6505ed5..0000000 --- a/packages/effect-effect-ts/src/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Effect, IO } from '@effect-ts/core' -import { Either } from '@effect-ts/core/Either' -import { Option } from '@effect-ts/core/Option' -import * as _ from '@imho/effect' - -export type EffectTs = A extends _.Option - ? Option> - : A extends _.Either - ? Either, EffectTs> - : A extends _.IO - ? IO.IO> - : A extends _.Task - ? B extends _.Either - ? Effect.IO, EffectTs> - : Effect.UIO> - : A extends Error - ? A - : A extends (...args: any) => any - ? (...args: EffectTs>) => EffectTs> - : A extends { [K: string]: any } - ? { [K in keyof A]: EffectTs } - : A diff --git a/packages/effect-effect-ts/tsconfig.json b/packages/effect-effect-ts/tsconfig.json deleted file mode 100644 index 41b3dc9..0000000 --- a/packages/effect-effect-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } -} diff --git a/packages/effect-fp-ts/CHANGELOG.md b/packages/effect-fp-ts/CHANGELOG.md deleted file mode 100644 index 328af03..0000000 --- a/packages/effect-fp-ts/CHANGELOG.md +++ /dev/null @@ -1,59 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.3](https://github.com/xzhavilla/imho/compare/@imho/effect-fp-ts@0.3.2...@imho/effect-fp-ts@0.3.3) (2023-07-28) - -**Note:** Version bump only for package @imho/effect-fp-ts - - - - - -## [0.3.2](https://github.com/xzhavilla/imho/compare/@imho/effect-fp-ts@0.3.1...@imho/effect-fp-ts@0.3.2) (2023-07-24) - - -### Bug Fixes - -* **effect:** avoid forcing `readonly` property ([#2](https://github.com/xzhavilla/imho/issues/2)) ([e4c96d8](https://github.com/xzhavilla/imho/commit/e4c96d8770e99ecc7d77c5da7d5b13bfe6127ea3)) - - - - - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/effect-fp-ts@0.3.0...@imho/effect-fp-ts@0.3.1) (2023-07-24) - - -### Bug Fixes - -* **effect:** avoid transforming Error types ([#1](https://github.com/xzhavilla/imho/issues/1)) ([cabefc4](https://github.com/xzhavilla/imho/commit/cabefc438eaa31dc9da47ce7d5539f2e17606764)) - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/effect-fp-ts@0.2.0...@imho/effect-fp-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **effect:** add Effect module ([e7aa396](https://github.com/xzhavilla/imho/commit/e7aa3960ca0c65467140a68fc40475f9e5e1fe70)) diff --git a/packages/effect-fp-ts/README.md b/packages/effect-fp-ts/README.md deleted file mode 100644 index 91a2232..0000000 --- a/packages/effect-fp-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/effect-fp-ts - -[![npm](https://img.shields.io/npm/v/@imho/effect-fp-ts)](https://www.npmjs.com/package/@imho/effect-fp-ts) diff --git a/packages/effect-fp-ts/package.json b/packages/effect-fp-ts/package.json deleted file mode 100644 index 442551a..0000000 --- a/packages/effect-fp-ts/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@imho/effect-fp-ts", - "version": "0.3.3", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/effect": "^0.2.0", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/effect-fp-ts/src/index.ts b/packages/effect-fp-ts/src/index.ts deleted file mode 100644 index 9d6124f..0000000 --- a/packages/effect-fp-ts/src/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as _ from '@imho/effect' -import { Either } from 'fp-ts/Either' -import { IO } from 'fp-ts/IO' -import { IOEither } from 'fp-ts/IOEither' -import { IOOption } from 'fp-ts/IOOption' -import { Option } from 'fp-ts/Option' -import { Task } from 'fp-ts/Task' -import { TaskEither } from 'fp-ts/TaskEither' -import { TaskOption } from 'fp-ts/TaskOption' - -export type FpTs = A extends _.Option - ? Option> - : A extends _.Either - ? Either, FpTs> - : A extends _.IO - ? B extends _.Option - ? IOOption> - : B extends _.Either - ? IOEither, FpTs> - : IO> - : A extends _.Task - ? B extends _.Option - ? TaskOption> - : B extends _.Either - ? TaskEither, FpTs> - : Task> - : A extends Error - ? A - : A extends (...args: any) => any - ? (...args: FpTs>) => FpTs> - : A extends { [K: string]: any } - ? { [K in keyof A]: FpTs } - : A diff --git a/packages/effect-fp-ts/tsconfig.json b/packages/effect-fp-ts/tsconfig.json deleted file mode 100644 index 41b3dc9..0000000 --- a/packages/effect-fp-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } -} diff --git a/packages/effect-raw/CHANGELOG.md b/packages/effect-raw/CHANGELOG.md deleted file mode 100644 index 7770bd2..0000000 --- a/packages/effect-raw/CHANGELOG.md +++ /dev/null @@ -1,59 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.3](https://github.com/xzhavilla/imho/compare/@imho/effect-raw@0.3.2...@imho/effect-raw@0.3.3) (2023-07-28) - -**Note:** Version bump only for package @imho/effect-raw - - - - - -## [0.3.2](https://github.com/xzhavilla/imho/compare/@imho/effect-raw@0.3.1...@imho/effect-raw@0.3.2) (2023-07-24) - - -### Bug Fixes - -* **effect:** avoid forcing `readonly` property ([#2](https://github.com/xzhavilla/imho/issues/2)) ([e4c96d8](https://github.com/xzhavilla/imho/commit/e4c96d8770e99ecc7d77c5da7d5b13bfe6127ea3)) - - - - - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/effect-raw@0.3.0...@imho/effect-raw@0.3.1) (2023-07-24) - - -### Bug Fixes - -* **effect:** avoid transforming Error types ([#1](https://github.com/xzhavilla/imho/issues/1)) ([cabefc4](https://github.com/xzhavilla/imho/commit/cabefc438eaa31dc9da47ce7d5539f2e17606764)) - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/effect-raw@0.2.0...@imho/effect-raw@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **effect:** add Effect module ([e7aa396](https://github.com/xzhavilla/imho/commit/e7aa3960ca0c65467140a68fc40475f9e5e1fe70)) diff --git a/packages/effect-raw/README.md b/packages/effect-raw/README.md deleted file mode 100644 index 4a3d452..0000000 --- a/packages/effect-raw/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/effect-raw - -[![npm](https://img.shields.io/npm/v/@imho/effect-raw)](https://www.npmjs.com/package/@imho/effect-raw) diff --git a/packages/effect-raw/package.json b/packages/effect-raw/package.json deleted file mode 100644 index 04ed529..0000000 --- a/packages/effect-raw/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@imho/effect-raw", - "version": "0.3.3", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/effect": "^0.2.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/effect-raw/src/index.ts b/packages/effect-raw/src/index.ts deleted file mode 100644 index 5506a10..0000000 --- a/packages/effect-raw/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as _ from '@imho/effect' - -export type Raw = A extends _.Option - ? Raw | undefined - : A extends _.Either - ? Raw | never - : A extends _.IO - ? Raw - : A extends _.Task - ? Promise> - : A extends Error - ? A - : A extends (...args: any) => any - ? (...args: Raw>) => Raw> - : A extends { [K: string]: any } - ? { [K in keyof A]: Raw } - : A diff --git a/packages/effect-raw/tsconfig.json b/packages/effect-raw/tsconfig.json deleted file mode 100644 index 41b3dc9..0000000 --- a/packages/effect-raw/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } -} diff --git a/packages/effect/CHANGELOG.md b/packages/effect/CHANGELOG.md deleted file mode 100644 index e2b3712..0000000 --- a/packages/effect/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.2.1](https://github.com/xzhavilla/imho/compare/@imho/effect@0.2.0...@imho/effect@0.2.1) (2023-07-28) - -**Note:** Version bump only for package @imho/effect - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **effect:** add Effect module ([e7aa396](https://github.com/xzhavilla/imho/commit/e7aa3960ca0c65467140a68fc40475f9e5e1fe70)) diff --git a/packages/effect/README.md b/packages/effect/README.md deleted file mode 100644 index c416df4..0000000 --- a/packages/effect/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/effect - -[![npm](https://img.shields.io/npm/v/@imho/effect)](https://www.npmjs.com/package/@imho/effect) diff --git a/packages/effect/package.json b/packages/effect/package.json deleted file mode 100644 index f22e308..0000000 --- a/packages/effect/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "@imho/effect", - "version": "0.2.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/effect/src/index.ts b/packages/effect/src/index.ts deleted file mode 100644 index 6a07c84..0000000 --- a/packages/effect/src/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -declare const OptionURI: unique symbol -export interface Option { - readonly [OptionURI]: typeof OptionURI -} - -declare const EitherURI: unique symbol -export interface Either { - readonly [EitherURI]: typeof EitherURI -} - -declare const IOURI: unique symbol -export interface IO { - readonly [IOURI]: typeof IOURI -} - -declare const TaskURI: unique symbol -export interface Task { - readonly [TaskURI]: typeof TaskURI -} diff --git a/packages/effect/tsconfig.json b/packages/effect/tsconfig.json deleted file mode 100644 index fe47617..0000000 --- a/packages/effect/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } -} diff --git a/packages/http-fp-ts-axios/CHANGELOG.md b/packages/http-axios/CHANGELOG.md similarity index 100% rename from packages/http-fp-ts-axios/CHANGELOG.md rename to packages/http-axios/CHANGELOG.md diff --git a/packages/http-axios/README.md b/packages/http-axios/README.md new file mode 100644 index 0000000..18bc0dc --- /dev/null +++ b/packages/http-axios/README.md @@ -0,0 +1,3 @@ +# @imho/http-axios + +[![npm](https://img.shields.io/npm/v/@imho/http-axios)](https://www.npmjs.com/package/@imho/http-axios) diff --git a/packages/http-fp-ts/package.json b/packages/http-axios/package.json similarity index 67% rename from packages/http-fp-ts/package.json rename to packages/http-axios/package.json index d27754c..bc56c91 100644 --- a/packages/http-fp-ts/package.json +++ b/packages/http-axios/package.json @@ -1,5 +1,5 @@ { - "name": "@imho/http-fp-ts", + "name": "@imho/http-axios", "version": "0.1.1", "description": "", "license": "MIT", @@ -7,10 +7,9 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,9 +17,11 @@ "prepack": "npm run build" }, "peerDependencies": { - "@imho/effect-fp-ts": "^0.3.2", - "@imho/http": "^0.1.0", - "fp-ts": "^2.16.0" + "@imho/clock": "*", + "@imho/http": "*", + "@imho/log": "*", + "@xzhayon/fx": "^0.3.0 || ^0.4.0", + "axios": "^1.4.0" }, "publishConfig": { "access": "public" diff --git a/packages/http-raw-axios/src/AxiosHttp.test.ts b/packages/http-axios/src/AxiosHttp.test.ts similarity index 53% rename from packages/http-raw-axios/src/AxiosHttp.test.ts rename to packages/http-axios/src/AxiosHttp.test.ts index 655fba6..26fefbe 100644 --- a/packages/http-raw-axios/src/AxiosHttp.test.ts +++ b/packages/http-axios/src/AxiosHttp.test.ts @@ -1,31 +1,45 @@ -import { DateClock } from '@imho/clock-raw' +import { DateClock } from '@imho/clock' import { HttpError, HttpResponseError } from '@imho/http' -import { VoidLog } from '@imho/log-raw' +import { VoidLog } from '@imho/log' import axios from 'axios' +import nock from 'nock' import { AxiosHttp } from './AxiosHttp' describe('AxiosHttp', () => { + nock('http://foobar') + .get('/404') + .reply(404) + .get('/json') + .reply(200, JSON.stringify({ foo: 'bar' }), { + 'content-type': 'application/json', + }) + .get('/text') + .reply(200, 'foobar', { 'content-type': 'text/plain' }) + .get('/xml') + .reply(200, 'bar', { 'content-type': 'application/xml' }) + const http = new AxiosHttp(axios, new DateClock(), new VoidLog()) describe('get', () => { - test('throwing `HttpError` on invalid request', async () => { + test('returning `HttpError` on invalid request', async () => { const response = http.get(`foo://bar`) + await expect(response).rejects.toThrow(HttpError) await expect(response).rejects.not.toThrow(HttpResponseError) }) - test('throwing `HttpResponseError` on HTTP error', async () => { - await expect(http.get(`${process.env.NGINX_URL}/404`)).rejects.toThrow( + + test('returning `HttpResponseError` on HTTP error', async () => { + await expect(http.get(`http://foobar/404`)).rejects.toThrow( HttpResponseError, ) }) + test.each([ ['JSON', 'json', 'application/json', { foo: 'bar' }], ['text', 'text', 'text/plain', 'foobar'], ['XML', 'xml', 'application/xml', 'bar'], ])('forwarding %s response', async (_type, path, mimeType, body) => { - await expect( - http.get(`${process.env.NGINX_URL}/${path}`), - ).resolves.toMatchObject({ + await expect(http.get(`http://foobar/${path}`)).resolves.toMatchObject({ status: 200, headers: { 'content-type': mimeType }, body, diff --git a/packages/http-axios/src/AxiosHttp.ts b/packages/http-axios/src/AxiosHttp.ts new file mode 100644 index 0000000..10b694c --- /dev/null +++ b/packages/http-axios/src/AxiosHttp.ts @@ -0,0 +1,94 @@ +import { Clock } from '@imho/clock' +import { + Body, + Http, + HttpError, + HttpResponseError, + Options, + Url, +} from '@imho/http' +import { Log } from '@imho/log' +import { Axios, isAxiosError } from 'axios' +import { fromAxiosResponse } from './Response' + +const source = 'AxiosHttp' + +export class AxiosHttp implements Http { + constructor( + private readonly axios: Axios, + private readonly clock: Clock, + private readonly log: Log, + ) {} + + delete(url: Url, options?: Options) { + return this.request('delete', url, null, options) + } + + get(url: Url, options?: Options) { + return this.request('get', url, null, options) + } + + head(url: Url, options?: Options) { + return this.request('head', url, null, options) + } + + options(url: Url, options?: Options) { + return this.request('options', url, null, options) + } + + patch(url: Url, body?: Body | null, options?: Options) { + return this.request('patch', url, body, options) + } + + post(url: Url, body?: Body | null, options?: Options) { + return this.request('post', url, body, options) + } + + put(url: Url, body?: Body | null, options?: Options) { + return this.request('put', url, body, options) + } + + private async request( + method: Extract, + url: Url, + body?: Body | null, + options?: Options, + ) { + try { + const startTime = this.clock.now() + const response = await this.axios.request({ + url: url.toString(), + method, + headers: options?.headers, + params: options?.query, + data: body, + }) + const endTime = this.clock.now() + await this.log.debug('HTTP request succeded', { + url: response.config.url ?? url.toString(), + method, + duration: endTime.valueOf() - startTime.valueOf(), + source, + }) + + return fromAxiosResponse(response) + } catch (cause) { + const error = + isAxiosError(cause) && cause.response !== undefined + ? new HttpResponseError( + fromAxiosResponse(cause.response), + `HTTP ${cause.response.status} ${cause.response.statusText}`, + { cause }, + ) + : new HttpError('Cannot get response from server', { cause }) + await this.log.error('HTTP request failed', { + error, + url: url.toString(), + method, + source, + }) + + throw error + } + } +} diff --git a/packages/http-axios/src/FxAxiosHttp.test.ts b/packages/http-axios/src/FxAxiosHttp.test.ts new file mode 100644 index 0000000..a45df43 --- /dev/null +++ b/packages/http-axios/src/FxAxiosHttp.test.ts @@ -0,0 +1,63 @@ +import { Clock, FxDateClock } from '@imho/clock' +import { Http, HttpError, HttpResponseError } from '@imho/http' +import { FxVoidLog, Log } from '@imho/log' +import { layer, perform, run } from '@xzhayon/fx' +import axios from 'axios' +import nock from 'nock' +import { FxAxiosHttp } from './FxAxiosHttp' + +describe('FxAxiosHttp', () => { + nock('http://foobar') + .get('/404') + .reply(404) + .get('/json') + .reply(200, JSON.stringify({ foo: 'bar' }), { + 'content-type': 'application/json', + }) + .get('/text') + .reply(200, 'foobar', { 'content-type': 'text/plain' }) + .get('/xml') + .reply(200, 'bar', { 'content-type': 'application/xml' }) + + const _layer = layer() + .with(Http, FxAxiosHttp(axios)) + .with(Clock, FxDateClock()) + .with(Log, FxVoidLog()) + .do() + + describe('get', () => { + test('returning `HttpError` on invalid request', async () => { + function* f() { + return yield* perform(Http.get(`foo://bar`)) + } + const response = run(f(), _layer) + + await expect(response).rejects.toThrow(HttpError) + await expect(response).rejects.not.toThrow(HttpResponseError) + }) + + test('returning `HttpResponseError` on HTTP error', async () => { + function* f() { + return yield* perform(Http.get(`http://foobar/404`)) + } + + await expect(run(f(), _layer)).rejects.toThrow(HttpResponseError) + }) + + test.each([ + ['JSON', 'json', 'application/json', { foo: 'bar' }], + ['text', 'text', 'text/plain', 'foobar'], + ['XML', 'xml', 'application/xml', 'bar'], + ])('forwarding %s response', async (_type, path, mimeType, body) => { + function* f() { + return yield* perform(Http.get(`http://foobar/${path}`)) + } + + await expect(run(f(), _layer)).resolves.toMatchObject({ + status: 200, + headers: { 'content-type': mimeType }, + body, + }) + }) + }) +}) diff --git a/packages/http-axios/src/FxAxiosHttp.ts b/packages/http-axios/src/FxAxiosHttp.ts new file mode 100644 index 0000000..00b3244 --- /dev/null +++ b/packages/http-axios/src/FxAxiosHttp.ts @@ -0,0 +1,75 @@ +import { Clock } from '@imho/clock' +import { + Body, + Http, + HttpError, + HttpResponseError, + Options, + Url, +} from '@imho/http' +import { Log } from '@imho/log' +import { Handler, perform } from '@xzhayon/fx' +import { Axios, isAxiosError } from 'axios' +import { fromAxiosResponse } from './Response' + +const source = 'FxAxiosHttp' + +export function FxAxiosHttp(axios: Axios) { + async function* request( + method: Extract, + url: Url, + body?: Body | null, + options?: Options, + ) { + try { + const startTime = yield* perform(Clock.now()) + const response = await axios.request({ + url: url.toString(), + method, + headers: options?.headers, + params: options?.query, + data: body, + }) + const endTime = yield* perform(Clock.now()) + yield* perform( + Log.debug('HTTP request succeded', { + url: response.config.url ?? url.toString(), + method, + duration: endTime.valueOf() - startTime.valueOf(), + source, + }), + ) + + return fromAxiosResponse(response) + } catch (cause) { + const error = + isAxiosError(cause) && cause.response !== undefined + ? new HttpResponseError( + fromAxiosResponse(cause.response), + `HTTP ${cause.response.status} ${cause.response.statusText}`, + { cause }, + ) + : new HttpError('Cannot get response from server', { cause }) + yield* perform( + Log.error('HTTP request failed', { + error, + url: url.toString(), + method, + source, + }), + ) + + throw error + } + } + + return { + delete: (url, options) => request('delete', url, null, options), + get: (url, options) => request('get', url, null, options), + head: (url, options) => request('head', url, null, options), + options: (url, options) => request('options', url, null, options), + patch: (url, body, options) => request('patch', url, body, options), + post: (url, body, options) => request('post', url, body, options), + put: (url, body, options) => request('put', url, body, options), + } satisfies Handler +} diff --git a/packages/http-axios/src/Response.ts b/packages/http-axios/src/Response.ts new file mode 100644 index 0000000..2aa3d70 --- /dev/null +++ b/packages/http-axios/src/Response.ts @@ -0,0 +1,14 @@ +import { Response } from '@imho/http' +import { AxiosResponse } from 'axios' + +export const fromAxiosResponse = ({ + status, + headers, + data, +}: AxiosResponse): Response => ({ + status, + headers: Object.fromEntries( + Object.entries(headers).filter(([_, value]) => value !== undefined), + ), + body: data, +}) diff --git a/packages/http-axios/src/index.ts b/packages/http-axios/src/index.ts new file mode 100644 index 0000000..fce7c94 --- /dev/null +++ b/packages/http-axios/src/index.ts @@ -0,0 +1,2 @@ +export * from './AxiosHttp' +export * from './FxAxiosHttp' diff --git a/packages/http-raw/tsconfig.json b/packages/http-axios/tsconfig.json similarity index 70% rename from packages/http-raw/tsconfig.json rename to packages/http-axios/tsconfig.json index fc7c947..2ed2340 100644 --- a/packages/http-raw/tsconfig.json +++ b/packages/http-axios/tsconfig.json @@ -1,9 +1,9 @@ { "extends": "../../tsconfig.build.json", "references": [ - { "path": "../effect-raw" }, + { "path": "../clock" }, { "path": "../http" }, - { "path": "../http-fp-ts" } + { "path": "../log" } ], "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/http-effect-ts-axios/CHANGELOG.md b/packages/http-effect-ts-axios/CHANGELOG.md deleted file mode 100644 index 66d2372..0000000 --- a/packages/http-effect-ts-axios/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/http-effect-ts-axios@0.1.0...@imho/http-effect-ts-axios@0.1.1) (2023-07-28) - -**Note:** Version bump only for package @imho/http-effect-ts-axios - - - - - -# 0.1.0 (2023-07-28) - - -### Features - -* **http:** add Http module ([#7](https://github.com/xzhavilla/imho/issues/7)) ([f03204e](https://github.com/xzhavilla/imho/commit/f03204ebcbb5c9caf773596803d4b5ff82e9673f)) diff --git a/packages/http-effect-ts-axios/README.md b/packages/http-effect-ts-axios/README.md deleted file mode 100644 index 2bf28c5..0000000 --- a/packages/http-effect-ts-axios/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/http-effect-ts-axios - -[![npm](https://img.shields.io/npm/v/@imho/http-effect-ts-axios)](https://www.npmjs.com/package/@imho/http-effect-ts-axios) diff --git a/packages/http-effect-ts-axios/package.json b/packages/http-effect-ts-axios/package.json deleted file mode 100644 index b4767e3..0000000 --- a/packages/http-effect-ts-axios/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@imho/http-effect-ts-axios", - "version": "0.1.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/http-fp-ts-axios": "^0.1.1" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/clock-effect-ts": "^0.1.1", - "@imho/http-effect-ts": "^0.1.0", - "@imho/log-effect-ts": "^0.3.1", - "axios": "^1.4.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/http-effect-ts-axios/src/AxiosHttp.test.ts b/packages/http-effect-ts-axios/src/AxiosHttp.test.ts deleted file mode 100644 index 4269719..0000000 --- a/packages/http-effect-ts-axios/src/AxiosHttp.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import * as Layer from '@effect-ts/core/Effect/Layer' -import { DateClock, HasClock } from '@imho/clock-effect-ts' -import { HttpError, HttpResponseError } from '@imho/http' -import { HasHttp, Http } from '@imho/http-effect-ts' -import { HasLog, VoidLog } from '@imho/log-effect-ts' -import axios from 'axios' -import { AxiosHttp } from './AxiosHttp' - -describe('AxiosHttp', () => { - const layer = pipe( - Layer.fromEffect(HasHttp)(AxiosHttp(axios)), - Layer.using(Layer.fromValue(HasClock)(new DateClock())), - Layer.using(Layer.fromValue(HasLog)(new VoidLog())), - Layer.main, - ) - - describe('get', () => { - test('returning `HttpError` on invalid request', async () => { - const response = Http.get(`foo://bar`) - await expect( - pipe(response, Effect.provideLayer(layer), Effect.runPromise), - ).rejects.toThrow(HttpError) - await expect( - pipe(response, Effect.provideLayer(layer), Effect.runPromise), - ).rejects.not.toThrow(HttpResponseError) - }) - test('returning `HttpResponseError` on HTTP error', async () => { - await expect( - pipe( - Http.get(`${process.env.NGINX_URL}/404`), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).rejects.toThrow(HttpResponseError) - }) - test.each([ - ['JSON', 'json', 'application/json', { foo: 'bar' }], - ['text', 'text', 'text/plain', 'foobar'], - ['XML', 'xml', 'application/xml', 'bar'], - ])('forwarding %s response', async (_type, path, mimeType, body) => { - await expect( - pipe( - Http.get(`${process.env.NGINX_URL}/${path}`), - Effect.provideLayer(layer), - Effect.runPromise, - ), - ).resolves.toMatchObject({ - status: 200, - headers: { 'content-type': mimeType }, - body, - }) - }) - }) -}) diff --git a/packages/http-effect-ts-axios/src/AxiosHttp.ts b/packages/http-effect-ts-axios/src/AxiosHttp.ts deleted file mode 100644 index a27364d..0000000 --- a/packages/http-effect-ts-axios/src/AxiosHttp.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Effect } from '@effect-ts/core' -import { Clock, EffectTsToFpTsClock, HasClock } from '@imho/clock-effect-ts' -import { FpTsToEffectTsHttp, Http } from '@imho/http-effect-ts' -import * as fpTs from '@imho/http-fp-ts-axios' -import { EffectTsToFpTsLog, HasLog, Log } from '@imho/log-effect-ts' -import { Axios } from 'axios' - -export const AxiosHttp = (axios: Axios) => - Effect.accessServices({ clock: HasClock, log: HasLog })( - ({ clock, log }): Http => - new (class AxiosHttp extends FpTsToEffectTsHttp { - constructor(axios: Axios, clock: Clock, log: Log) { - super( - fpTs.AxiosHttp(axios)({ - clock: new EffectTsToFpTsClock(clock), - log: new EffectTsToFpTsLog(log), - }), - ) - } - })(axios, clock, log), - ) diff --git a/packages/http-effect-ts-axios/src/index.ts b/packages/http-effect-ts-axios/src/index.ts deleted file mode 100644 index 391dfd8..0000000 --- a/packages/http-effect-ts-axios/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './AxiosHttp' diff --git a/packages/http-effect-ts-axios/tsconfig.json b/packages/http-effect-ts-axios/tsconfig.json deleted file mode 100644 index 67d3ebb..0000000 --- a/packages/http-effect-ts-axios/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../clock-effect-ts" }, - { "path": "../http" }, - { "path": "../http-effect-ts" }, - { "path": "../http-fp-ts-axios" }, - { "path": "../log-effect-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/http-effect-ts/CHANGELOG.md b/packages/http-effect-ts/CHANGELOG.md deleted file mode 100644 index c3bc5e2..0000000 --- a/packages/http-effect-ts/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/http-effect-ts@0.1.0...@imho/http-effect-ts@0.1.1) (2023-07-28) - -**Note:** Version bump only for package @imho/http-effect-ts - - - - - -# 0.1.0 (2023-07-28) - - -### Features - -* **http:** add Http module ([#7](https://github.com/xzhavilla/imho/issues/7)) ([f03204e](https://github.com/xzhavilla/imho/commit/f03204ebcbb5c9caf773596803d4b5ff82e9673f)) diff --git a/packages/http-effect-ts/README.md b/packages/http-effect-ts/README.md deleted file mode 100644 index 82fee64..0000000 --- a/packages/http-effect-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/http-effect-ts - -[![npm](https://img.shields.io/npm/v/@imho/http-effect-ts)](https://www.npmjs.com/package/@imho/http-effect-ts) diff --git a/packages/http-effect-ts/package.json b/packages/http-effect-ts/package.json deleted file mode 100644 index 5ccee9a..0000000 --- a/packages/http-effect-ts/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@imho/http-effect-ts", - "version": "0.1.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "fp-ts": "^2.16.1" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/effect-effect-ts": "^0.3.2 || ^0.4.0", - "@imho/http": "^0.1.0", - "@imho/http-fp-ts": "^0.1.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/http-effect-ts/src/FpTsToEffectTsHttp.ts b/packages/http-effect-ts/src/FpTsToEffectTsHttp.ts deleted file mode 100644 index 6b39134..0000000 --- a/packages/http-effect-ts/src/FpTsToEffectTsHttp.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import { Body, Options, Url } from '@imho/http' -import * as fpTs from '@imho/http-fp-ts' -import { either } from 'fp-ts' -import { Http } from './Http' - -export class FpTsToEffectTsHttp implements Http { - constructor(private readonly http: fpTs.Http) {} - - delete(url: Url, options?: Options) { - return this.request('delete', url, options) - } - - get(url: Url, options?: Options) { - return this.request('get', url, options) - } - - head(url: Url, options?: Options) { - return this.request('head', url, options) - } - - options(url: Url, options?: Options) { - return this.request('options', url, options) - } - - patch(url: Url, body?: Body | null, options?: Options) { - return this.request('patch', url, body, options) - } - - post(url: Url, body?: Body | null, options?: Options) { - return this.request('post', url, body, options) - } - - put(url: Url, body?: Body | null, options?: Options) { - return this.request('put', url, body, options) - } - - private request( - method: A, - ...args: Parameters - ) { - return pipe( - Effect.promise(this.http[method](...(args as [any]))), - Effect.chain((response) => - either.isLeft(response) - ? Effect.fail(response.left) - : Effect.succeed(response.right), - ), - ) - } -} diff --git a/packages/http-effect-ts/src/Http.ts b/packages/http-effect-ts/src/Http.ts deleted file mode 100644 index 1fb8502..0000000 --- a/packages/http-effect-ts/src/Http.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Effect, Has } from '@effect-ts/core' -import { EffectTs } from '@imho/effect-effect-ts' -import * as _ from '@imho/http' - -export interface Http extends EffectTs<_.Http> {} - -export const HasHttp = Has.tag() - -export const Http = Effect.deriveLifted(HasHttp)( - ['delete', 'get', 'head', 'options', 'patch', 'post', 'put'], - [], - [], -) diff --git a/packages/http-effect-ts/src/index.ts b/packages/http-effect-ts/src/index.ts deleted file mode 100644 index b88df42..0000000 --- a/packages/http-effect-ts/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './FpTsToEffectTsHttp' -export * from './Http' diff --git a/packages/http-effect-ts/tsconfig.json b/packages/http-effect-ts/tsconfig.json deleted file mode 100644 index 470ba24..0000000 --- a/packages/http-effect-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../effect-effect-ts" }, - { "path": "../http" }, - { "path": "../http-fp-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/http-fp-ts-axios/README.md b/packages/http-fp-ts-axios/README.md deleted file mode 100644 index 2f1a20c..0000000 --- a/packages/http-fp-ts-axios/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/http-fp-ts-axios - -[![npm](https://img.shields.io/npm/v/@imho/http-fp-ts-axios)](https://www.npmjs.com/package/@imho/http-fp-ts-axios) diff --git a/packages/http-fp-ts-axios/package.json b/packages/http-fp-ts-axios/package.json deleted file mode 100644 index c4ec5ff..0000000 --- a/packages/http-fp-ts-axios/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@imho/http-fp-ts-axios", - "version": "0.1.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/clock-fp-ts": "^0.1.0", - "@imho/http": "^0.1.0", - "@imho/http-fp-ts": "^0.1.0", - "@imho/log-fp-ts": "^0.3.0", - "axios": "^1.4.0", - "fp-ts": "^2.16.1" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/http-fp-ts-axios/src/AxiosHttp.test.ts b/packages/http-fp-ts-axios/src/AxiosHttp.test.ts deleted file mode 100644 index b6f85d2..0000000 --- a/packages/http-fp-ts-axios/src/AxiosHttp.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { DateClock } from '@imho/clock-fp-ts' -import { HttpError, HttpResponseError } from '@imho/http' -import { Http } from '@imho/http-fp-ts' -import { VoidLog } from '@imho/log-fp-ts' -import axios from 'axios' -import { either } from 'fp-ts' -import { AxiosHttp } from './AxiosHttp' - -describe('AxiosHttp', () => { - const http = AxiosHttp(axios)({ - clock: new DateClock(), - log: new VoidLog(), - }) - - describe('get', () => { - test('returning `HttpError` on invalid request', async () => { - const error = ((await Http.get(`foo://bar`)(http)()) as any).left - expect(error).toBeInstanceOf(HttpError) - expect(error).not.toBeInstanceOf(HttpResponseError) - }) - test('returning `HttpResponseError` on HTTP error', async () => { - expect( - ((await Http.get(`${process.env.NGINX_URL}/404`)(http)()) as any).left, - ).toBeInstanceOf(HttpResponseError) - }) - test.each([ - ['JSON', 'json', 'application/json', { foo: 'bar' }], - ['text', 'text', 'text/plain', 'foobar'], - ['XML', 'xml', 'application/xml', 'bar'], - ])('forwarding %s response', async (_type, path, mimeType, body) => { - await expect( - Http.get(`${process.env.NGINX_URL}/${path}`)(http)(), - ).resolves.toMatchObject( - either.right({ - status: 200, - headers: { 'content-type': mimeType }, - body, - }), - ) - }) - }) -}) diff --git a/packages/http-fp-ts-axios/src/AxiosHttp.ts b/packages/http-fp-ts-axios/src/AxiosHttp.ts deleted file mode 100644 index 5c27040..0000000 --- a/packages/http-fp-ts-axios/src/AxiosHttp.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { Clock } from '@imho/clock-fp-ts' -import { - Body, - HttpError, - HttpResponseError, - Options, - Response, - Url, -} from '@imho/http' -import { Http } from '@imho/http-fp-ts' -import { Log } from '@imho/log-fp-ts' -import { Axios, AxiosResponse, isAxiosError } from 'axios' -import { reader, taskEither } from 'fp-ts' -import { pipe } from 'fp-ts/function' -import { TaskEither } from 'fp-ts/TaskEither' - -const channel = 'AxiosHttp' - -export const AxiosHttp = (axios: Axios) => - pipe( - reader.ask<{ clock: Clock; log: Log }>(), - reader.map( - ({ clock, log }): Http => - new (class AxiosHttp implements Http { - constructor( - private readonly axios: Axios, - private readonly clock: Clock, - private readonly log: Log, - ) {} - - delete(url: Url, options?: Options) { - return this.request('delete', url, null, options) - } - - get(url: Url, options?: Options) { - return this.request('get', url, null, options) - } - - head(url: Url, options?: Options) { - return this.request('head', url, null, options) - } - - options(url: Url, options?: Options) { - return this.request('options', url, null, options) - } - - patch(url: Url, body?: Body | null, options?: Options) { - return this.request('patch', url, body, options) - } - - post(url: Url, body?: Body | null, options?: Options) { - return this.request('post', url, body, options) - } - - put(url: Url, body?: Body | null, options?: Options) { - return this.request('put', url, body, options) - } - - private request( - method: keyof Http, - url: Url, - body?: Body | null, - options?: Options, - ): TaskEither { - return pipe( - taskEither.Do, - taskEither.bind('startTime', () => - taskEither.fromIO(this.clock.now()), - ), - taskEither.bind('response', () => - taskEither.tryCatch( - () => - this.axios.request({ - url: url.toString(), - method, - headers: options?.headers, - params: options?.query, - data: body, - }), - (cause) => - isAxiosError(cause) && cause.response !== undefined - ? new HttpResponseError( - response(cause.response), - `HTTP ${cause.response.status} ${cause.response.statusText}`, - { cause }, - ) - : new HttpError('Cannot get response from server', { - cause, - }), - ), - ), - taskEither.bind('endTime', () => - taskEither.fromIO(this.clock.now()), - ), - taskEither.tapTask(({ response, startTime, endTime }) => - this.log.debug('HTTP request succeded', { - channel, - url: response.config.url ?? url.toString(), - method, - duration: endTime - startTime, - }), - ), - taskEither.orElseFirstTaskK((error) => - this.log.error('HTTP request failed', { - channel, - error, - url: url.toString(), - method, - }), - ), - taskEither.map(({ response }) => response), - taskEither.map(response), - ) - } - })(axios, clock, log), - ), - ) - -const response = ({ status, headers, data }: AxiosResponse): Response => ({ - status, - headers: Object.fromEntries( - Object.entries(headers).filter(([_, value]) => value !== undefined), - ), - body: data, -}) diff --git a/packages/http-fp-ts-axios/src/index.ts b/packages/http-fp-ts-axios/src/index.ts deleted file mode 100644 index 391dfd8..0000000 --- a/packages/http-fp-ts-axios/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './AxiosHttp' diff --git a/packages/http-fp-ts-axios/tsconfig.json b/packages/http-fp-ts-axios/tsconfig.json deleted file mode 100644 index 15d6972..0000000 --- a/packages/http-fp-ts-axios/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../clock-fp-ts" }, - { "path": "../http" }, - { "path": "../http-fp-ts" }, - { "path": "../log-fp-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/http-fp-ts/CHANGELOG.md b/packages/http-fp-ts/CHANGELOG.md deleted file mode 100644 index d0436d1..0000000 --- a/packages/http-fp-ts/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/http-fp-ts@0.1.0...@imho/http-fp-ts@0.1.1) (2023-07-28) - -**Note:** Version bump only for package @imho/http-fp-ts - - - - - -# 0.1.0 (2023-07-28) - - -### Features - -* **http:** add Http module ([#7](https://github.com/xzhavilla/imho/issues/7)) ([f03204e](https://github.com/xzhavilla/imho/commit/f03204ebcbb5c9caf773596803d4b5ff82e9673f)) diff --git a/packages/http-fp-ts/README.md b/packages/http-fp-ts/README.md deleted file mode 100644 index b5758cd..0000000 --- a/packages/http-fp-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/http-fp-ts - -[![npm](https://img.shields.io/npm/v/@imho/http-fp-ts)](https://www.npmjs.com/package/@imho/http-fp-ts) diff --git a/packages/http-fp-ts/src/Http.ts b/packages/http-fp-ts/src/Http.ts deleted file mode 100644 index e9f8635..0000000 --- a/packages/http-fp-ts/src/Http.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { FpTs } from '@imho/effect-fp-ts' -import * as _ from '@imho/http' -import { readerTaskEither } from 'fp-ts' -import { pipe } from 'fp-ts/function' - -export interface Http extends FpTs<_.Http> {} - -const request = - (method: A) => - (...args: Parameters) => - pipe( - readerTaskEither.ask(), - readerTaskEither.chainTaskEitherK((http) => - http[method](...(args as [any])), - ), - ) - -export const Http = { - delete: request('delete'), - get: request('get'), - head: request('head'), - options: request('options'), - patch: request('patch'), - post: request('post'), - put: request('put'), -} diff --git a/packages/http-fp-ts/src/index.ts b/packages/http-fp-ts/src/index.ts deleted file mode 100644 index 4824060..0000000 --- a/packages/http-fp-ts/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Http' diff --git a/packages/http-fp-ts/tsconfig.json b/packages/http-fp-ts/tsconfig.json deleted file mode 100644 index 3153bfb..0000000 --- a/packages/http-fp-ts/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect-fp-ts" }, { "path": "../http" }], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/http-raw-axios/CHANGELOG.md b/packages/http-raw-axios/CHANGELOG.md deleted file mode 100644 index e224cdd..0000000 --- a/packages/http-raw-axios/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/http-raw-axios@0.1.0...@imho/http-raw-axios@0.1.1) (2023-07-28) - -**Note:** Version bump only for package @imho/http-raw-axios - - - - - -# 0.1.0 (2023-07-28) - - -### Features - -* **http:** add Http module ([#7](https://github.com/xzhavilla/imho/issues/7)) ([f03204e](https://github.com/xzhavilla/imho/commit/f03204ebcbb5c9caf773596803d4b5ff82e9673f)) diff --git a/packages/http-raw-axios/README.md b/packages/http-raw-axios/README.md deleted file mode 100644 index 77f125e..0000000 --- a/packages/http-raw-axios/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/http-raw-axios - -[![npm](https://img.shields.io/npm/v/@imho/http-raw-axios)](https://www.npmjs.com/package/@imho/http-raw-axios) diff --git a/packages/http-raw-axios/package.json b/packages/http-raw-axios/package.json deleted file mode 100644 index def0fef..0000000 --- a/packages/http-raw-axios/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@imho/http-raw-axios", - "version": "0.1.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/http-fp-ts-axios": "^0.1.1" - }, - "peerDependencies": { - "@imho/clock-raw": "^0.1.1", - "@imho/http-raw": "^0.1.0", - "@imho/log-raw": "^0.3.0", - "axios": "^1.4.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/http-raw-axios/src/AxiosHttp.ts b/packages/http-raw-axios/src/AxiosHttp.ts deleted file mode 100644 index e8a20ff..0000000 --- a/packages/http-raw-axios/src/AxiosHttp.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Clock, RawToFpTsClock } from '@imho/clock-raw' -import * as fpTs from '@imho/http-fp-ts-axios' -import { FpTsToRawHttp } from '@imho/http-raw' -import { Log, RawToFpTsLog } from '@imho/log-raw' -import { Axios } from 'axios' - -export class AxiosHttp extends FpTsToRawHttp { - constructor(axios: Axios, clock: Clock, log: Log) { - super( - fpTs.AxiosHttp(axios)({ - clock: new RawToFpTsClock(clock), - log: new RawToFpTsLog(log), - }), - ) - } -} diff --git a/packages/http-raw-axios/src/index.ts b/packages/http-raw-axios/src/index.ts deleted file mode 100644 index 391dfd8..0000000 --- a/packages/http-raw-axios/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './AxiosHttp' diff --git a/packages/http-raw-axios/tsconfig.json b/packages/http-raw-axios/tsconfig.json deleted file mode 100644 index e581cc4..0000000 --- a/packages/http-raw-axios/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../clock-raw" }, - { "path": "../http" }, - { "path": "../http-fp-ts-axios" }, - { "path": "../http-raw" }, - { "path": "../log-raw" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/http-raw/CHANGELOG.md b/packages/http-raw/CHANGELOG.md deleted file mode 100644 index 84c01d8..0000000 --- a/packages/http-raw/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.1.1](https://github.com/xzhavilla/imho/compare/@imho/http-raw@0.1.0...@imho/http-raw@0.1.1) (2023-07-28) - -**Note:** Version bump only for package @imho/http-raw - - - - - -# 0.1.0 (2023-07-28) - - -### Features - -* **http:** add Http module ([#7](https://github.com/xzhavilla/imho/issues/7)) ([f03204e](https://github.com/xzhavilla/imho/commit/f03204ebcbb5c9caf773596803d4b5ff82e9673f)) diff --git a/packages/http-raw/README.md b/packages/http-raw/README.md deleted file mode 100644 index 8b1d171..0000000 --- a/packages/http-raw/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/http-raw - -[![npm](https://img.shields.io/npm/v/@imho/http-raw)](https://www.npmjs.com/package/@imho/http-raw) diff --git a/packages/http-raw/package.json b/packages/http-raw/package.json deleted file mode 100644 index 1d117bf..0000000 --- a/packages/http-raw/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "@imho/http-raw", - "version": "0.1.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "fp-ts": "^2.16.1" - }, - "peerDependencies": { - "@imho/effect-raw": "^0.3.2", - "@imho/http": "^0.1.0", - "@imho/http-fp-ts": "^0.1.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/http-raw/src/FpTsToRawHttp.ts b/packages/http-raw/src/FpTsToRawHttp.ts deleted file mode 100644 index 1de140b..0000000 --- a/packages/http-raw/src/FpTsToRawHttp.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Body, Options, Url } from '@imho/http' -import * as fpTs from '@imho/http-fp-ts' -import { either } from 'fp-ts' -import { Http } from './Http' - -export class FpTsToRawHttp implements Http { - constructor(private readonly http: fpTs.Http) {} - - delete(url: Url, options?: Options) { - return this.request('delete', url, options) - } - - get(url: Url, options?: Options) { - return this.request('get', url, options) - } - - head(url: Url, options?: Options) { - return this.request('head', url, options) - } - - options(url: Url, options?: Options) { - return this.request('options', url, options) - } - - patch(url: Url, body?: Body | null, options?: Options) { - return this.request('patch', url, body, options) - } - - post(url: Url, body?: Body | null, options?: Options) { - return this.request('post', url, body, options) - } - - put(url: Url, body?: Body | null, options?: Options) { - return this.request('put', url, body, options) - } - - private async request( - method: A, - ...args: Parameters - ) { - const response = await this.http[method](...(args as [any]))() - if (either.isLeft(response)) { - throw response.left - } - - return response.right - } -} diff --git a/packages/http-raw/src/Http.ts b/packages/http-raw/src/Http.ts deleted file mode 100644 index 1cdc688..0000000 --- a/packages/http-raw/src/Http.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Raw } from '@imho/effect-raw' -import * as _ from '@imho/http' - -export interface Http extends Raw<_.Http> {} diff --git a/packages/http-raw/src/index.ts b/packages/http-raw/src/index.ts deleted file mode 100644 index 2572300..0000000 --- a/packages/http-raw/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './FpTsToRawHttp' -export * from './Http' diff --git a/packages/http/package.json b/packages/http/package.json index 9826236..882f128 100644 --- a/packages/http/package.json +++ b/packages/http/package.json @@ -7,10 +7,9 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,7 +17,7 @@ "prepack": "npm run build" }, "peerDependencies": { - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.2.3 || ^0.3.0 || ^0.4.0" }, "publishConfig": { "access": "public" diff --git a/packages/http/src/Http.ts b/packages/http/src/Http.ts index 54e7eab..d804b66 100644 --- a/packages/http/src/Http.ts +++ b/packages/http/src/Http.ts @@ -1,28 +1,23 @@ -import { Either, Task } from '@imho/effect' +import * as fx from '@xzhayon/fx' import { Body } from './Body' -import { HttpError } from './HttpError' import { Options } from './Options' import { Response } from './Response' import { Url } from './Url' export interface Http { - delete(url: Url, options?: Options): Task> - get(url: Url, options?: Options): Task> - head(url: Url, options?: Options): Task> - options(url: Url, options?: Options): Task> - patch( - url: Url, - body?: Body | null, - options?: Options, - ): Task> - post( - url: Url, - body?: Body | null, - options?: Options, - ): Task> - put( - url: Url, - body?: Body | null, - options?: Options, - ): Task> + readonly [fx.URI]?: unique symbol + delete(url: Url, options?: Options): Promise + get(url: Url, options?: Options): Promise + head(url: Url, options?: Options): Promise + options(url: Url, options?: Options): Promise + patch(url: Url, body?: Body | null, options?: Options): Promise + post(url: Url, body?: Body | null, options?: Options): Promise + put(url: Url, body?: Body | null, options?: Options): Promise +} + +export const tag = fx.tag('Http') + +export const Http = { + tag, + ...fx.struct(tag)('delete', 'get', 'head', 'options', 'patch', 'post', 'put'), } diff --git a/packages/http/src/HttpError.ts b/packages/http/src/HttpError.ts index cee0e24..6a9e4d8 100644 --- a/packages/http/src/HttpError.ts +++ b/packages/http/src/HttpError.ts @@ -1,5 +1,5 @@ export const HttpErrorURI = Symbol() export class HttpError extends Error { - private readonly [HttpErrorURI]!: typeof HttpErrorURI + readonly [HttpErrorURI]!: typeof HttpErrorURI readonly name: string = 'HttpError' } diff --git a/packages/http/src/HttpResponseError.ts b/packages/http/src/HttpResponseError.ts index 75cfa60..edeac78 100644 --- a/packages/http/src/HttpResponseError.ts +++ b/packages/http/src/HttpResponseError.ts @@ -3,7 +3,7 @@ import { Response } from './Response' export const HttpResponseErrorURI = Symbol() export class HttpResponseError extends HttpError { - private readonly [HttpResponseErrorURI]!: typeof HttpResponseErrorURI + readonly [HttpResponseErrorURI]!: typeof HttpResponseErrorURI readonly name: string = 'HttpResponseError' constructor( diff --git a/packages/http/tsconfig.json b/packages/http/tsconfig.json index e84f0a5..fe0dc1e 100644 --- a/packages/http/tsconfig.json +++ b/packages/http/tsconfig.json @@ -1,5 +1,4 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/log-effect-ts-pino/CHANGELOG.md b/packages/log-effect-ts-pino/CHANGELOG.md deleted file mode 100644 index c73c1bf..0000000 --- a/packages/log-effect-ts-pino/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/log-effect-ts-pino@0.3.0...@imho/log-effect-ts-pino@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/log-effect-ts-pino - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/log-effect-ts-pino@0.2.0...@imho/log-effect-ts-pino@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **log:** add pino Log implementation ([28aed83](https://github.com/xzhavilla/imho/commit/28aed83120a7e6de36c15acac3672463e993a97f)) diff --git a/packages/log-effect-ts-pino/README.md b/packages/log-effect-ts-pino/README.md deleted file mode 100644 index 67bc365..0000000 --- a/packages/log-effect-ts-pino/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/log-effect-ts-pino - -[![npm](https://img.shields.io/npm/v/@imho/log-effect-ts-pino)](https://www.npmjs.com/package/@imho/log-effect-ts-pino) diff --git a/packages/log-effect-ts-pino/package.json b/packages/log-effect-ts-pino/package.json deleted file mode 100644 index e6f6e52..0000000 --- a/packages/log-effect-ts-pino/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@imho/log-effect-ts-pino", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "dependencies": { - "@imho/log-fp-ts-pino": "^0.3.1" - }, - "peerDependencies": { - "@imho/log-effect-ts": "^0.2.0 || ^0.3.0", - "pino": "^8.14.1" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/log-effect-ts-pino/src/PinoLog.test.ts b/packages/log-effect-ts-pino/src/PinoLog.test.ts deleted file mode 100644 index e3bc28e..0000000 --- a/packages/log-effect-ts-pino/src/PinoLog.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import * as Layer from '@effect-ts/core/Effect/Layer' -import { HasLog, Log } from '@imho/log-effect-ts' -import { pino } from 'pino' -import { PinoLog } from './PinoLog' - -describe('PinoLog', () => { - let buffer: string | null - const layer = pipe( - Layer.fromValue(HasLog)( - new PinoLog( - pino( - { level: 'debug' }, - { - write(message: string) { - buffer = message - }, - }, - ), - ), - ), - Layer.main, - ) - - beforeEach(() => { - buffer = null - }) - - test.each([ - ['debug', 'debug', 20], - ['info', 'info', 30], - ['notice', 'info', 30], - ['warning', 'warn', 40], - ['error', 'error', 50], - ['alert', 'fatal', 60], - ['critical', 'fatal', 60], - ['emergency', 'fatal', 60], - ] as const)( - 'hadling severity "%s" with level "%s" (%d)', - async (severity, _level, level) => { - await pipe( - Log[severity]('foo'), - Effect.provideLayer(layer), - Effect.runPromise, - ) - expect(JSON.parse(buffer ?? '')).toMatchObject({ level, msg: 'foo' }) - }, - ) -}) diff --git a/packages/log-effect-ts-pino/src/PinoLog.ts b/packages/log-effect-ts-pino/src/PinoLog.ts deleted file mode 100644 index 83657f4..0000000 --- a/packages/log-effect-ts-pino/src/PinoLog.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { FpTsToEffectTsLog } from '@imho/log-effect-ts' -import * as fpTs from '@imho/log-fp-ts-pino' -import pino from 'pino' - -export class PinoLog extends FpTsToEffectTsLog { - constructor(pino: pino.Logger) { - super(new fpTs.PinoLog(pino)) - } -} diff --git a/packages/log-effect-ts-pino/src/index.ts b/packages/log-effect-ts-pino/src/index.ts deleted file mode 100644 index 515538a..0000000 --- a/packages/log-effect-ts-pino/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PinoLog' diff --git a/packages/log-effect-ts-pino/tsconfig.json b/packages/log-effect-ts-pino/tsconfig.json deleted file mode 100644 index cc51d58..0000000 --- a/packages/log-effect-ts-pino/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../log-fp-ts-pino" }, - { "path": "../log-effect-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/log-effect-ts/CHANGELOG.md b/packages/log-effect-ts/CHANGELOG.md deleted file mode 100644 index bee1acf..0000000 --- a/packages/log-effect-ts/CHANGELOG.md +++ /dev/null @@ -1,48 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.2](https://github.com/xzhavilla/imho/compare/@imho/log-effect-ts@0.3.1...@imho/log-effect-ts@0.3.2) (2023-07-28) - -**Note:** Version bump only for package @imho/log-effect-ts - - - - - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/log-effect-ts@0.3.0...@imho/log-effect-ts@0.3.1) (2023-07-24) - - -### Bug Fixes - -* update dependencies ([8153a62](https://github.com/xzhavilla/imho/commit/8153a62440343badf7cd715f276b7850b9fb4d32)) - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/log-effect-ts@0.2.0...@imho/log-effect-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **log:** add Log module ([cd68ee2](https://github.com/xzhavilla/imho/commit/cd68ee26bdcc1fea94415683b5934b7a9c3fa95f)) diff --git a/packages/log-effect-ts/README.md b/packages/log-effect-ts/README.md deleted file mode 100644 index 6e60cc0..0000000 --- a/packages/log-effect-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/log-effect-ts - -[![npm](https://img.shields.io/npm/v/@imho/log-effect-ts)](https://www.npmjs.com/package/@imho/log-effect-ts) diff --git a/packages/log-effect-ts/package.json b/packages/log-effect-ts/package.json deleted file mode 100644 index 876289d..0000000 --- a/packages/log-effect-ts/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "@imho/log-effect-ts", - "version": "0.3.2", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@effect-ts/core": "^0.60.5", - "@imho/effect-effect-ts": "^0.2.0 || ^0.3.0 || ^0.4.0", - "@imho/log": "^0.2.0 || ^0.3.0", - "@imho/log-fp-ts": "^0.2.0 || ^0.3.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/log-effect-ts/src/EffectTsToFpTsLog.ts b/packages/log-effect-ts/src/EffectTsToFpTsLog.ts deleted file mode 100644 index 7a2c0be..0000000 --- a/packages/log-effect-ts/src/EffectTsToFpTsLog.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Effect, pipe } from '@effect-ts/core' -import * as fpTs from '@imho/log-fp-ts' -import { Log } from './Log' - -export class EffectTsToFpTsLog implements fpTs.Log { - constructor(private readonly log: Log) {} - - debug(message: string, context?: object) { - return () => pipe(this.log.debug(message, context), Effect.runPromise) - } - - info(message: string, context?: object) { - return () => pipe(this.log.info(message, context), Effect.runPromise) - } - - notice(message: string, context?: object) { - return () => pipe(this.log.notice(message, context), Effect.runPromise) - } - - warning(message: string, context?: object) { - return () => pipe(this.log.warning(message, context), Effect.runPromise) - } - - error(message: string, context?: object) { - return () => pipe(this.log.error(message, context), Effect.runPromise) - } - - alert(message: string, context?: object) { - return () => pipe(this.log.alert(message, context), Effect.runPromise) - } - - critical(message: string, context?: object) { - return () => pipe(this.log.critical(message, context), Effect.runPromise) - } - - emergency(message: string, context?: object) { - return () => pipe(this.log.emergency(message, context), Effect.runPromise) - } -} diff --git a/packages/log-effect-ts/src/FpTsToEffectTsLog.ts b/packages/log-effect-ts/src/FpTsToEffectTsLog.ts deleted file mode 100644 index b500f8d..0000000 --- a/packages/log-effect-ts/src/FpTsToEffectTsLog.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Effect } from '@effect-ts/core' -import * as fpTs from '@imho/log-fp-ts' -import { Log } from './Log' - -export class FpTsToEffectTsLog implements Log { - constructor(protected readonly log: fpTs.Log) {} - - debug(message: string, context?: object) { - return Effect.promise(this.log.debug(message, context)) - } - - info(message: string, context?: object) { - return Effect.promise(this.log.info(message, context)) - } - - notice(message: string, context?: object) { - return Effect.promise(this.log.notice(message, context)) - } - - warning(message: string, context?: object) { - return Effect.promise(this.log.warning(message, context)) - } - - error(message: string, context?: object) { - return Effect.promise(this.log.error(message, context)) - } - - alert(message: string, context?: object) { - return Effect.promise(this.log.alert(message, context)) - } - - critical(message: string, context?: object) { - return Effect.promise(this.log.critical(message, context)) - } - - emergency(message: string, context?: object) { - return Effect.promise(this.log.emergency(message, context)) - } -} diff --git a/packages/log-effect-ts/src/Log.ts b/packages/log-effect-ts/src/Log.ts deleted file mode 100644 index fc6ca6a..0000000 --- a/packages/log-effect-ts/src/Log.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Effect, Has } from '@effect-ts/core' -import { EffectTs } from '@imho/effect-effect-ts' -import * as _ from '@imho/log' - -export interface Log extends EffectTs<_.Log> {} - -export const HasLog = Has.tag() - -export const Log = Effect.deriveLifted(HasLog)( - [ - 'debug', - 'info', - 'notice', - 'warning', - 'error', - 'alert', - 'critical', - 'emergency', - ], - [], - [], -) diff --git a/packages/log-effect-ts/src/VoidLog.ts b/packages/log-effect-ts/src/VoidLog.ts deleted file mode 100644 index 092fc22..0000000 --- a/packages/log-effect-ts/src/VoidLog.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as fpTs from '@imho/log-fp-ts' -import { FpTsToEffectTsLog } from './FpTsToEffectTsLog' - -export class VoidLog extends FpTsToEffectTsLog { - constructor() { - super(new fpTs.VoidLog()) - } -} diff --git a/packages/log-effect-ts/src/index.ts b/packages/log-effect-ts/src/index.ts deleted file mode 100644 index 01660f1..0000000 --- a/packages/log-effect-ts/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './EffectTsToFpTsLog' -export * from './FpTsToEffectTsLog' -export * from './Log' -export * from './VoidLog' diff --git a/packages/log-effect-ts/tsconfig.json b/packages/log-effect-ts/tsconfig.json deleted file mode 100644 index f042185..0000000 --- a/packages/log-effect-ts/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../effect-effect-ts" }, - { "path": "../log" }, - { "path": "../log-fp-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/log-fp-ts-pino/README.md b/packages/log-fp-ts-pino/README.md deleted file mode 100644 index 1c01f0f..0000000 --- a/packages/log-fp-ts-pino/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/log-fp-ts-pino - -[![npm](https://img.shields.io/npm/v/@imho/log-fp-ts-pino)](https://www.npmjs.com/package/@imho/log-fp-ts-pino) diff --git a/packages/log-fp-ts-pino/src/PinoLog.test.ts b/packages/log-fp-ts-pino/src/PinoLog.test.ts deleted file mode 100644 index ed05da5..0000000 --- a/packages/log-fp-ts-pino/src/PinoLog.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Log } from '@imho/log-fp-ts' -import { pino } from 'pino' -import { PinoLog } from './PinoLog' - -describe('PinoLog', () => { - let buffer: string | null - const log = new PinoLog( - pino( - { level: 'debug' }, - { - write(message: string) { - buffer = message - }, - }, - ), - ) - - beforeEach(() => { - buffer = null - }) - - test.each([ - ['debug', 'debug', 20], - ['info', 'info', 30], - ['notice', 'info', 30], - ['warning', 'warn', 40], - ['error', 'error', 50], - ['alert', 'fatal', 60], - ['critical', 'fatal', 60], - ['emergency', 'fatal', 60], - ] as const)( - 'hadling severity "%s" with level "%s" (%d)', - async (severity, _level, level) => { - await Log[severity]('foo')(log)() - expect(JSON.parse(buffer ?? '')).toMatchObject({ level, msg: 'foo' }) - }, - ) -}) diff --git a/packages/log-fp-ts-pino/src/PinoLog.ts b/packages/log-fp-ts-pino/src/PinoLog.ts deleted file mode 100644 index 5b5c758..0000000 --- a/packages/log-fp-ts-pino/src/PinoLog.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Log } from '@imho/log-fp-ts' -import { task } from 'fp-ts' -import pino from 'pino' - -export class PinoLog implements Log { - constructor(private readonly pino: pino.Logger) {} - - debug(message: string, context?: object | undefined) { - return this.log('debug', message, context) - } - - info(message: string, context?: object | undefined) { - return this.log('info', message, context) - } - - notice(message: string, context?: object | undefined) { - return this.log('info', message, context) - } - - warning(message: string, context?: object | undefined) { - return this.log('warn', message, context) - } - - error(message: string, context?: object | undefined) { - return this.log('error', message, context) - } - - alert(message: string, context?: object | undefined) { - return this.log('fatal', message, context) - } - - critical(message: string, context?: object | undefined) { - return this.log('fatal', message, context) - } - - emergency(message: string, context?: object | undefined) { - return this.log('fatal', message, context) - } - - private log(level: pino.Level, message: string, context?: object) { - return task.fromIO(() => this.pino[level](context, message)) - } -} diff --git a/packages/log-fp-ts-pino/src/index.ts b/packages/log-fp-ts-pino/src/index.ts deleted file mode 100644 index 515538a..0000000 --- a/packages/log-fp-ts-pino/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PinoLog' diff --git a/packages/log-fp-ts/CHANGELOG.md b/packages/log-fp-ts/CHANGELOG.md deleted file mode 100644 index c5c9d70..0000000 --- a/packages/log-fp-ts/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/log-fp-ts@0.3.0...@imho/log-fp-ts@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/log-fp-ts - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/log-fp-ts@0.2.0...@imho/log-fp-ts@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **log:** add Log module ([cd68ee2](https://github.com/xzhavilla/imho/commit/cd68ee26bdcc1fea94415683b5934b7a9c3fa95f)) diff --git a/packages/log-fp-ts/README.md b/packages/log-fp-ts/README.md deleted file mode 100644 index 8f0c59f..0000000 --- a/packages/log-fp-ts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/log-fp-ts - -[![npm](https://img.shields.io/npm/v/@imho/log-fp-ts)](https://www.npmjs.com/package/@imho/log-fp-ts) diff --git a/packages/log-fp-ts/package.json b/packages/log-fp-ts/package.json deleted file mode 100644 index a2aa165..0000000 --- a/packages/log-fp-ts/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@imho/log-fp-ts", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/effect-fp-ts": "^0.2.0 || ^0.3.0", - "@imho/log": "^0.2.0 || ^0.3.0", - "fp-ts": "^2.16.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/log-fp-ts/src/Log.ts b/packages/log-fp-ts/src/Log.ts deleted file mode 100644 index 4c215ba..0000000 --- a/packages/log-fp-ts/src/Log.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { FpTs } from '@imho/effect-fp-ts' -import * as _ from '@imho/log' -import { Severity } from '@imho/log' -import { readerTask } from 'fp-ts' -import { pipe } from 'fp-ts/function' - -export interface Log extends FpTs<_.Log> {} - -const log = (severity: Severity) => (message: string, context?: object) => - pipe( - readerTask.ask(), - readerTask.chainTaskK((log) => log[severity](message, context)), - ) - -export const Log = { - debug: log('debug'), - info: log('info'), - notice: log('notice'), - warning: log('warning'), - error: log('error'), - alert: log('alert'), - critical: log('critical'), - emergency: log('emergency'), -} diff --git a/packages/log-fp-ts/src/VoidLog.ts b/packages/log-fp-ts/src/VoidLog.ts deleted file mode 100644 index 174a625..0000000 --- a/packages/log-fp-ts/src/VoidLog.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { task } from 'fp-ts' -import { Log } from './Log' - -export class VoidLog implements Log { - debug() { - return task.of(undefined) - } - - info() { - return task.of(undefined) - } - - notice() { - return task.of(undefined) - } - - warning() { - return task.of(undefined) - } - - error() { - return task.of(undefined) - } - - alert() { - return task.of(undefined) - } - - critical() { - return task.of(undefined) - } - - emergency() { - return task.of(undefined) - } -} diff --git a/packages/log-fp-ts/src/index.ts b/packages/log-fp-ts/src/index.ts deleted file mode 100644 index 06119ce..0000000 --- a/packages/log-fp-ts/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './Log' -export * from './VoidLog' diff --git a/packages/log-fp-ts-pino/CHANGELOG.md b/packages/log-pino/CHANGELOG.md similarity index 100% rename from packages/log-fp-ts-pino/CHANGELOG.md rename to packages/log-pino/CHANGELOG.md diff --git a/packages/log-pino/README.md b/packages/log-pino/README.md new file mode 100644 index 0000000..5a415b8 --- /dev/null +++ b/packages/log-pino/README.md @@ -0,0 +1,3 @@ +# @imho/log-pino + +[![npm](https://img.shields.io/npm/v/@imho/log-pino)](https://www.npmjs.com/package/@imho/log-pino) diff --git a/packages/log-raw-pino/package.json b/packages/log-pino/package.json similarity index 69% rename from packages/log-raw-pino/package.json rename to packages/log-pino/package.json index 5546899..b7f162c 100644 --- a/packages/log-raw-pino/package.json +++ b/packages/log-pino/package.json @@ -1,5 +1,5 @@ { - "name": "@imho/log-raw-pino", + "name": "@imho/log-pino", "version": "0.3.1", "description": "", "license": "MIT", @@ -7,21 +7,18 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", "clean": "rm -rf dist *.tsbuildinfo", "prepack": "npm run build" }, - "dependencies": { - "@imho/log-fp-ts-pino": "^0.3.1" - }, "peerDependencies": { - "@imho/log-raw": "^0.2.0 || ^0.3.0", + "@imho/log": "*", + "@xzhayon/fx": "^0.2.3 || ^0.3.0 || ^0.4.0", "pino": "^8.14.1" }, "publishConfig": { diff --git a/packages/log-raw-pino/src/PinoLog.test.ts b/packages/log-pino/src/FxPinoLog.test.ts similarity index 55% rename from packages/log-raw-pino/src/PinoLog.test.ts rename to packages/log-pino/src/FxPinoLog.test.ts index b0fb999..dca171c 100644 --- a/packages/log-raw-pino/src/PinoLog.test.ts +++ b/packages/log-pino/src/FxPinoLog.test.ts @@ -1,9 +1,11 @@ +import { Log } from '@imho/log' +import { layer, perform, run } from '@xzhayon/fx' import { pino } from 'pino' -import { PinoLog } from './PinoLog' +import { FxPinoLog } from './FxPinoLog' -describe('PinoLog', () => { +describe('FxPinoLog', () => { let buffer: string | null - const log = new PinoLog( + const log = FxPinoLog( pino( { level: 'debug' }, { @@ -18,20 +20,23 @@ describe('PinoLog', () => { buffer = null }) - test.each([ + describe.each([ ['debug', 'debug', 20], ['info', 'info', 30], ['notice', 'info', 30], ['warning', 'warn', 40], ['error', 'error', 50], - ['alert', 'fatal', 60], ['critical', 'fatal', 60], + ['alert', 'fatal', 60], ['emergency', 'fatal', 60], - ] as const)( - 'hadling severity "%s" with level "%s" (%d)', - async (severity, _level, level) => { - await log[severity]('foo') + ] as const)('%s', (severity, _level, level) => { + test(`using level "${_level}" (${level})`, async () => { + function* f() { + yield* perform(Log[severity]('foo')) + } + await run(f(), layer().with(Log, log)) + expect(JSON.parse(buffer ?? '')).toMatchObject({ level, msg: 'foo' }) - }, - ) + }) + }) }) diff --git a/packages/log-pino/src/FxPinoLog.ts b/packages/log-pino/src/FxPinoLog.ts new file mode 100644 index 0000000..cdc6e84 --- /dev/null +++ b/packages/log-pino/src/FxPinoLog.ts @@ -0,0 +1,8 @@ +import { Log } from '@imho/log' +import { Handler } from '@xzhayon/fx' +import pino from 'pino' +import { PinoLog } from './PinoLog' + +export function FxPinoLog(pino: pino.Logger) { + return new PinoLog(pino) satisfies Handler +} diff --git a/packages/log-pino/src/PinoLog.ts b/packages/log-pino/src/PinoLog.ts new file mode 100644 index 0000000..60847ce --- /dev/null +++ b/packages/log-pino/src/PinoLog.ts @@ -0,0 +1,42 @@ +import { Log } from '@imho/log' +import pino from 'pino' + +export class PinoLog implements Log { + constructor(private readonly pino: pino.Logger) {} + + debug(message: string, context?: object) { + return this.log('debug', message, context) + } + + info(message: string, context?: object) { + return this.log('info', message, context) + } + + notice(message: string, context?: object) { + return this.log('info', message, context) + } + + warning(message: string, context?: object) { + return this.log('warn', message, context) + } + + error(message: string, context?: object) { + return this.log('error', message, context) + } + + critical(message: string, context?: object) { + return this.log('fatal', message, context) + } + + alert(message: string, context?: object) { + return this.log('fatal', message, context) + } + + emergency(message: string, context?: object) { + return this.log('fatal', message, context) + } + + private async log(level: pino.Level, message: string, context?: object) { + return this.pino[level](context, message) + } +} diff --git a/packages/log-pino/src/index.ts b/packages/log-pino/src/index.ts new file mode 100644 index 0000000..b857a8d --- /dev/null +++ b/packages/log-pino/src/index.ts @@ -0,0 +1,2 @@ +export * from './FxPinoLog' +export * from './PinoLog' diff --git a/packages/log-fp-ts/tsconfig.json b/packages/log-pino/tsconfig.json similarity index 59% rename from packages/log-fp-ts/tsconfig.json rename to packages/log-pino/tsconfig.json index a02c75f..2c7e9fb 100644 --- a/packages/log-fp-ts/tsconfig.json +++ b/packages/log-pino/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect-fp-ts" }, { "path": "../log" }], + "references": [{ "path": "../log" }], "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/packages/log-raw-pino/CHANGELOG.md b/packages/log-raw-pino/CHANGELOG.md deleted file mode 100644 index 990536f..0000000 --- a/packages/log-raw-pino/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/log-raw-pino@0.3.0...@imho/log-raw-pino@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/log-raw-pino - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/log-raw-pino@0.2.0...@imho/log-raw-pino@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **log:** add pino Log implementation ([28aed83](https://github.com/xzhavilla/imho/commit/28aed83120a7e6de36c15acac3672463e993a97f)) diff --git a/packages/log-raw-pino/README.md b/packages/log-raw-pino/README.md deleted file mode 100644 index 40a8910..0000000 --- a/packages/log-raw-pino/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/log-raw-pino - -[![npm](https://img.shields.io/npm/v/@imho/log-raw-pino)](https://www.npmjs.com/package/@imho/log-raw-pino) diff --git a/packages/log-raw-pino/src/PinoLog.ts b/packages/log-raw-pino/src/PinoLog.ts deleted file mode 100644 index 48bb36e..0000000 --- a/packages/log-raw-pino/src/PinoLog.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as fpTs from '@imho/log-fp-ts-pino' -import { FpTsToRawLog } from '@imho/log-raw' -import * as pino from 'pino' - -export class PinoLog extends FpTsToRawLog { - constructor(pino: pino.Logger) { - super(new fpTs.PinoLog(pino)) - } -} diff --git a/packages/log-raw-pino/src/index.ts b/packages/log-raw-pino/src/index.ts deleted file mode 100644 index 515538a..0000000 --- a/packages/log-raw-pino/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PinoLog' diff --git a/packages/log-raw-pino/tsconfig.json b/packages/log-raw-pino/tsconfig.json deleted file mode 100644 index 4e0d2e2..0000000 --- a/packages/log-raw-pino/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [{ "path": "../log-fp-ts-pino" }, { "path": "../log-raw" }], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/log-raw/CHANGELOG.md b/packages/log-raw/CHANGELOG.md deleted file mode 100644 index a3eecf2..0000000 --- a/packages/log-raw/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.3.1](https://github.com/xzhavilla/imho/compare/@imho/log-raw@0.3.0...@imho/log-raw@0.3.1) (2023-07-28) - -**Note:** Version bump only for package @imho/log-raw - - - - - -# [0.3.0](https://github.com/xzhavilla/imho/compare/@imho/log-raw@0.2.0...@imho/log-raw@0.3.0) (2023-07-22) - - -### Bug Fixes - -* add missing dependencies ([592fc9f](https://github.com/xzhavilla/imho/commit/592fc9fe916394c22211a5f2d1e7b7cc644e401c)) - - -### BREAKING CHANGES - -* new peer dependencies added - -Refs: https://stackoverflow.com/questions/54926369/what-dependency-type-should-types-be-for-a-published-package - - - - - -# 0.2.0 (2023-07-21) - - -### Features - -* **log:** add Log module ([cd68ee2](https://github.com/xzhavilla/imho/commit/cd68ee26bdcc1fea94415683b5934b7a9c3fa95f)) diff --git a/packages/log-raw/README.md b/packages/log-raw/README.md deleted file mode 100644 index 7dfde3d..0000000 --- a/packages/log-raw/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @imho/log-raw - -[![npm](https://img.shields.io/npm/v/@imho/log-raw)](https://www.npmjs.com/package/@imho/log-raw) diff --git a/packages/log-raw/package.json b/packages/log-raw/package.json deleted file mode 100644 index f1c0bc1..0000000 --- a/packages/log-raw/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "@imho/log-raw", - "version": "0.3.1", - "description": "", - "license": "MIT", - "author": "Alberto Villa ", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "!**/*.map", - "!**/*.test.*", - "/*.md", - "/dist" - ], - "scripts": { - "build": "tsc -b", - "clean": "rm -rf dist *.tsbuildinfo", - "prepack": "npm run build" - }, - "peerDependencies": { - "@imho/effect-raw": "^0.2.0 || ^0.3.0", - "@imho/log": "^0.2.0 || ^0.3.0", - "@imho/log-fp-ts": "^0.2.0 || ^0.3.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/log-raw/src/FpTsToRawLog.ts b/packages/log-raw/src/FpTsToRawLog.ts deleted file mode 100644 index ddbf7b9..0000000 --- a/packages/log-raw/src/FpTsToRawLog.ts +++ /dev/null @@ -1,38 +0,0 @@ -import * as fpTs from '@imho/log-fp-ts' -import { Log } from './Log' - -export class FpTsToRawLog implements Log { - constructor(private readonly log: fpTs.Log) {} - - debug(message: string, context?: object) { - return this.log.debug(message, context)() - } - - info(message: string, context?: object) { - return this.log.info(message, context)() - } - - notice(message: string, context?: object) { - return this.log.notice(message, context)() - } - - warning(message: string, context?: object) { - return this.log.warning(message, context)() - } - - error(message: string, context?: object) { - return this.log.error(message, context)() - } - - alert(message: string, context?: object) { - return this.log.alert(message, context)() - } - - critical(message: string, context?: object) { - return this.log.critical(message, context)() - } - - emergency(message: string, context?: object) { - return this.log.emergency(message, context)() - } -} diff --git a/packages/log-raw/src/Log.ts b/packages/log-raw/src/Log.ts deleted file mode 100644 index 7c4f91b..0000000 --- a/packages/log-raw/src/Log.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Raw } from '@imho/effect-raw' -import * as _ from '@imho/log' - -export interface Log extends Raw<_.Log> {} diff --git a/packages/log-raw/src/RawToFpTsLog.ts b/packages/log-raw/src/RawToFpTsLog.ts deleted file mode 100644 index 2329526..0000000 --- a/packages/log-raw/src/RawToFpTsLog.ts +++ /dev/null @@ -1,38 +0,0 @@ -import * as fpTs from '@imho/log-fp-ts' -import { Log } from './Log' - -export class RawToFpTsLog implements fpTs.Log { - constructor(private readonly log: Log) {} - - debug(message: string, context?: object) { - return () => this.log.debug(message, context) - } - - info(message: string, context?: object) { - return () => this.log.info(message, context) - } - - notice(message: string, context?: object) { - return () => this.log.notice(message, context) - } - - warning(message: string, context?: object) { - return () => this.log.warning(message, context) - } - - error(message: string, context?: object) { - return () => this.log.error(message, context) - } - - alert(message: string, context?: object) { - return () => this.log.alert(message, context) - } - - critical(message: string, context?: object) { - return () => this.log.critical(message, context) - } - - emergency(message: string, context?: object) { - return () => this.log.emergency(message, context) - } -} diff --git a/packages/log-raw/src/VoidLog.ts b/packages/log-raw/src/VoidLog.ts deleted file mode 100644 index 1d9466f..0000000 --- a/packages/log-raw/src/VoidLog.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as fpTs from '@imho/log-fp-ts' -import { FpTsToRawLog } from './FpTsToRawLog' - -export class VoidLog extends FpTsToRawLog { - constructor() { - super(new fpTs.VoidLog()) - } -} diff --git a/packages/log-raw/src/index.ts b/packages/log-raw/src/index.ts deleted file mode 100644 index 1d9719e..0000000 --- a/packages/log-raw/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './FpTsToRawLog' -export * from './Log' -export * from './RawToFpTsLog' -export * from './VoidLog' diff --git a/packages/log-raw/tsconfig.json b/packages/log-raw/tsconfig.json deleted file mode 100644 index 7fd150b..0000000 --- a/packages/log-raw/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.build.json", - "references": [ - { "path": "../effect-raw" }, - { "path": "../log" }, - { "path": "../log-fp-ts" } - ], - "compilerOptions": { "rootDir": "src", "outDir": "dist" } -} diff --git a/packages/log/package.json b/packages/log/package.json index 633f755..66941f3 100644 --- a/packages/log/package.json +++ b/packages/log/package.json @@ -7,10 +7,9 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "!**/*.map", - "!**/*.test.*", "/*.md", - "/dist" + "/dist", + "!**/*.test.*" ], "scripts": { "build": "tsc -b", @@ -18,7 +17,7 @@ "prepack": "npm run build" }, "peerDependencies": { - "@imho/effect": "^0.2.0" + "@xzhayon/fx": "^0.2.1 || ^0.3.0 || ^0.4.0" }, "publishConfig": { "access": "public" diff --git a/packages/log/src/Log.ts b/packages/log/src/Log.ts index c268f52..3761195 100644 --- a/packages/log/src/Log.ts +++ b/packages/log/src/Log.ts @@ -1,6 +1,22 @@ -import { Task } from '@imho/effect' +import * as fx from '@xzhayon/fx' import { Severity } from './Severity' -export type Log = { - readonly [K in Severity]: (message: string, context?: object) => Task +export type Log = { readonly [fx.URI]?: unique symbol } & { + readonly [K in Severity]: (message: string, context?: object) => Promise +} + +export const tag = fx.tag('Log') + +export const Log = { + tag, + ...fx.struct(tag)( + 'debug', + 'info', + 'notice', + 'warning', + 'error', + 'critical', + 'alert', + 'emergency', + ), } diff --git a/packages/log/src/Severity.ts b/packages/log/src/Severity.ts index 97e3c44..735b17d 100644 --- a/packages/log/src/Severity.ts +++ b/packages/log/src/Severity.ts @@ -4,6 +4,6 @@ export type Severity = | 'notice' | 'warning' | 'error' - | 'alert' | 'critical' + | 'alert' | 'emergency' diff --git a/packages/log/src/index.ts b/packages/log/src/index.ts index 157a977..266835f 100644 --- a/packages/log/src/index.ts +++ b/packages/log/src/index.ts @@ -1,2 +1,4 @@ export * from './Log' export * from './Severity' +export * from './void/FxVoidLog' +export * from './void/VoidLog' diff --git a/packages/log/src/void/FxVoidLog.ts b/packages/log/src/void/FxVoidLog.ts new file mode 100644 index 0000000..3702765 --- /dev/null +++ b/packages/log/src/void/FxVoidLog.ts @@ -0,0 +1,7 @@ +import { Handler } from '@xzhayon/fx' +import { Log } from '../Log' +import { VoidLog } from './VoidLog' + +export function FxVoidLog() { + return new VoidLog() satisfies Handler +} diff --git a/packages/log/src/void/VoidLog.ts b/packages/log/src/void/VoidLog.ts new file mode 100644 index 0000000..4d7c60f --- /dev/null +++ b/packages/log/src/void/VoidLog.ts @@ -0,0 +1,19 @@ +import { Log } from '../Log' + +export class VoidLog implements Log { + async debug() {} + + async info() {} + + async notice() {} + + async warning() {} + + async error() {} + + async critical() {} + + async alert() {} + + async emergency() {} +} diff --git a/packages/log/tsconfig.json b/packages/log/tsconfig.json index 41b3dc9..fe0dc1e 100644 --- a/packages/log/tsconfig.json +++ b/packages/log/tsconfig.json @@ -1,9 +1,4 @@ { "extends": "../../tsconfig.build.json", - "references": [{ "path": "../effect" }], - "compilerOptions": { - "rootDir": "src", - "emitDeclarationOnly": true, - "outDir": "dist" - } + "compilerOptions": { "rootDir": "src", "outDir": "dist" } } diff --git a/test/tsconfig.json b/test/tsconfig.json deleted file mode 100644 index 2f6c1db..0000000 --- a/test/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "../tsconfig.build.json", "compilerOptions": { "outDir": "dist" } } diff --git a/tsconfig.build.json b/tsconfig.build.json index e2c0100..e042168 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,7 +3,6 @@ "strict": true, "module": "commonjs", "declaration": true, - "declarationMap": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "target": "es2022",