Skip to content

Commit

Permalink
chore: update effect (#615)
Browse files Browse the repository at this point in the history
* chore: update effect

* test: remove custom run util in favour of @effect/vitest

* use the Logger.pretty instead of effect-log

* promote usage of @effect/vitest + use runFork instead of runPromise
  • Loading branch information
sukovanej authored Jul 13, 2024
1 parent b90ca2f commit b3e1c67
Show file tree
Hide file tree
Showing 24 changed files with 481 additions and 472 deletions.
8 changes: 8 additions & 0 deletions .changeset/tricky-comics-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"effect-http-security": patch
"effect-http-error": patch
"effect-http-node": patch
"effect-http": patch
---

Update effect.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,17 +532,16 @@ const app = RouterBuilder.make(api).pipe(
The test might look as follows.

```ts
import { it } from '@effect/vitest';
import { NodeTesting } from 'effect-http-node';

test("test /hello endpoint", async () => {
const response = await NodeTesting.make(app, api).pipe(
it.scoped("test /hello endpoint", () => Effect.gen(function* (){
const response = yield* NodeTesting.make(app, api).pipe(
Effect.flatMap((client) => client.hello({ query: { input: 12 } })),
Effect.scoped,
Effect.runPromise,
);

expect(response).toEqual("13");
});
}));
```

In comparison to the `Client` we need to run our endpoint handlers
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@
"changeset-publish": "pnpm build && changeset publish"
},
"devDependencies": {
"@babel/cli": "^7.24.7",
"@babel/core": "^7.24.7",
"@babel/cli": "^7.24.8",
"@babel/core": "^7.24.8",
"@babel/plugin-transform-export-namespace-from": "^7.24.7",
"@babel/plugin-transform-modules-commonjs": "^7.24.7",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.3",
"@effect/build-utils": "^0.7.7",
"@effect/docgen": "^0.4.3",
"@effect/dtslint": "^0.1.0",
"@effect/eslint-plugin": "^0.1.2",
"@effect/language-service": "^0.1.0",
"@effect/vitest": "^0.5.21",
"@types/node": "^20.14.9",
"@effect/vitest": "^0.6.7",
"@types/node": "^20.14.10",
"@types/swagger-ui-dist": "^3.30.5",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"@vitest/coverage-v8": "^1.6.0",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-codegen": "0.28.0",
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sort-destructure-keys": "^2.0.0",
"glob": "^10.4.2",
"glob": "^11.0.0",
"madge": "^7.0.0",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"tsx": "^4.15.8",
"typescript": "^5.5.2",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"tsx": "^4.16.2",
"typescript": "^5.5.3",
"vitest": "^1.6.0"
},
"pnpm": {
Expand Down
8 changes: 4 additions & 4 deletions packages/effect-http-error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"peerDependencies": {
"@effect/platform": "^0.58.0",
"@effect/schema": "^0.68.0",
"effect": "^3.4.0"
"effect": "^3.5.0"
},
"devDependencies": {
"@effect/platform": "^0.58.14",
"@effect/schema": "^0.68.12",
"effect": "^3.4.5"
"@effect/platform": "^0.58.27",
"@effect/schema": "^0.68.23",
"effect": "^3.5.3"
}
}
3 changes: 1 addition & 2 deletions packages/effect-http-node/examples/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from "node:fs"

import { Data, Effect, Layer, Logger, LogLevel, pipe } from "effect"
import { PrettyLogger } from "effect-log"

export class FileNotFoundError extends Data.TaggedError("FileNotFoundError")<{
filename: string
Expand All @@ -19,6 +18,6 @@ export const readFile = (filename: string) =>
)

export const debugLogger = pipe(
PrettyLogger.layer(),
Logger.pretty,
Layer.merge(Logger.minimumLogLevel(LogLevel.All))
)
5 changes: 2 additions & 3 deletions packages/effect-http-node/examples/esm-example/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Effect } from "effect"
import { Effect, Logger } from "effect"
import { NodeServer } from "effect-http-node"
import { PrettyLogger } from "effect-log"

import { NodeRuntime } from "@effect/platform-node"
import { ItemRepositoryInMemory } from "./repository.js"
import { app } from "./server.js"

const program = app.pipe(
NodeServer.listen({ port: 3000 }),
Effect.provide(PrettyLogger.layer()),
Effect.provide(Logger.pretty),
Effect.provide(ItemRepositoryInMemory)
)

Expand Down
5 changes: 2 additions & 3 deletions packages/effect-http-node/examples/handle-raw.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Headers, HttpServerResponse } from "@effect/platform"
import { NodeRuntime } from "@effect/platform-node"
import { Schema } from "@effect/schema"
import { Effect } from "effect"
import { Effect, Logger } from "effect"
import { Api, RouterBuilder } from "effect-http"
import { NodeServer } from "effect-http-node"
import { PrettyLogger } from "effect-log"

export const api = Api.make({ title: "Example API" }).pipe(
Api.addEndpoint(
Expand All @@ -28,7 +27,7 @@ export const app = RouterBuilder.make(api).pipe(

const program = app.pipe(
NodeServer.listen({ port: 3000 }),
Effect.provide(PrettyLogger.layer())
Effect.provide(Logger.pretty)
)

NodeRuntime.runMain(program)
2 changes: 1 addition & 1 deletion packages/effect-http-node/examples/headers-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Effect.all(
Effect.catchAll((e) => Effect.logInfo(`Error ${JSON.stringify(e)}`)),
Array.replicate(1000000)
)
).pipe(Effect.scoped, Effect.runPromise)
).pipe(Effect.scoped, Effect.runFork)
2 changes: 1 addition & 1 deletion packages/effect-http-node/examples/mock-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const program = pipe(
Effect.scoped
)

Effect.runPromise(program)
Effect.runFork(program)
5 changes: 2 additions & 3 deletions packages/effect-http-node/examples/plain-text.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NodeRuntime } from "@effect/platform-node"
import { Schema } from "@effect/schema"
import { Effect } from "effect"
import { Effect, Logger } from "effect"
import { Api, Representation, RouterBuilder } from "effect-http"
import { NodeServer } from "effect-http-node"
import { PrettyLogger } from "effect-log"

export const api = Api.make({ title: "Example API" }).pipe(
Api.addEndpoint(
Expand All @@ -21,6 +20,6 @@ export const app = RouterBuilder.make(api).pipe(

app.pipe(
NodeServer.listen({ port: 3000 }),
Effect.provide(PrettyLogger.layer()),
Effect.provide(Logger.pretty),
NodeRuntime.runMain
)
2 changes: 1 addition & 1 deletion packages/effect-http-node/examples/readme-quickstart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ const program = pipe(
Effect.scoped
)

Effect.runPromise(program)
Effect.runFork(program)
5 changes: 2 additions & 3 deletions packages/effect-http-node/examples/unexpected-error.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NodeRuntime } from "@effect/platform-node"
import { Schema } from "@effect/schema"
import { Data, Effect } from "effect"
import { Data, Effect, Logger } from "effect"
import { Api, RouterBuilder } from "effect-http"
import { NodeServer } from "effect-http-node"
import { PrettyLogger } from "effect-log"

export const api = Api.make({ title: "Example API" }).pipe(
Api.addEndpoint(
Expand All @@ -23,7 +22,7 @@ export const app = RouterBuilder.make(api).pipe(

const program = app.pipe(
NodeServer.listen({ port: 3000 }),
Effect.provide(PrettyLogger.layer())
Effect.provide(Logger.pretty)
)

NodeRuntime.runMain(program)
17 changes: 8 additions & 9 deletions packages/effect-http-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@
"@effect/platform": "^0.58.0",
"@effect/platform-node": "^0.53.0",
"@effect/schema": "^0.68.0",
"effect": "^3.4.0",
"effect": "^3.5.0",
"effect-http": "workspace:^"
},
"devDependencies": {
"@effect/platform": "^0.58.14",
"@effect/platform-bun": "^0.38.13",
"@effect/platform-node": "^0.53.13",
"@effect/schema": "^0.68.12",
"@types/node": "^20.14.9",
"effect": "^3.4.5",
"@effect/platform": "^0.58.27",
"@effect/platform-bun": "^0.38.26",
"@effect/platform-node": "^0.53.26",
"@effect/schema": "^0.68.23",
"@types/node": "^20.14.10",
"effect": "^3.5.3",
"effect-http": "workspace:^",
"effect-http-error": "workspace:^",
"effect-http-security": "workspace:^",
"effect-log": "^0.31.5"
"effect-http-security": "workspace:^"
}
}
2 changes: 1 addition & 1 deletion packages/effect-http-node/src/NodeTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const makeRaw: <R, E>(
*
* assert.deepStrictEqual(response.status, 200)
* assert.deepStrictEqual(yield* response.json, { hello: "world" })
* }).pipe(Effect.scoped, Effect.runPromise)
* }).pipe(Effect.scoped, Effect.runFork)
*
* @category constructors
* @since 1.0.0
Expand Down
7 changes: 3 additions & 4 deletions packages/effect-http-node/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { Cause, Deferred, Duration, Effect, Either, Exit, Fiber, Layer, Match, p
import { Api, Client, ExampleServer, RouterBuilder, Security } from "effect-http"
import { NodeSwaggerFiles, NodeTesting } from "effect-http-node"
import { createServer } from "node:http"
import { expect, test, vi } from "vitest"
import { expect, vi } from "vitest"
import { exampleApiEmptyResponse, exampleApiGetQueryParameter } from "./examples.js"
import { runTestEffect } from "./utils.js"

it.scoped(
"quickstart example e2e",
Expand Down Expand Up @@ -39,7 +38,7 @@ it.scoped(
})
)

test.each(["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"] as const)(
it.scoped.each(["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"] as const)(
"Dummy call - %s",
(method) =>
Effect.gen(function*(_) {
Expand All @@ -66,7 +65,7 @@ test.each(["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"] as const)(
)

expect(response).toEqual({ name: "milan" })
}).pipe(runTestEffect)
})
)

it.scoped(
Expand Down
5 changes: 2 additions & 3 deletions packages/effect-http-node/test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
exampleApiParams,
exampleApiPutResponse
} from "./examples.js"
import { runTestEffect } from "./utils.js"

const Service1 = Context.GenericTag<number>("@services/Service1")
const Service2 = Context.GenericTag<string>("@services/Service2")
Expand Down Expand Up @@ -92,7 +91,7 @@ it.scoped("headers", () =>
})
}))

test.each(
it.scoped.each(
[
{ response: HttpError.conflictError("error"), status: 409 }
]
Expand All @@ -115,7 +114,7 @@ test.each(

expect(result.left).toMatchObject({ status })
// TODO
}).pipe(runTestEffect))
}))

test("Attempt to add a non-existing operation should fail as a safe guard", () => {
expect(() =>
Expand Down
10 changes: 5 additions & 5 deletions packages/effect-http-node/test/swagger-router.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpClientRequest, HttpRouter } from "@effect/platform"
import { expect, it } from "@effect/vitest"
import { Array, Effect } from "effect"
import { SwaggerRouter } from "effect-http"
import { NodeTesting } from "effect-http-node"
import { expect, test } from "vitest"

const docsUrls = [
"/api/docs",
Expand All @@ -13,7 +13,7 @@ const docsUrls = [
"/api/docs/favicon-32x32.png"
]

test("swagger-router mount", () =>
it.scoped("swagger-router mount", () =>
Effect.gen(function*(_) {
const router = HttpRouter.empty.pipe(
HttpRouter.mount("/api/docs", SwaggerRouter.make({}))
Expand All @@ -31,9 +31,9 @@ test("swagger-router mount", () =>
const html = yield* _(indexResponse.text)
expect(html).includes("/api/docs/swagger-ui.css")
}
}).pipe(Effect.scoped, Effect.runPromise))
}))

test("swagger-router mountApp", () =>
it.scoped("swagger-router mountApp", () =>
Effect.gen(function*(_) {
const router = HttpRouter.empty.pipe(
HttpRouter.mountApp("/api/docs", SwaggerRouter.make({}))
Expand All @@ -51,4 +51,4 @@ test("swagger-router mountApp", () =>
const html = yield* _(indexResponse.text)
expect(html).includes("/api/docs/swagger-ui.css")
}
}).pipe(Effect.scoped, Effect.runPromise))
}))
12 changes: 0 additions & 12 deletions packages/effect-http-node/test/utils.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/effect-http-node/tsconfig.src.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{ "path": "../effect-http" },
],
"compilerOptions": {
"types": ["node"],
"tsBuildInfoFile": ".tsbuildinfo/src.tsbuildinfo",
"rootDir": "src",
"outDir": "build/src",
Expand Down
8 changes: 4 additions & 4 deletions packages/effect-http-security/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
"peerDependencies": {
"@effect/platform": "^0.58.0",
"@effect/schema": "^0.68.0",
"effect": "^3.4.0",
"effect": "^3.5.0",
"effect-http-error": "workspace:^"
},
"devDependencies": {
"@effect/platform": "^0.58.14",
"@effect/schema": "^0.68.12",
"effect": "^3.4.5",
"@effect/platform": "^0.58.27",
"@effect/schema": "^0.68.23",
"effect": "^3.5.3",
"effect-http-error": "workspace:^"
}
}
8 changes: 4 additions & 4 deletions packages/effect-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"peerDependencies": {
"@effect/platform": "^0.58.0",
"@effect/schema": "^0.68.0",
"effect": "^3.4.0"
"effect": "^3.5.0"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@effect/platform": "^0.58.14",
"@effect/schema": "^0.68.12",
"effect": "^3.4.5"
"@effect/platform": "^0.58.27",
"@effect/schema": "^0.68.23",
"effect": "^3.5.3"
}
}
Loading

0 comments on commit b3e1c67

Please sign in to comment.