-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract parsers from examples
- Loading branch information
1 parent
ca9add2
commit e2c1eb0
Showing
13 changed files
with
215 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "parsers", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@tsconfig/node20": "^20.1.4", | ||
"typescript": "^5.5.4", | ||
"typescript-eslint": "^7.18.0" | ||
}, | ||
"dependencies": { | ||
"yup": "^1.4.0", | ||
"zod": "^3.23.8" | ||
} | ||
} |
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 @@ | ||
# Parsers | ||
|
||
Shows example usage of various parsers / validation libraries |
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,59 @@ | ||
import { api, res } from '@refactorthis/funcy' | ||
import { object, string, number, date, array } from 'yup' | ||
|
||
export const GetTodoPath = object({ | ||
id: string().required(), | ||
}) | ||
|
||
export const ListQuery = object({ | ||
skip: number(), | ||
take: number(), | ||
}) | ||
|
||
export const CreateTodoRequest = object({ | ||
id: string().required(), | ||
title: string().required(), | ||
description: string().required(), | ||
due: date().required(), | ||
}) | ||
|
||
export const TodoResponse = object({ | ||
id: string(), | ||
title: string(), | ||
}) | ||
|
||
export const ListTodoResponse = object({ | ||
items: array(TodoResponse), | ||
skip: number(), | ||
take: number(), | ||
}) | ||
|
||
export const create = api({ | ||
parser: { | ||
request: CreateTodoRequest, | ||
}, | ||
handler: async ({ request }) => res.created(request), | ||
}) | ||
|
||
export const get = api({ | ||
parser: { | ||
path: GetTodoPath, | ||
response: TodoResponse, | ||
}, | ||
handler: async ({ path }) => res.ok(path), | ||
}) | ||
|
||
export const list = api({ | ||
parser: { | ||
query: ListQuery, | ||
response: ListTodoResponse, | ||
}, | ||
handler: async ({ query }) => res.ok(query), | ||
}) | ||
|
||
export const remove = api({ | ||
parser: { | ||
path: GetTodoPath, | ||
}, | ||
handler: async ({ path }) => res.ok(path), | ||
}) |
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,59 @@ | ||
import { api, res } from '@refactorthis/funcy' | ||
import z from 'zod' | ||
|
||
export const GetTodoPath = z.object({ | ||
id: z.string(), | ||
}) | ||
|
||
export const ListQuery = z.object({ | ||
skip: z.number().optional(), | ||
take: z.number().optional(), | ||
}) | ||
|
||
export const CreateTodoRequest = z.object({ | ||
id: z.string(), | ||
title: z.string(), | ||
description: z.string(), | ||
due: z.coerce.date(), | ||
}) | ||
|
||
export const TodoResponse = z.object({ | ||
id: z.string(), | ||
title: z.string(), | ||
}) | ||
|
||
export const ListTodoResponse = z.object({ | ||
items: z.array(TodoResponse), | ||
skip: z.number(), | ||
take: z.number(), | ||
}) | ||
|
||
export const create = api({ | ||
parser: { | ||
request: CreateTodoRequest, | ||
}, | ||
handler: async ({ request }) => res.created(request), | ||
}) | ||
|
||
export const get = api({ | ||
parser: { | ||
path: GetTodoPath, | ||
response: TodoResponse, | ||
}, | ||
handler: async ({ path }) => res.ok(path), | ||
}) | ||
|
||
export const list = api({ | ||
parser: { | ||
query: ListQuery, | ||
response: ListTodoResponse, | ||
}, | ||
handler: async ({ query }) => res.ok(query), | ||
}) | ||
|
||
export const remove = api({ | ||
parser: { | ||
path: GetTodoPath, | ||
}, | ||
handler: async ({ path }) => res.ok(path), | ||
}) |
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,15 @@ | ||
{ | ||
"extends": "@tsconfig/node20/tsconfig.json", | ||
"include": ["./src/*.ts"], | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"baseUrl": ".", | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": false, | ||
"allowSyntheticDefaultImports": true, | ||
"paths": { | ||
"@refactorthis/funcy": ["../../package"] | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
"vitest": "^1.5.0" | ||
}, | ||
"dependencies": { | ||
"zod": "^3.22.4", | ||
"yup": "^1.4.0" | ||
"zod": "^3.22.4" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -91,6 +91,6 @@ | |
}, | ||
"homepage": "https://github.com/refactorthis/funcy#readme", | ||
"workspaces": [ | ||
"examples/*" | ||
"examples/**/*" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 +1,2 @@ | ||
packages: | ||
- 'examples/*' | ||
- 'examples/**/*' |