Skip to content

Commit

Permalink
rm jest dependencies
Browse files Browse the repository at this point in the history
change to tsup for build

fix ci name
  • Loading branch information
pr0m3th3usEx committed Nov 5, 2024
1 parent 03a943d commit da23e9c
Show file tree
Hide file tree
Showing 11 changed files with 652 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-class-validator.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci-cabin
name: ci-class-validator
on:
push:
branches: [main]
Expand Down
11 changes: 5 additions & 6 deletions packages/auth-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface SignOutParams<R extends boolean = true> {
redirect?: R
}


export interface SessionProviderProps {
children: React.ReactNode
session?: Session | null
Expand Down Expand Up @@ -136,17 +135,17 @@ export function now() {
}

export function parseUrl(url?: string) {
const defaultUrl = 'http://localhost:3000/api/auth';
const parsedUrl = new URL(url?.startsWith('http') ? url : `https://${url}` || defaultUrl);
const defaultUrl = 'http://localhost:3000/api/auth'
const parsedUrl = new URL(url?.startsWith('http') ? url : `https://${url}` || defaultUrl)

const path = parsedUrl.pathname === '/' ? '/api/auth' : parsedUrl.pathname.replace(/\/$/, '');
const base = `${parsedUrl.origin}${path}`;
const path = parsedUrl.pathname === '/' ? '/api/auth' : parsedUrl.pathname.replace(/\/$/, '')
const base = `${parsedUrl.origin}${path}`

return {
origin: parsedUrl.origin,
host: parsedUrl.host,
path,
base,
toString: () => base,
};
}
}
4 changes: 2 additions & 2 deletions packages/class-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"test": "vitest --run",
"build": "rimraf dist && tsc",
"build": "rimraf dist && tsup ./src/index.ts --format esm,cjs --dts",
"prerelease": "yarn build && yarn test",
"release": "yarn publish"
},
Expand All @@ -34,8 +34,8 @@
},
"devDependencies": {
"hono": "^4.0.10",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"tsup": "^8.3.5",
"typescript": "^5.3.3",
"vitest": "^1.4.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/event-emitter/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Hono } from 'hono'
import type {Context} from 'hono'
import { Hono } from 'hono'
import type { Context } from 'hono'
import { describe, expect, it, vi } from 'vitest'
import { createEmitter, defineHandler, defineHandlers, emitter } from './index'
import type {Emitter} from './index' // Adjust the import path as needed
import { createEmitter, defineHandler, defineHandlers, emitter } from './index'
import type { Emitter } from './index' // Adjust the import path as needed

describe('Event Emitter Middleware', () => {
describe('createEmitter', () => {
Expand Down
27 changes: 13 additions & 14 deletions packages/node-ws/src/events.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
interface CloseEventInit extends EventInit {
code?: number;
reason?: string;
wasClean?: boolean;
code?: number
reason?: string
wasClean?: boolean
}

/**
* @link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
*/
export const CloseEvent = globalThis.CloseEvent ?? class extends Event {
export const CloseEvent =
globalThis.CloseEvent ??
class extends Event {
#eventInitDict

constructor(
type: string,
eventInitDict: CloseEventInit = {}
) {
super(type, eventInitDict)
this.#eventInitDict = eventInitDict
constructor(type: string, eventInitDict: CloseEventInit = {}) {
super(type, eventInitDict)
this.#eventInitDict = eventInitDict
}

get wasClean(): boolean {
return this.#eventInitDict.wasClean ?? false
return this.#eventInitDict.wasClean ?? false
}

get code(): number {
return this.#eventInitDict.code ?? 0
return this.#eventInitDict.code ?? 0
}

get reason(): string {
return this.#eventInitDict.reason ?? ''
return this.#eventInitDict.reason ?? ''
}
}
}
1 change: 0 additions & 1 deletion packages/node-ws/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ describe('WebSocket helper', () => {

beforeEach(async () => {
app = new Hono()

;({ injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app }))

server = await new Promise<ServerType>((resolve) => {
Expand Down
18 changes: 9 additions & 9 deletions packages/typebox-validator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ export function tbValidator<
}
return data
}

const errors = Array.from(Value.Errors(schema, data));
if (hook) {
const hookResult = hook({ success: false, errors }, c);
if (hookResult instanceof Response || hookResult instanceof Promise) {
return hookResult;
}
}

return c.json({ success: false, errors }, 400);
const errors = Array.from(Value.Errors(schema, data))
if (hook) {
const hookResult = hook({ success: false, errors }, c)
if (hookResult instanceof Response || hookResult instanceof Promise) {
return hookResult
}
}

return c.json({ success: false, errors }, 400)
})
}
88 changes: 46 additions & 42 deletions packages/typebox-validator/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type as T, TypeBoxError } from '@sinclair/typebox';
import { Type as T, TypeBoxError } from '@sinclair/typebox'
import { Hono } from 'hono'
import type { Equal, Expect } from 'hono/utils/types'
import { tbValidator } from '../src'
import { ValueError } from '@sinclair/typebox/value';
import { ValueError } from '@sinclair/typebox/value'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type ExtractSchema<T> = T extends Hono<infer _, infer S> ? S : never
Expand Down Expand Up @@ -91,35 +91,37 @@ describe('With Hook', () => {
title: T.String(),
})

app.post(
'/post',
tbValidator('json', schema, (result, c) => {
if (!result.success) {
return c.text('Invalid!', 400)
app
.post(
'/post',
tbValidator('json', schema, (result, c) => {
if (!result.success) {
return c.text('Invalid!', 400)
}
const data = result.data
return c.text(`${data.id} is valid!`)
}),
(c) => {
const data = c.req.valid('json')
return c.json({
success: true,
message: `${data.id} is ${data.title}`,
})
}
const data = result.data
return c.text(`${data.id} is valid!`)
}),
(c) => {
const data = c.req.valid('json')
return c.json({
success: true,
message: `${data.id} is ${data.title}`,
})
}
).post(
'/errorTest',
tbValidator('json', schema, (result, c) => {
return c.json(result, 400)
}),
(c) => {
const data = c.req.valid('json')
return c.json({
success: true,
message: `${data.id} is ${data.title}`,
})
}
)
)
.post(
'/errorTest',
tbValidator('json', schema, (result, c) => {
return c.json(result, 400)
}),
(c) => {
const data = c.req.valid('json')
return c.json({
success: true,
message: `${data.id} is ${data.title}`,
})
}
)

it('Should return 200 response', async () => {
const req = new Request('http://localhost/post', {
Expand Down Expand Up @@ -168,24 +170,26 @@ describe('With Hook', () => {
expect(res).not.toBeNull()
expect(res.status).toBe(400)

const {errors, success} = (await res.json()) as { success: boolean; errors: any[] }
const { errors, success } = (await res.json()) as { success: boolean; errors: any[] }
expect(success).toBe(false)
expect(Array.isArray(errors)).toBe(true)
expect(errors.map((e: ValueError) => ({
'type': e?.schema?.type,
expect(
errors.map((e: ValueError) => ({
type: e?.schema?.type,
path: e?.path,
message: e?.message
}))).toEqual([
message: e?.message,
}))
).toEqual([
{
"type": "string",
"path": "/title",
"message": "Required property"
type: 'string',
path: '/title',
message: 'Required property',
},
{
"type": "string",
"path": "/title",
"message": "Expected string"
}
type: 'string',
path: '/title',
message: 'Expected string',
},
])
})
})
8 changes: 7 additions & 1 deletion packages/valibot-validator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { Context, Env, Input as HonoInput, MiddlewareHandler, ValidationTargets } from 'hono'
import { validator } from 'hono/validator'
import type { GenericSchema, GenericSchemaAsync, InferInput, InferOutput, SafeParseResult } from 'valibot'
import type {
GenericSchema,
GenericSchemaAsync,
InferInput,
InferOutput,
SafeParseResult,
} from 'valibot'
import { safeParseAsync } from 'valibot'

type Hook<T extends GenericSchema | GenericSchemaAsync, E extends Env, P extends string> = (
Expand Down
10 changes: 5 additions & 5 deletions packages/valibot-validator/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineConfig } from "tsup";
import { defineConfig } from 'tsup'

export default defineConfig({
entryPoints: ["src/index.ts"],
format: ["cjs", "esm"],
entryPoints: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
outDir: "dist",
outDir: 'dist',
clean: true,
});
})
Loading

0 comments on commit da23e9c

Please sign in to comment.