-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: β¨ turn errors into separate package & improve readme
* feat: β¨ monorepo * fix: π move to npm with lerna * fix: π move to npm * fix: π build & tests * fix: π build & tests * fix: π build & tests * chore(version): π§ π¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.0 * fix: π build * chore(version): π§ π¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.1 * fix: π test upload * chore(version): π§ π¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.2 * fix: π test upload * chore(version): π§ π¦οΈ prerelease version bump to 0.0.6-feat-split-into-multiple-packages.3 * fix: π test upload * fix: π upgrade node * fix: π package readmes * fix: π examples linting * fix: π circular dependency * fix: π test error output experiment * fix: π add examples to readme * fix: π add examples to readme * chore: π§ print ./node_modules/@zhttp * fix: π tests * fix: π tests * fix: π tests * fix: π tests * fix: π cleanup * fix: π cleanup --------- Co-authored-by: Evert De Spiegeleer <evert.despiegeleer@rightcrowd.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c13f51b
commit 5eabe6c
Showing
41 changed files
with
4,583 additions
and
2,709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn run sync:readme | ||
npm run sync:readme | ||
git add ./*.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { z } from 'zod' | ||
import { controller, get } from '@zhttp/core' | ||
|
||
export const greetingController = controller('greeting') | ||
.description('A controller that greets the world.') | ||
|
||
greetingController.endpoint( | ||
get('/hello', 'getGreeting') | ||
.description('Say hello to everyone') | ||
.input(z.object({ | ||
query: z.object({ | ||
name: z.string().optional() | ||
}) | ||
})) | ||
.response(z.object({ | ||
message: z.string() | ||
})) | ||
.handler(async ({ query }) => { | ||
return { | ||
message: `Hello ${query.name ?? 'everyone'}!` | ||
} | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { z } from 'zod' | ||
import { endpoint, get } from '@zhttp/core' | ||
|
||
const zGreetingOutput = z.object({ | ||
message: z.string() | ||
}) | ||
|
||
const zGreetingInput = z.object({ | ||
query: z.object({ | ||
name: z.string().optional() | ||
}) | ||
}) | ||
|
||
// β¬ For common http methods (get, post, put, del), utility functions are available: | ||
get('/hello', 'getGreeting') | ||
.description('Say hello to everyone') | ||
.input(zGreetingInput) | ||
.response(zGreetingOutput) | ||
.handler(async ({ query }) => { | ||
return { | ||
message: `Hello ${query.name ?? 'everyone'}!` | ||
} | ||
}) | ||
|
||
// `endpoint` is a generic function which supports every http method. | ||
endpoint('get', '/goodbye', 'getGoodbye') | ||
.description('Say goodbye to everyone') | ||
.input(zGreetingInput) | ||
.response(zGreetingOutput) | ||
.handler(async ({ query }) => { | ||
return { | ||
message: `Goodbye ${query.name ?? 'everyone'}!` | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { type Request, type Response, type NextFunction } from 'express' | ||
import { middleware, MiddlewareTypes } from '@zhttp/core' | ||
|
||
export const lastVisitMiddleware = middleware({ | ||
name: 'lastVisitMiddleware', | ||
type: MiddlewareTypes.BEFORE, | ||
handler (req: Request, res: Response, next: NextFunction) { | ||
const now = new Date() | ||
const lastVisitCookieValue = req.cookies.beenHereBefore | ||
const lastVisitTime = lastVisitCookieValue != null ? new Date(String(lastVisitCookieValue)) : undefined | ||
res.cookie('beenHereBefore', now.toISOString()) | ||
if (lastVisitTime == null) { | ||
console.log('Seems like we\'ve got a new user π') | ||
next(); return | ||
} | ||
const daysSinceLastVisit = (now.getTime() - lastVisitTime.getTime()) / (1000 * 60 * 60 * 24) | ||
console.log(`It's been ${daysSinceLastVisit} days since this user last visited.`) | ||
next() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Server } from '@zhttp/core' | ||
import { greetingController } from './concept-controller.js' | ||
import { lastVisitMiddleware } from './concept-middleware.js' | ||
|
||
const server = new Server({ | ||
controllers: [greetingController], | ||
middlewares: [lastVisitMiddleware] | ||
}, { | ||
port: 8080 | ||
}) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.