Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
"wrangler": "^3.72.0"
},
"dependencies": {
"@hono/zod-validator": "^0.2.2",
"@hono/valibot-validator": "^0.3.0",
"hono": "^4.5.6",
"zod": "^3.23.8"
"valibot": "^0.37.0"
},
"pnpm": {
"overrides": {
Expand Down
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Env } from '..';
import { internalRouter } from './internal';
import { v8App } from './v8';
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { HTTPException } from 'hono/http-exception';
import { Hono } from 'hono/tiny';

export const app = new Hono<{ Bindings: Env }>();

Expand Down
15 changes: 5 additions & 10 deletions src/routes/internal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Env } from '..';
import { deleteOldCache } from '../crons/deleteOldCache';
import { ListResult } from '../storage';
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { vValidator } from '@hono/valibot-validator';
import { bearerAuth } from 'hono/bearer-auth';
import { z } from 'zod';
import { Hono } from 'hono/tiny';
import { object, number, optional, pipe, minValue, maxValue } from 'valibot';

export const internalRouter = new Hono<{ Bindings: Env }>();

Expand All @@ -15,7 +15,7 @@ internalRouter.use('*', async (c, next) => {

internalRouter.post(
'/delete-expired-objects',
zValidator('json', z.object({ expireInHours: z.number().optional() })),
vValidator('json', object({ expireInHours: optional(number()) })),
async (c) => {
const { expireInHours } = c.req.valid('json');
await deleteOldCache({
Expand All @@ -28,12 +28,7 @@ internalRouter.post(

internalRouter.post(
'/populate-random-objects',
zValidator(
'json',
z.object({
count: z.number().int().min(1).max(1000),
})
),
vValidator('json', object({ count: pipe(number(), maxValue(1000), minValue(1)) })),
async (c) => {
const { count } = c.req.valid('json');
const storage = c.env.STORAGE_MANAGER.getActiveStorage();
Expand Down
86 changes: 50 additions & 36 deletions src/routes/v8/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { Env } from '../..';
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { vValidator } from '@hono/valibot-validator';
import { bearerAuth } from 'hono/bearer-auth';
import { cache } from 'hono/cache';
import { z } from 'zod';
import { Hono } from 'hono/tiny';
import {
object,
number,
optional,
pipe,
minValue,
maxValue,
string,
literal,
transform,
array,
union,
} from 'valibot';

export const DEFAULT_TEAM_ID = 'team_default_team';

Expand All @@ -15,15 +27,17 @@ artifactRouter.use('*', async (c, next) => {
await middleware(c, next);
});

const vCoerceNumber = () => pipe(string(), transform(Number), number());

artifactRouter.post(
'/',
zValidator(
vValidator(
'json',
z.object({
hashes: z.array(z.string()), // artifactIds
object({
hashes: array(string()),
})
),
zValidator('query', z.object({ teamId: z.string().optional(), slug: z.string().optional() })),
vValidator('query', object({ teamId: optional(string()), slug: optional(string()) })),
(c) => {
const data = c.req.valid('json');
const { teamId: teamIdQuery, slug } = c.req.valid('query');
Expand All @@ -42,17 +56,17 @@ artifactRouter.get('/status', (c) => {

artifactRouter.put(
'/:artifactId',
zValidator('param', z.object({ artifactId: z.string() })),
zValidator('query', z.object({ teamId: z.string().optional(), slug: z.string().optional() })),
zValidator(
vValidator('param', object({ artifactId: string() })),
vValidator('query', object({ teamId: optional(string()), slug: optional(string()) })),
vValidator(
'header',
z.object({
'content-type': z.literal('application/octet-stream'),
'content-length': z.coerce.number().optional(),
'x-artifact-duration': z.coerce.number().optional(),
'x-artifact-client-ci': z.string().optional(),
'x-artifact-client-interactive': z.coerce.number().min(0).max(1).optional(),
'x-artifact-tag': z.string().optional(),
object({
'content-type': literal('application/octet-stream'),
'content-length': optional(vCoerceNumber()),
'x-artifact-duration': optional(vCoerceNumber()),
'x-artifact-client-ci': optional(string()),
'x-artifact-client-interactive': optional(pipe(vCoerceNumber(), minValue(0), maxValue(1))),
'x-artifact-tag': optional(string()),
})
),
async (c) => {
Expand Down Expand Up @@ -83,13 +97,13 @@ artifactRouter.get(
wait: false,
cacheControl: 'max-age=300, stale-while-revalidate=300',
}),
zValidator('param', z.object({ artifactId: z.string() })),
zValidator('query', z.object({ teamId: z.string().optional(), slug: z.string().optional() })),
zValidator(
vValidator('param', object({ artifactId: string() })),
vValidator('query', object({ teamId: optional(string()), slug: optional(string()) })),
vValidator(
'header',
z.object({
'x-artifact-client-ci': z.string().optional(),
'x-artifact-client-interactive': z.coerce.number().min(0).max(1).optional(),
object({
'x-artifact-client-ci': optional(string()),
'x-artifact-client-interactive': optional(pipe(vCoerceNumber(), minValue(0), maxValue(1))),
})
),
async (c) => {
Expand All @@ -116,24 +130,24 @@ artifactRouter.get(

artifactRouter.post(
'/events',
zValidator(
vValidator(
'json',
z.array(
z.object({
sessionId: z.string().uuid(),
source: z.union([z.literal('LOCAL'), z.literal('REMOTE')]),
event: z.union([z.literal('HIT'), z.literal('MISS')]),
hash: z.string(), // artifactId
duration: z.coerce.number().optional(),
array(
object({
sessionId: string(),
source: union([literal('LOCAL'), literal('REMOTE')]),
event: union([literal('HIT'), literal('MISS')]),
hash: string(),
duration: optional(number()),
})
)
),
zValidator('query', z.object({ teamId: z.string().optional(), slug: z.string().optional() })),
zValidator(
vValidator('query', object({ teamId: optional(string()), slug: optional(string()) })),
vValidator(
'header',
z.object({
'x-artifact-client-ci': z.string().optional(),
'x-artifact-client-interactive': z.coerce.number().min(0).max(1).optional(),
object({
'x-artifact-client-ci': optional(string()),
'x-artifact-client-interactive': optional(pipe(vCoerceNumber(), minValue(0), maxValue(1))),
})
),
(c) => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v8/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Env } from '../..';
import { artifactRouter } from './artifacts';
import { Hono } from 'hono';
import { Hono } from 'hono/tiny';

export const v8App = new Hono<{ Bindings: Env }>();

Expand Down