rajt 0.0.98 → 0.0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rajt",
3
3
  "description": "A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.",
4
- "version": "0.0.98",
4
+ "version": "0.0.99",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "files": ["bin", "src"],
@@ -37,27 +37,28 @@
37
37
  "dependencies": {
38
38
  "@hono/node-server": "^1.19.9",
39
39
  "@hono/standard-validator": "^0.2.2",
40
+ "@hono/zod-validator": "^0.7.6",
40
41
  "@scalar/hono-api-reference": "^0.9.40",
41
42
  "chokidar": "^3.5.2",
42
43
  "citty": "^0.1.6",
43
44
  "consola": "^3.4.2",
44
- "cripta": "~0.1.10",
45
+ "cripta": "^0.1.10",
45
46
  "dotenv": "^16.5.0",
46
47
  "esbuild": "^0.25.2",
47
- "forj": "~0.1.8",
48
+ "forj": "^0.1.8",
48
49
  "hono": "^4.11.7",
49
- "hono-openapi": "^1.2.0",
50
+ "hono-openapi": "^1.3.0",
50
51
  "localflare-api": "^0.4.2",
51
52
  "localflare-core": "^0.4.2",
52
53
  "miniflare": "^4.20260301.1",
53
54
  "pathe": "^2.0",
54
55
  "quansync": "^0.2.11",
55
- "t0n": "~0.1.11",
56
+ "t0n": "^0.1.12",
56
57
  "tiny-glob": "^0.2",
57
58
  "tsx": "^4.19.4",
58
59
  "wrangler": "^4.61.0",
59
60
  "zod": "^4.3.6",
60
- "zod-openapi": "4"
61
+ "zod-openapi": "^5.4.6"
61
62
  },
62
63
  "devDependencies": {
63
64
  "@cloudflare/workers-types": "^4.20260113.0",
@@ -70,7 +71,8 @@
70
71
  "node": ">=18.0.0"
71
72
  },
72
73
  "resolutions": {
73
- "@smithy/types": "^4.3.0"
74
+ "@smithy/types": "^4.3.0",
75
+ "zod": "^4.3.6"
74
76
  },
75
77
  "publishConfig": {
76
78
  "registry": "https://registry.npmjs.org"
package/src/create-app.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { Hono } from 'hono'
2
2
  import { logger } from 'hono/logger'
3
3
  import { matchedRoutes } from 'hono/route'
4
- import { describeRoute } from 'hono-openapi'
5
4
  import { Envir, Datte } from 't0n'
6
5
  import type {
7
6
  Env, Context, Next,
8
7
  HTTPResponseError,
9
8
  ServerOptions,
10
9
  } from './types'
11
- import { resolve, resolveMiddleware } from './utils/resolve'
10
+ import { resolve, resolveMiddleware, mw } from './utils/resolve'
12
11
  import { getMiddlewares, getHandler } from './register'
13
12
  import request, { GET_REQUEST } from './request'
14
13
  import response from './response'
15
14
  import { isDev } from './utils/environment'
16
15
  import { gray } from 't0n/color'
16
+ import { Route } from './types'
17
17
 
18
18
  const NFHandler = () => response.notFound()
19
19
  const EHandler = async (e: Error | HTTPResponseError) => {
@@ -108,24 +108,19 @@ export const createApp = <E extends Env>(options?: ServerOptions<E>) => {
108
108
 
109
109
  if (options?.init) options.init(app)
110
110
 
111
- const routes = options?.routes || []
112
- for (const route of routes) {
111
+ const routes = options?.routes || [] // @ts-ignore
112
+ const routeRegister = options?.routeRegister ? options.routeRegister : (_: Hono, route: Route) => { // @ts0ignore
113
113
  if (Array.isArray(route)) { // @ts-ignore
114
- app[route[0]](route[1], ...mw(route[2], route[3]), ...resolve(getHandler(route[3]), route[3]))
114
+ _[route[0]](route[1], ...mw(route[2], route[3]), ...resolve(getHandler(route[3]), route[3]))
115
115
  } else { // @ts-ignore
116
- app[route.method](route.path, describeRoute(route.desc), ...mw(route.middlewares, route.name), ...resolve(route.handle, route.name))
116
+ _[route.method](route.path, ...mw(route.middlewares, route.name), ...resolve(route.handle, route.name))
117
117
  }
118
118
  }
119
119
 
120
- return app
121
- }
120
+ for (const route of routes)
121
+ routeRegister(app, route)
122
122
 
123
- function mw(...objs: string[]): Function[] {
124
- return objs.flatMap(obj => {
125
- if (typeof obj != 'string') return null
126
- // @ts-ignore
127
- return getHandler(obj)?.mw || null
128
- }).flat().filter(Boolean)
123
+ return app
129
124
  }
130
125
 
131
126
  export default createApp
package/src/dev.ts CHANGED
@@ -3,7 +3,7 @@ import { config } from 'dotenv'
3
3
  import { getRoutes, getMiddlewares, getConfigs } from './routes'
4
4
  import { registerHandler, registerMiddleware } from './register'
5
5
  import Config from './config'
6
- import { registerOpenAPI } from './oas'
6
+ import { registerOpenAPI } from './open-api/register'
7
7
  import createApp from './create-app'
8
8
  import { Ability } from 'rajt/auth'
9
9
  import { setEnv, detectEnvironment } from 'rajt/env'
@@ -1,12 +1,9 @@
1
- import { STATUS_CODES } from 'node:http'
2
1
  import { basicAuth } from 'hono/basic-auth'
3
2
  import { Scalar } from '@scalar/hono-api-reference'
4
- import { generateSpecs, resolver } from 'hono-openapi'
5
3
  import { Envir } from 't0n'
6
- import z from 'zod'
7
- import response from './response'
8
- import { getHandler } from './register'
9
- import type { Hono } from './types'
4
+ import response from '../response'
5
+ import { getHandler } from '../register'
6
+ import type { Hono } from '../types'
10
7
 
11
8
  export function config(opts: any) {
12
9
  const docs = opts?.docs ?? {}
@@ -68,38 +65,3 @@ export function registerOpenAPI(app: Hono, conf: any) {
68
65
  })
69
66
  )
70
67
  }
71
-
72
- export async function generateOpenAPI(app: Hono, conf: any) {
73
- const opts = config(conf)
74
- if (opts.disable) return {}
75
-
76
- return await generateSpecs(app, {
77
- documentation: {
78
- info: {
79
- title: opts.appName,
80
- version: opts.appVersion,
81
- description: Envir.get('APP_DESCRIPTION', ''),
82
- },
83
- components: {
84
- securitySchemes: {
85
- JWT: {
86
- type: 'http',
87
- scheme: 'bearer',
88
- bearerFormat: 'JWT',
89
- },
90
- },
91
- responses: {
92
- 500: {
93
- description: STATUS_CODES[500],
94
- content: { // @ts-ignore
95
- 'application/json': await resolver(z.object({
96
- m: z.array(z.string()),
97
- })).toOpenAPISchema(),
98
- },
99
- },
100
- ...opts?.responses,
101
- },
102
- },
103
- },
104
- })
105
- }
@@ -0,0 +1,41 @@
1
+ import { STATUS_CODES } from 'node:http'
2
+ import { generateSpecs, resolver } from 'hono-openapi'
3
+ import { array, object, string } from 'zod/mini'
4
+ import { Envir } from 't0n'
5
+ import type { Hono } from '../types'
6
+ import { config } from './register'
7
+
8
+ export async function generateOpenAPI(app: Hono, conf: any) {
9
+ const opts = config(conf)
10
+ if (opts.disable) return {}
11
+
12
+ return await generateSpecs(app, {
13
+ documentation: {
14
+ info: {
15
+ title: opts.appName,
16
+ version: opts.appVersion,
17
+ description: Envir.get('APP_DESCRIPTION', ''),
18
+ },
19
+ components: {
20
+ securitySchemes: {
21
+ JWT: {
22
+ type: 'http',
23
+ scheme: 'bearer',
24
+ bearerFormat: 'JWT',
25
+ },
26
+ },
27
+ responses: {
28
+ 500: {
29
+ description: STATUS_CODES[500],
30
+ content: { // @ts-ignore
31
+ 'application/json': await resolver(object({
32
+ m: array(string()),
33
+ })).toOpenAPISchema(),
34
+ },
35
+ },
36
+ ...opts?.responses,
37
+ },
38
+ },
39
+ },
40
+ })
41
+ }
package/src/prod.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Config from './config'
2
- import { registerOpenAPI } from './oas'
2
+ import { registerOpenAPI } from './open-api/register'
3
3
  import { Ability } from './auth'
4
4
  import createApp from './create-app'
5
5
 
package/src/routes.ts CHANGED
@@ -13,12 +13,12 @@ import versionSHA from './utils/version-sha'
13
13
  import type { Routes, StandardSchemaV1 } from './types'
14
14
  import { rn, substep, warn } from './utils/log'
15
15
  import { _root } from './utils/paths'
16
-
17
- import { generateOpenAPI } from './oas'
18
- import z from 'zod'
19
- import { resolver } from 'hono-openapi'
16
+ import { generateOpenAPI } from './open-api/spec'
17
+ import type * as z from 'zod'
18
+ import { describeRoute, resolver } from 'hono-openapi'
20
19
  import { mimes } from 'hono/utils/mime'
21
20
  import { STATUS_CODES } from 'node:http'
21
+ import { mw, resolve as _resolve } from './utils/resolve'
22
22
 
23
23
  import { highlightedMethod, highlightedURI } from './cli/utils'
24
24
 
@@ -344,7 +344,9 @@ export async function cacheRoutes() {
344
344
  middlewares.forEach(mw => registerMiddleware(mw.handle))
345
345
 
346
346
  // @ts-ignore
347
- const openApi = await generateOpenAPI(createApp({ routes }), configs?.rajt || {})
347
+ const openApi = await generateOpenAPI(createApp({ routes, routeRegister: (app: Hono, route: Route) => {
348
+ app[route.method](route.path, describeRoute(route.desc), ...mw(route.middlewares, route.name), ..._resolve(route.handle, route.name))
349
+ } }), configs?.rajt || {})
348
350
 
349
351
  const iPath = join(_root, '.rajt/imports.mjs')
350
352
  ensureDir(iPath)
package/src/types.ts CHANGED
@@ -10,7 +10,7 @@ import { mimes, type BaseMime } from 'hono/utils/mime'
10
10
  import type { OpenAPIV3_1, OpenAPIV3 } from 'openapi-types'
11
11
  import type { StandardSchemaV1 } from '@standard-schema/spec'
12
12
  import type { DescribeRouteOptions as RawDescribeRouteOptions, ResolverReturnType } from 'hono-openapi'
13
- import z from 'zod'
13
+ import type * as z from 'zod'
14
14
  import Action from './action'
15
15
  import request from './request'
16
16
  import response from './response'
@@ -1,3 +1,5 @@
1
+ import { getHandler } from '../register'
2
+
1
3
  export function resolve(obj: any, id: string) {
2
4
  if (typeof obj == 'function' && obj?.length == 2)
3
5
  return [obj]
@@ -33,3 +35,11 @@ export function resolveMiddleware(obj: any) {
33
35
 
34
36
  throw new Error('Invalid middleware provided. Must be a Hono middleware function or MiddlewareClass instance/constructor')
35
37
  }
38
+
39
+ export function mw(...objs: string[]): Function[] {
40
+ return objs.flatMap(obj => {
41
+ if (typeof obj != 'string') return null
42
+ // @ts-ignore
43
+ return getHandler(obj)?.mw || null
44
+ }).flat().filter(Boolean)
45
+ }
package/src/validator.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ZodObject } from 'zod'
2
- import { validator } from 'hono-openapi'
1
+ import type * as z from 'zod'
2
+ import { zValidator } from '@hono/zod-validator'
3
3
  import response from './response'
4
4
  import type {
5
5
  Rule, Rules,
@@ -7,11 +7,11 @@ import type {
7
7
  } from './types'
8
8
 
9
9
  export default class $Validator {
10
- private static cache = new Map<string, (schema: ZodObject<any>) => Rule>()
10
+ private static cache = new Map<string, (schema: z.ZodObject<any>) => Rule>()
11
11
 
12
12
  private static createRule<T extends keyof ValidationTargets>(
13
13
  target: T,
14
- schema: ZodObject<any>
14
+ schema: z.ZodObject<any>
15
15
  ): Rule {
16
16
  return {
17
17
  target,
@@ -24,7 +24,7 @@ export default class $Validator {
24
24
  if (this.cache.has(target))
25
25
  return this.cache.get(target)
26
26
 
27
- const fn = (schema: ZodObject<any>) => this.createRule(target, schema)
27
+ const fn = (schema: z.ZodObject<any>) => this.createRule(target, schema)
28
28
  this.cache.set(target, fn)
29
29
  return fn
30
30
  }
@@ -38,9 +38,9 @@ export default class $Validator {
38
38
 
39
39
  static parse(rules: Rules): Function[] {
40
40
  return (Array.isArray(rules) ? rules : [rules]) // @ts-ignore
41
- .flatMap(rule => validator(rule.target, rule.schema, (result, c) => {
41
+ .flatMap(rule => zValidator(rule.target, rule.schema, (result, c) => {
42
42
  if (!result.success) // @ts-ignore
43
- return response.badRequest(result.error)
43
+ return response.badRequest({ ...result.error.flatten()[rule.eTarget] })
44
44
  }))
45
45
  }
46
46
  }