rajt 0.0.101 → 0.0.102

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.101",
4
+ "version": "0.0.102",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
7
7
  "files": ["bin", "src"],
@@ -19,11 +19,11 @@ export class Ability {
19
19
  }
20
20
 
21
21
  static fromAction(target: any): string {
22
- return !target ? '' : this.format(typeof target == 'string' ? target : (target.name.length > 3 ? target.name : (target?.p || '')))
22
+ return !target ? '' : this.format(typeof target === 'string' ? target : (target.name.length > 3 ? target.name : (target?.p || '')))
23
23
  }
24
24
 
25
25
  static format(path: string) {
26
- return path == '/'
26
+ return path === '/'
27
27
  ? 'index'
28
28
  : path.normalize('NFD')
29
29
  .replace(/[\u0300-\u036f]/g, '')
@@ -28,7 +28,7 @@ export default defineCommand({
28
28
 
29
29
  // @ts-ignore
30
30
  await build.run({ args: { platform } })
31
- const isBun = getRuntime() == 'bun'
31
+ const isBun = getRuntime() === 'bun'
32
32
 
33
33
  switch (platform) {
34
34
  case 'aws':
@@ -109,7 +109,7 @@ export default defineCommand({
109
109
 
110
110
  const started = (port: number) => {
111
111
  log(`Starting API on http://${host}:${port}`)
112
- if (platform == 'cf')
112
+ if (platform === 'cf')
113
113
  log(`Localflare on https://studio.localflare.dev`)
114
114
  rn()
115
115
  }
@@ -136,7 +136,7 @@ export default defineCommand({
136
136
  {
137
137
  stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
138
138
  // stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
139
- shell: process.platform == 'win32',
139
+ shell: process.platform === 'win32',
140
140
  env: {...process.env, DOCKER_HOST: getDockerHost()},
141
141
  }
142
142
  )
@@ -202,8 +202,8 @@ export default defineCommand({
202
202
  case 'node':
203
203
  return withPort(desiredPort, async (port) => {
204
204
  started(port)
205
- const isBun = getRuntime() == 'bun'
206
- const isWin32 = process.platform == 'win32'
205
+ const isBun = getRuntime() === 'bun'
206
+ const isWin32 = process.platform === 'win32'
207
207
  const params = isBun
208
208
  ? ['run', '--port=' + port, '--hot', '--silent', '--no-clear-screen', '--no-summary', join(_root, 'node_modules/rajt/src/dev.ts')]
209
209
  : [join(_root, 'node_modules/.bin/tsx' + (isWin32 ? '.exe' : '')), 'watch', join(_root, 'node_modules/rajt/src/dev-node.ts')]
@@ -19,13 +19,13 @@ export default defineCommand({
19
19
  },
20
20
  },
21
21
  async run({ args }) {
22
- if (args._.length != 2) {
22
+ if (args._.length !== 2) {
23
23
  error('Invalid args: '+ gray('[ACTION] [DATABASE]'))
24
24
  return rn()
25
25
  }
26
26
 
27
27
  const [action, database] = args._
28
- const isBun = getRuntime() == 'bun'
28
+ const isBun = getRuntime() === 'bun'
29
29
  const isRemote = !!args?.remote
30
30
 
31
31
  try {
@@ -46,15 +46,15 @@ export default defineCommand({
46
46
  keys.add(key)
47
47
 
48
48
  let mLength = method.length
49
- if (method == 'GET') mLength += 5
49
+ if (method === 'GET') mLength += 5
50
50
 
51
51
  maxMethodLength = Math.max(maxMethodLength, mLength)
52
52
  maxPathLength = Math.max(maxPathLength, path.length)
53
53
 
54
54
  return [
55
- isMiddleware && method != 'ALL' || !isMiddleware,
55
+ isMiddleware && method !== 'ALL' || !isMiddleware,
56
56
  opts.path ? path.startsWith(opts.path) : true,
57
- opts.method ? method == opts.method : true,
57
+ opts.method ? method === opts.method : true,
58
58
  ].every(Boolean)
59
59
  })
60
60
 
@@ -68,7 +68,7 @@ export default defineCommand({
68
68
  let mLength = method.length
69
69
  let str = highlightedMethod(method, null, true)
70
70
 
71
- if (method == 'GET')
71
+ if (method === 'GET')
72
72
  mLength += 5
73
73
 
74
74
  console.log(str + ' '.repeat(maxMethodLength - mLength) +' '+ highlightedURI(path, method))
package/src/cli/index.ts CHANGED
@@ -32,7 +32,7 @@ const version = [name, isColorSupported ? gray('v'+rajtVersion) : rajtVersion].j
32
32
  if (directly()) {
33
33
  const _args = process.argv.slice(2)
34
34
  const length = _args.length
35
- if (!length || (length == 1 && ['-v', '--version', '--v', '-version'].includes(_args[0]))) {
35
+ if (!length || (length === 1 && ['-v', '--version', '--v', '-version'].includes(_args[0]))) {
36
36
  console.log(version)
37
37
  process.exit(0)
38
38
  }
package/src/cli/stubs.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export const replace = (str: string, map: Record<string, string>) => {
2
- if (!str || typeof str != 'string' || !map || typeof map != 'object') return str
2
+ if (!str || typeof str !== 'string' || !map || typeof map !== 'object') return str
3
3
  const entries = Object.entries(map)
4
4
  const length = entries?.length || 0
5
5
  if (!length) return str
6
6
 
7
7
  str = str.trimStart()
8
- if (length == 1)
8
+ if (length === 1)
9
9
  return str.replaceAll(entries[0][0], entries[0][1])
10
10
 
11
11
  return entries.reduce(
package/src/cli/utils.ts CHANGED
@@ -44,7 +44,7 @@ export const platformError = () => error(`Provide a valid platform: ${formatArgs
44
44
 
45
45
  export function getRuntime() {
46
46
  try {
47
- return process?.isBun || typeof Bun != 'undefined' ? 'bun' : 'node'
47
+ return process?.isBun || typeof Bun !== 'undefined' ? 'bun' : 'node'
48
48
  } catch {
49
49
  return 'node'
50
50
  }
@@ -120,7 +120,7 @@ const dist = '.rajt/dist'
120
120
  export const build = async (platform: Platform, env: string = 'prd') => {
121
121
  const startTime = Date.now()
122
122
 
123
- const isCF = platform == 'cf'
123
+ const isCF = platform === 'cf'
124
124
  cleanDir(join(_root, dist))
125
125
 
126
126
  if (isCF) {
@@ -138,7 +138,7 @@ export const build = async (platform: Platform, env: string = 'prd') => {
138
138
  const encoder = new TextEncoder()
139
139
 
140
140
  // @ts-ignore
141
- platform = platform != 'node' ? '-'+ platform : ''
141
+ platform = platform !== 'node' ? '-'+ platform : ''
142
142
  const opts = {
143
143
  entryPoints: [join(_rajt, `prod${platform}.ts`)],
144
144
  bundle: true,
@@ -258,7 +258,7 @@ export function cleanDB(key: string, config?: WranglerConfig) {
258
258
  config ??= wranglerConfig()
259
259
  if (!config?.d1_databases) return
260
260
  for (const db of config.d1_databases) {
261
- if (key == db.database_name || key == db.binding) {
261
+ if (key === db.database_name || key === db.binding) {
262
262
  const ns = 'miniflare-D1DatabaseObject'
263
263
  const fileName = join(ns, durableObjectNamespace(db.preview_database_id || db.database_id || db.binding, ns) +'.sqlite')
264
264
 
@@ -463,7 +463,7 @@ export async function wait(ms: number) {
463
463
  export function getDockerHost() {
464
464
  const platform = process.platform
465
465
 
466
- if (platform == 'darwin') {
466
+ if (platform === 'darwin') {
467
467
  for (const socket of [
468
468
  '/Users/'+ process.env.USER +'/.docker/run/docker.sock',
469
469
  '/var/run/docker.sock',
@@ -476,7 +476,7 @@ export function getDockerHost() {
476
476
  return 'tcp://localhost:2375'
477
477
  }
478
478
 
479
- return process.env.DOCKER_HOST || (platform == 'win32' ? 'tcp://localhost:2375' : 'unix:///var/run/docker.sock')
479
+ return process.env.DOCKER_HOST || (platform === 'win32' ? 'tcp://localhost:2375' : 'unix:///var/run/docker.sock')
480
480
  }
481
481
 
482
482
  export function makeFile(path: string, content: string) {
package/src/create-app.ts CHANGED
@@ -21,10 +21,10 @@ const EHandler = async (e: Error | HTTPResponseError) => {
21
21
  console.error(e)
22
22
 
23
23
  switch (true) {
24
- case 'status' in e && e.status == 401:
24
+ case 'status' in e && e.status === 401:
25
25
  return response.unauthorized()
26
26
 
27
- case 'status' in e && e.status == 400: // @ts-ignore
27
+ case 'status' in e && e.status === 400: // @ts-ignore
28
28
  return response.badRequest(null, e?.message)
29
29
 
30
30
  default:
@@ -69,13 +69,13 @@ export const createApp = <E extends Env>(options?: ServerOptions<E>) => {
69
69
  if (isDev()) {
70
70
  app.use('*', async function (c: Context, next: Next) {
71
71
  const method = c.req.method
72
- const route = matchedRoutes(c).find(route => route.method == method)?.path
72
+ const route = matchedRoutes(c).find(route => route.method === method)?.path
73
73
  const logWithRoute = (args: string[]) => {
74
74
  if (!route || !args.length) return args
75
75
  return args.map(arg => {
76
76
  if (!arg) return arg
77
77
  const split = arg?.split(' ')
78
- if (split.length < 3 || split[2] == route)
78
+ if (split.length < 3 || split[2] === route)
79
79
  return arg
80
80
 
81
81
  split.splice(Math.min(3, split.length), 0, gray(route))
package/src/http.ts CHANGED
@@ -29,10 +29,10 @@ export const getVerb = [
29
29
  ]
30
30
 
31
31
  function method(method: string, ...args: any[]): void | ClassDecorator {
32
- if (args.length == 1 && typeof args[0] == 'function')
32
+ if (args.length === 1 && typeof args[0] === 'function')
33
33
  return _method(method, '/', args[0])
34
34
 
35
- const path = typeof args[0] == 'string' ? args[0] : '/'
35
+ const path = typeof args[0] === 'string' ? args[0] : '/'
36
36
  return (target: Function) => _method(method, path, target)
37
37
  }
38
38
 
@@ -117,7 +117,7 @@ export function Middlewares(...handlers: MiddlewareType[]) {
117
117
  export function Auth(target: Function): void
118
118
  export function Auth(): ClassDecorator
119
119
  export function Auth(...args: any[]): void | ClassDecorator {
120
- if (args.length == 1 && typeof args[0] == 'function')
120
+ if (args.length === 1 && typeof args[0] === 'function')
121
121
  return _auth(args[0])
122
122
 
123
123
  return (target: any) => _auth(target)
package/src/response.ts CHANGED
@@ -58,7 +58,7 @@ export default class $Response {
58
58
  headers?: HeaderRecord
59
59
  ): Response | Promise<Response> {
60
60
  const res = (html: string) => this.raw(status, html, 'text/html; charset=UTF-8' as BaseMime, headers)
61
- return typeof html == 'string'
61
+ return typeof html === 'string'
62
62
  ? res(html)
63
63
  : resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res)
64
64
  }
package/src/routes.ts CHANGED
@@ -46,7 +46,7 @@ const walk = async (dir: string, baseDir: string, fn: Function, parentMw: string
46
46
 
47
47
  if (stat.isDirectory()) {
48
48
  await walk(fullPath, baseDir, fn, currentMw)
49
- } else if (file != 'index.ts' && file.endsWith('.ts') && !file.endsWith('.d.ts')) {
49
+ } else if (file !== 'index.ts' && file.endsWith('.ts') && !file.endsWith('.d.ts')) {
50
50
  const mod = await IMPORT(fullPath)
51
51
  fn(fullPath, baseDir, mod.default, currentMw)
52
52
  }
@@ -56,18 +56,18 @@ const walk = async (dir: string, baseDir: string, fn: Function, parentMw: string
56
56
  function isZodSchema(obj: any): obj is z.ZodType {
57
57
  return (
58
58
  obj &&
59
- typeof obj == 'object' &&
59
+ typeof obj === 'object' &&
60
60
  ('_def' in obj || '_type' in obj) &&
61
61
  (obj.safeParse !== undefined || obj.parse !== undefined)
62
62
  )
63
63
  }
64
64
 
65
65
  function ResolveDescribeSchema(obj: any, deep: boolean = false) {
66
- if (!obj || typeof obj != 'object') return obj
66
+ if (!obj || typeof obj !== 'object') return obj
67
67
  if (isZodSchema(obj))
68
68
  return { content: {'application/json': { schema: resolver(obj as unknown as StandardSchemaV1) }} }
69
69
 
70
- if (obj.content && typeof obj.content == 'object') {
70
+ if (obj.content && typeof obj.content === 'object') {
71
71
  for (const mediaType in obj.content) {
72
72
  const contentItem = obj.content[mediaType]
73
73
  if (contentItem?.schema && isZodSchema(contentItem.schema))
@@ -83,7 +83,7 @@ function ResolveDescribeSchema(obj: any, deep: boolean = false) {
83
83
  }
84
84
 
85
85
  for (const key in obj) {
86
- if (obj[key] && typeof obj[key] == 'object') {
86
+ if (obj[key] && typeof obj[key] === 'object') {
87
87
  obj[key] = ResolveDescribeSchema(obj[key], true)
88
88
 
89
89
  if (!deep && !obj[key]?.description) {
@@ -137,7 +137,7 @@ export async function getRoutes(
137
137
  }
138
138
 
139
139
  const mw = (handle.mw?.length ? [...handle.mw, ...middlewares] : middlewares).flatMap(obj => {
140
- return typeof obj == 'string' ? obj : obj?.name || null
140
+ return typeof obj === 'string' ? obj : obj?.name || null
141
141
  }).filter(Boolean) as Function[]
142
142
 
143
143
  routes.push({
@@ -193,7 +193,7 @@ function extractHttpPath(file: string) {
193
193
  .map(part => part.startsWith('[') && part.endsWith(']') ? ':'+ part.slice(1, -1) : part)
194
194
  .join('/')
195
195
 
196
- return route == '/' ? '/' : route.replace(/\/$/, '')
196
+ return route === '/' ? '/' : route.replace(/\/$/, '')
197
197
  }
198
198
 
199
199
  export function sortRoutes(routes: Routes) {
@@ -212,7 +212,7 @@ export function sortRoutes(routes: Routes) {
212
212
  return metaB.score - metaA.score
213
213
  })
214
214
 
215
- while (list.length && list.at(-1)?.path == '/') {
215
+ while (list.length && list.at(-1)?.path === '/') {
216
216
  const last = list.pop()
217
217
  last && list.unshift(last)
218
218
  }
@@ -277,9 +277,9 @@ export async function getConfigs(
277
277
  const keyPath = extractName(file).split('.')
278
278
 
279
279
  keyPath.reduce((acc, key, index) => {
280
- if (index == keyPath.length - 1) {
280
+ if (index === keyPath.length - 1) {
281
281
  acc[key] = mod.default
282
- } else if (!acc[key] || typeof acc[key] != 'object') {
282
+ } else if (!acc[key] || typeof acc[key] !== 'object') {
283
283
  acc[key] = {}
284
284
  }
285
285
 
@@ -297,15 +297,15 @@ function stringifyToJS(value: unknown): string {
297
297
 
298
298
  const type = typeof value
299
299
 
300
- if (type == 'string') return JSON.stringify(value)
301
- if (type == 'number' || type == 'boolean') return String(value)
302
- if (type == 'bigint') return `${value}n`
303
- if (type == 'function') return value.toString()
300
+ if (type === 'string') return JSON.stringify(value)
301
+ if (type === 'number' || type === 'boolean') return String(value)
302
+ if (type === 'bigint') return `${value}n`
303
+ if (type === 'function') return value.toString()
304
304
 
305
305
  if (Array.isArray(value))
306
306
  return `[${value.map(stringifyToJS).join(',')}]`
307
307
 
308
- if (type == 'object') {
308
+ if (type === 'object') {
309
309
  const entries = Object.entries(value as Record<string, unknown>)
310
310
  .map(([key, val]) => `${IDENTIFIER_RE.test(key) ? key : JSON.stringify(key)}:${stringifyToJS(val)}`)
311
311
 
@@ -328,7 +328,7 @@ async function dependencyPath(lib: string) {
328
328
  export async function cacheRoutes() {
329
329
  const env = Object.entries(
330
330
  config({ path: join(_root, '.env.prod') })?.parsed || {}
331
- ).filter(([key, val]) => key?.toLowerCase().indexOf('aws') != 0) // prevent AWS credentials
331
+ ).filter(([key, val]) => key?.toLowerCase().startsWith('aws')) // prevent AWS credentials
332
332
 
333
333
  const version = versionSHA('../../.git') // @ts-ignore
334
334
  env.push(['VERSION_SHA', process.env['VERSION_SHA'] = version]) // @ts-ignore
@@ -2,7 +2,7 @@ const prd = Symbol('prd')
2
2
  const dev = Symbol('dev')
3
3
 
4
4
  // @ts-ignore
5
- let env = process.env.RAJT_ENV || prd
5
+ let env = process.env.RAJT_ENV || detectEnvironment()
6
6
 
7
7
  export const getEnv = () => env // @ts-ignore
8
8
  export const setEnv = (e: symbol) => env = e
package/src/utils/func.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export const isAsyncFn = (fn: any) => {
2
- return fn?.constructor?.name == 'AsyncFunction'
2
+ return fn?.constructor?.name === 'AsyncFunction'
3
3
  || fn.toString().toLowerCase().trim().startsWith('async')
4
4
  }
5
5
 
6
6
  export const isAnonFn = (fn: any) => {
7
- return fn?.name == '' || fn?.name == 'anonymous'
7
+ return fn?.name === '' || fn?.name === 'anonymous'
8
8
  }
package/src/utils/log.ts CHANGED
@@ -54,7 +54,7 @@ const LOGGING_METHOD = {
54
54
 
55
55
  function prefixedLog(prefixType: keyof typeof prefixes, ...msg: any[]) {
56
56
  const length = msg.length
57
- if ((msg[0] === '' || msg[0] === undefined) && length == 1)
57
+ if ((msg[0] === '' || msg[0] === undefined) && length === 1)
58
58
  msg.shift()
59
59
 
60
60
  const consoleMethod: keyof typeof LOGGING_METHOD =
@@ -64,12 +64,12 @@ function prefixedLog(prefixType: keyof typeof prefixes, ...msg: any[]) {
64
64
 
65
65
  const prefix = prefixes[prefixType]
66
66
  // If there's no message, don't print the prefix but a new line
67
- if (length == 0) {
67
+ if (length === 0) {
68
68
  console[consoleMethod]('')
69
69
  } else {
70
70
  // Ensure if there's ANSI escape codes it's concatenated into one string.
71
71
  // Chrome DevTool can only handle color if it's in one string.
72
- if (length == 1 && typeof msg[0] == 'string') {
72
+ if (length === 1 && typeof msg[0] === 'string') {
73
73
  console[consoleMethod](prefix +' '+ msg[0])
74
74
  } else {
75
75
  console[consoleMethod](prefix, ...msg)
package/src/utils/port.ts CHANGED
@@ -5,7 +5,7 @@ import { error, warn } from './log'
5
5
  export function withPort(desiredPort: number, cb: (port: number) => void, maxAttempts = 10) {
6
6
  getAvailablePort(desiredPort)
7
7
  .then(([port, pid]) => {
8
- if (port != desiredPort)
8
+ if (port !== desiredPort)
9
9
  warn(
10
10
  `Port ${desiredPort} is in use by ${pid ? 'process '+ pid : 'an unknown process'}, using available port ${port} instead`
11
11
  )
@@ -3,10 +3,10 @@ import { getHandler } from '../register'
3
3
  export function resolve(...objs: any[]) {
4
4
  const _ = []
5
5
  for (let obj of objs) {
6
- if (typeof obj == 'string')
6
+ if (typeof obj === 'string')
7
7
  obj = getHandler(obj)
8
8
 
9
- if (typeof obj == 'function' && obj?.length == 2) {
9
+ if (typeof obj === 'function' && obj?.length === 2) {
10
10
 
11
11
  } else if (obj?.run) {
12
12
  _.push(...obj.run())
@@ -34,7 +34,7 @@ export function resolve(...objs: any[]) {
34
34
  }
35
35
 
36
36
  export function resolveMiddleware(obj: any) {
37
- if (typeof obj == 'function' && obj.length == 2)
37
+ if (typeof obj === 'function' && obj.length === 2)
38
38
  return obj
39
39
 
40
40
  if (obj?.factory)