Skip to content

esecx/singlend

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

singlend

Multiple operations on a single endpoint with hono and zod ๐Ÿš€

Hoe to use

npx jsr add @evex/singlend
bunx jsr add @evex/singlend
deno add @evex/singlend
import { Hono } from "@hono/hono";
import { z } from "zod";
import { Singlend } from "@evex/singlend";

const app = new Hono();
const singlend = new Singlend();

singlend
	.group(
		z.object({
			id: z.string(),
		}),
		(query, next, error) => {
			if (!query.id.startsWith("@")) {
				return error({
					message: "Invalid id",
				});
			} else {
				return next({
					id: query.id.slice(1),
				});
			}
		},
		(singlend) =>
			singlend.on(
				"setIcon",
				z.object({
					iconUrl: z.string(),
				}),
				(query, value, ok) =>
					ok({
						message: "Set icon of " + value.id + " to " +
							query.iconUrl,
					}),
			),
	)
	.on(
		"setBackgroundColor",
		z.object({
			backgroundColor: z.string().length(7),
		}),
		(query, ok, error) => {
			if (!query.backgroundColor.startsWith("#")) {
				return error({
					message: "Invalid background color",
				});
			}

			return ok({
				message: "Set background color to " + query.backgroundColor,
			});
		},
	);

app.use("/api/singlend", singlend.middleware());

// launch server

More: https://jsr.io/@evex/singlend/doc/~/Singlend

ToDo

  • Support hc
  • Clean up dupl code

About

Multiple operations on a single endpoint with hono and zod ๐Ÿš€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%