Skip to content

Commit 8d9819b

Browse files
committed
add effect-http-redoc
1 parent 6349265 commit 8d9819b

27 files changed

+2348
-106
lines changed

.changeset/gentle-lies-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect-http-redoc": patch
3+
---
4+
5+
Initial release.

.eslintrc.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-undef */
22
module.exports = {
3+
root: true,
34
ignorePatterns: ["dist", "build", "docs", "*.md"],
45
parser: "@typescript-eslint/parser",
56
parserOptions: {
@@ -36,11 +37,14 @@ module.exports = {
3637
"object-shorthand": "error",
3738
"prefer-destructuring": "off",
3839
"sort-imports": "off",
40+
"no-restricted-syntax": ["error", {
41+
"selector": "CallExpression[callee.property.name='push'] > SpreadElement.arguments",
42+
"message": "Do not use spread arguments in Array.push"
43+
}],
3944
"no-unused-vars": "off",
4045
"prefer-rest-params": "off",
4146
"prefer-spread": "off",
4247
"import/first": "error",
43-
"import/no-cycle": "error",
4448
"import/newline-after-import": "error",
4549
"import/no-duplicates": "error",
4650
"import/no-unresolved": "off",

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"editor.defaultFormatter": "vscode.json-language-features"
99
},
1010
"[markdown]": {
11-
"editor.defaultFormatter": "esbenp.prettier-vscode"
11+
"editor.defaultFormatter": "esbenp.prettier-vscode",
12+
"prettier.semi": false,
13+
"prettier.trailingComma": "none"
1214
},
1315
"[javascript]": {
1416
"editor.defaultFormatter": "dbaeumer.vscode-eslint"

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"@effect/eslint-plugin": "^0.2.0",
3333
"@effect/language-service": "^0.1.0",
3434
"@effect/vitest": "^0.8.0",
35-
"@types/node": "^22.0.0",
35+
"@types/node": "^22.1.0",
3636
"@types/swagger-ui-dist": "^3.30.5",
37-
"@typescript-eslint/eslint-plugin": "^7.18.0",
38-
"@typescript-eslint/parser": "^7.18.0",
37+
"@typescript-eslint/eslint-plugin": "^7.16.0",
38+
"@typescript-eslint/parser": "^7.16.0",
3939
"@vitest/coverage-v8": "^2.0.5",
4040
"babel-plugin-annotate-pure-calls": "^0.4.0",
4141
"eslint": "^8.57.0",
@@ -49,7 +49,7 @@
4949
"madge": "^7.0.0",
5050
"prettier": "^3.3.3",
5151
"rimraf": "^6.0.1",
52-
"tsx": "^4.16.3",
52+
"tsx": "^4.16.5",
5353
"typescript": "^5.5.4",
5454
"vitest": "^2.0.5"
5555
},

packages/effect-http-node/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"effect-http": "workspace:^"
4040
},
4141
"devDependencies": {
42-
"@effect/platform": "^0.61.1",
43-
"@effect/platform-bun": "^0.41.1",
44-
"@effect/platform-node": "^0.56.1",
45-
"@effect/schema": "^0.70.0",
46-
"@types/node": "^22.0.0",
42+
"@effect/platform": "^0.61.2",
43+
"@effect/platform-bun": "^0.41.2",
44+
"@effect/platform-node": "^0.56.2",
45+
"@effect/schema": "^0.70.1",
46+
"@types/node": "^22.1.0",
4747
"effect": "^3.6.0",
4848
"effect-http": "workspace:^"
4949
}

packages/effect-http-redoc/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Milan Suk
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# effect-http-node
2+
3+
This is the node-specific package. Please refer to the main readme.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "node_modules/@effect/docgen/schema.json",
3+
"exclude": [
4+
"src/internal/**/*.ts"
5+
],
6+
"examplesCompilerOptions": {
7+
"noEmit": true,
8+
"strict": true,
9+
"skipLibCheck": true,
10+
"moduleResolution": "Bundler",
11+
"module": "ES2022",
12+
"target": "ES2022",
13+
"lib": [
14+
"ES2022",
15+
"DOM"
16+
],
17+
"paths": {
18+
"effect-http": [
19+
"../../../effect-http/src/index.js"
20+
],
21+
"effect-http/*": [
22+
"../../../effect-http/src/*.js"
23+
]
24+
}
25+
}
26+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { HttpRouter } from "@effect/platform"
2+
import { NodeContext, NodeRuntime } from "@effect/platform-node"
3+
import { Schema } from "@effect/schema"
4+
import { Effect, Logger, LogLevel, pipe } from "effect"
5+
import { Api, ApiGroup, ExampleServer, RouterBuilder } from "effect-http"
6+
import { NodeServer } from "effect-http-node"
7+
import { HttpRedoc } from "effect-http-redoc"
8+
9+
const Response = Schema.Struct({ name: Schema.String })
10+
11+
const testApi = pipe(
12+
ApiGroup.make("Testing", {
13+
description: "Test description",
14+
externalDocs: {
15+
description: "Test external doc",
16+
url: "https://www.google.com/search?q=effect-http"
17+
}
18+
}),
19+
ApiGroup.addEndpoint(
20+
ApiGroup.get("test", "/test").pipe(Api.setResponseBody(Response))
21+
)
22+
)
23+
24+
const userApi = pipe(
25+
ApiGroup.make("Users", {
26+
description: "All about users",
27+
externalDocs: {
28+
url: "https://www.google.com/search?q=effect-http"
29+
}
30+
}),
31+
ApiGroup.addEndpoint(
32+
ApiGroup.get("getUser", "/user").pipe(Api.setResponseBody(Response))
33+
),
34+
ApiGroup.addEndpoint(
35+
ApiGroup.post("storeUser", "/user").pipe(Api.setResponseBody(Response))
36+
),
37+
ApiGroup.addEndpoint(
38+
ApiGroup.put("updateUser", "/user").pipe(Api.setResponseBody(Response))
39+
),
40+
ApiGroup.addEndpoint(
41+
ApiGroup.delete("deleteUser", "/user").pipe(Api.setResponseBody(Response))
42+
)
43+
)
44+
45+
const categoriesApi = ApiGroup.make("Categories").pipe(
46+
ApiGroup.addEndpoint(
47+
ApiGroup.get("getCategory", "/category").pipe(Api.setResponseBody(Response))
48+
),
49+
ApiGroup.addEndpoint(
50+
ApiGroup.post("storeCategory", "/category").pipe(Api.setResponseBody(Response))
51+
),
52+
ApiGroup.addEndpoint(
53+
ApiGroup.put("updateCategory", "/category").pipe(Api.setResponseBody(Response))
54+
),
55+
ApiGroup.addEndpoint(
56+
ApiGroup.delete("deleteCategory", "/category").pipe(Api.setResponseBody(Response))
57+
)
58+
)
59+
60+
const api = Api.make().pipe(
61+
Api.addGroup(testApi),
62+
Api.addGroup(userApi),
63+
Api.addGroup(categoriesApi)
64+
)
65+
66+
ExampleServer.make(api).pipe(
67+
RouterBuilder.mapRouter(HttpRouter.mount("/redoc", HttpRedoc.make(api))),
68+
RouterBuilder.build,
69+
NodeServer.listen({ port: 3000 }),
70+
Effect.provide(Logger.pretty),
71+
Logger.withMinimumLogLevel(LogLevel.All),
72+
Effect.provide(HttpRedoc.RedocFilesLive),
73+
Effect.provide(NodeContext.layer),
74+
NodeRuntime.runMain
75+
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "effect-http-redoc",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"license": "MIT",
6+
"author": "Milan Suk <[email protected]>",
7+
"description": "Redoc router for effect-http",
8+
"homepage": "https://sukovanej.github.io/effect-http",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/sukovanej/effect-http.git"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/sukovanej/effect-http/issues"
15+
},
16+
"packageManager": "[email protected]",
17+
"publishConfig": {
18+
"access": "public",
19+
"directory": "dist"
20+
},
21+
"scripts": {
22+
"update-redoc": "curl https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js > src/static/redoc.standalone.js",
23+
"codegen": "build-utils prepare-v2",
24+
"build": "pnpm codegen && pnpm build-esm && pnpm build-cjs && pnpm build-annotate && build-utils pack-v2",
25+
"build-esm": "tsc -b tsconfig.build.json",
26+
"build-cjs": "babel build/esm --plugins @babel/transform-export-namespace-from --plugins @babel/transform-modules-commonjs --out-dir build/cjs --source-maps",
27+
"build-annotate": "babel build --plugins annotate-pure-calls --out-dir build --source-maps",
28+
"check": "tsc -b tsconfig.json",
29+
"test": "vitest",
30+
"coverage": "vitest --coverage"
31+
},
32+
"peerDependencies": {
33+
"@effect/platform": "^0.61.0",
34+
"effect": "^3.6.0",
35+
"effect-http": "workspace:^"
36+
},
37+
"devDependencies": {
38+
"@effect/platform": "^0.61.2",
39+
"@effect/platform-node": "^0.56.2",
40+
"@effect/schema": "^0.70.1",
41+
"effect": "^3.6.0",
42+
"effect-http": "workspace:^"
43+
}
44+
}

0 commit comments

Comments
 (0)