rajt 0.0.106 → 0.20260702.0
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/README.md +5 -5
- package/package.json +4 -4
- package/src/cli/commands/build.ts +1 -1
- package/src/cli/commands/deploy.ts +4 -2
- package/src/cli/commands/dev.ts +13 -5
- package/src/cli/commands/make.ts +15 -5
- package/src/cli/commands/migrate.ts +4 -2
- package/src/cli/commands/routes.ts +1 -1
- package/src/cli/index.ts +1 -1
- package/src/cli/types.ts +0 -1
- package/src/cli/utils.ts +4 -101
- package/src/dev-node.ts +1 -1
- package/src/routes.ts +7 -33
- package/src/utils/port.ts +1 -1
- package/src/utils/func.ts +0 -8
- package/src/utils/log.ts +0 -110
- package/src/utils/shutdown.ts +0 -19
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
<h1 align="left">λ Rajt<br/><a href="https://pr.new/attla/rajt"><img align="right" src="https://developer.stackblitz.com/img/start_pr_dark_small.svg" alt="Start new PR in StackBlitz Codeflow"></a><a href="https://npmjs.com/package/rajt"><img align="right" src="https://img.shields.io/npm/v/rajt.svg" alt="npm package"></a></h1>
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> ⚠️ Rajt is under ALFA development — expect updates, rough edges, and occasional breack changes.
|
|
4
|
+
<br/>
|
|
4
5
|
|
|
5
|
-
> *From Hungarian **`[ˈrɒjt]`** (meaning "start") and Russian **`Райт`** (meaning "wright").*
|
|
6
|
+
> *Runtime-Agnostic for Javascript and TypeScript*. <br />*From Hungarian **`[ˈrɒjt]`** (meaning "start") and Russian **`Райт`** (meaning "wright").*
|
|
6
7
|
|
|
7
8
|
<br/>
|
|
8
9
|
|
|
9
|
-
> ⚠️ Rajt is under ALFA development — expect updates, rough edges, and occasional breack changes.
|
|
10
|
-
<br/>
|
|
11
10
|
|
|
12
11
|
This framework is fully geared towards the serverless world, specifically AWS Lambda (Node.js, Bun and LLRT runtime) / Cloudflare Workers.
|
|
13
12
|
|
|
@@ -23,7 +22,8 @@ This framework is fully geared towards the serverless world, specifically AWS La
|
|
|
23
22
|
| -: | :- | :- |
|
|
24
23
|
| [rajt](https://github.com/attla/rajt) | [](https://npm.im/rajt) | 🧱 The core of Rajt serverless framework. |
|
|
25
24
|
| [create-rajt](https://github.com/attla/create-rajt) | [](https://npm.im/create-rajt) | 📁 CLI tool for create new Rajt projects, from starter templates. |
|
|
26
|
-
| [forj](https://github.com/attla/forj) | [](https://npm.im/forj) | 🗂️ Just another query builder in typescript |
|
|
25
|
+
| [forj](https://github.com/attla/forj) | [](https://npm.im/forj) | 🗂️ Just another query builder in typescript. |
|
|
26
|
+
| [duto](https://github.com/attla/duto) | [](https://npm.im/duto) | ⛳️ Static framework for web artisans. |
|
|
27
27
|
| [t0n](https://github.com/attla/t0n) | [](https://npm.im/t0n) | 🧰 Collection of elegant typescript resources for web artisans. |
|
|
28
28
|
| [cripta](https://github.com/attla/cripta) | [](https://npm.im/cripta) | 🧛 A layer of encryption a little too judicious. |
|
|
29
29
|
|
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
|
|
4
|
+
"version": "0.20260702.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"files": ["bin", "src"],
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"cripta": "^0.1.12",
|
|
46
46
|
"dotenv": "^16.5.0",
|
|
47
47
|
"esbuild": "^0.25.2",
|
|
48
|
-
"forj": "^0.1.
|
|
48
|
+
"forj": "^0.1.11",
|
|
49
49
|
"hono": "^4.12.8",
|
|
50
50
|
"hono-openapi": "^1.3.0",
|
|
51
51
|
"localflare-api": "^0.5.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"miniflare": "^4.20260312.0",
|
|
54
54
|
"pathe": "^2.0",
|
|
55
55
|
"quansync": "^0.2.11",
|
|
56
|
-
"t0n": "^0.
|
|
56
|
+
"t0n": "^0.20260702.0",
|
|
57
57
|
"tiny-glob": "^0.2",
|
|
58
58
|
"tsx": "^4.19.4",
|
|
59
59
|
"wrangler": "^4.61.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"bun-types": "^1.3.8",
|
|
67
67
|
"typescript": "^5.9.3"
|
|
68
68
|
},
|
|
69
|
-
"packageManager": "bun@1.3.
|
|
69
|
+
"packageManager": "bun@1.3.14",
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=18.0.0"
|
|
72
72
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
import { gray } from 't0n/color'
|
|
3
|
+
import { wait, error, rn } from 't0n/log'
|
|
3
4
|
import { build, normalizePlatform, platformError } from '../utils'
|
|
4
|
-
import { wait, error, rn } from '../../utils/log'
|
|
5
5
|
|
|
6
6
|
import { platforms } from '../constants'
|
|
7
7
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
2
|
import { defineCommand } from 'citty'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { error } from 't0n/log'
|
|
5
|
+
import { getRuntime } from 't0n/cli'
|
|
6
|
+
|
|
7
|
+
import { normalizePlatform, platformError } from '../utils'
|
|
6
8
|
import { _root } from '../../utils/paths'
|
|
7
9
|
import { platforms } from '../constants'
|
|
8
10
|
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -3,17 +3,19 @@ import { spawn, type ChildProcess } from 'node:child_process'
|
|
|
3
3
|
|
|
4
4
|
import { defineCommand } from 'citty'
|
|
5
5
|
import type { Miniflare } from 'miniflare'
|
|
6
|
-
import type
|
|
6
|
+
import { WRANGLER_CONFIG_FILES, type WranglerConfig } from 'localflare-core'
|
|
7
|
+
|
|
8
|
+
import { error, event, log, rn, warn } from 't0n/log'
|
|
9
|
+
import { getRuntime, shutdown, watch } from 't0n/cli'
|
|
10
|
+
|
|
7
11
|
import {
|
|
8
|
-
build, wait,
|
|
12
|
+
build, wait, normalizePlatform, platformError,
|
|
9
13
|
wranglerConfig, createMiniflare, localflareManifest,
|
|
10
14
|
getDockerHost,
|
|
11
15
|
findTsx
|
|
12
16
|
} from '../utils'
|
|
13
|
-
import { error, event, log, rn, warn } from '../../utils/log'
|
|
14
17
|
import { _root } from '../../utils/paths'
|
|
15
18
|
import { withPort } from '../../utils/port'
|
|
16
|
-
import shutdown from '../../utils/shutdown'
|
|
17
19
|
|
|
18
20
|
export default defineCommand({
|
|
19
21
|
meta: {
|
|
@@ -65,7 +67,13 @@ export default defineCommand({
|
|
|
65
67
|
event('Restarting..')
|
|
66
68
|
await fn()
|
|
67
69
|
// event('Restarted...')
|
|
68
|
-
}
|
|
70
|
+
}, [
|
|
71
|
+
join(_root, '{actions,features,routes,configs,enums,libs,locales,middlewares,models,utils}/**/*.ts'),
|
|
72
|
+
join(_root, '.env.dev'),
|
|
73
|
+
join(_root, '.env.prod'),
|
|
74
|
+
join(_root, 'package.json'),
|
|
75
|
+
...WRANGLER_CONFIG_FILES.map(f => join(_root, f)),
|
|
76
|
+
], _root)
|
|
69
77
|
// @ts-ignore
|
|
70
78
|
stop && shutdown(stop)
|
|
71
79
|
} catch (e: any) {
|
package/src/cli/commands/make.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
import { join, relative } from 'pathe'
|
|
3
3
|
import { Migrator } from 'forj'
|
|
4
|
-
import {
|
|
5
|
-
import { _root } from '../../utils/paths'
|
|
6
|
-
import { event, error } from '../../utils/log'
|
|
4
|
+
import { camelCase, kebabCase } from 't0n'
|
|
7
5
|
import { dim } from 't0n/color'
|
|
6
|
+
import { event, error } from 't0n/log'
|
|
7
|
+
import { makeFile, hasExt } from '../utils'
|
|
8
|
+
import { _root } from '../../utils/paths'
|
|
8
9
|
import * as stub from '../stubs'
|
|
9
10
|
|
|
10
11
|
export default defineCommand({
|
|
@@ -22,11 +23,20 @@ export default defineCommand({
|
|
|
22
23
|
if (!name)
|
|
23
24
|
return error('File name is required')
|
|
24
25
|
|
|
26
|
+
const makeFileName = (s: string) => {
|
|
27
|
+
const lastDotIndex = s.lastIndexOf('.')
|
|
28
|
+
const hasExtension = lastDotIndex > 0 && lastDotIndex < s.length - 1
|
|
29
|
+
|
|
30
|
+
return hasExtension
|
|
31
|
+
? `${kebabCase(s.substring(0, lastDotIndex))}.${s.substring(lastDotIndex + 1)}`
|
|
32
|
+
: s
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
const path = (p: string, dir: string = action) => join(_root, dir + 's', p)
|
|
26
36
|
let fileName = ''
|
|
27
37
|
switch (action) {
|
|
28
38
|
case 'config':
|
|
29
|
-
fileName = path(
|
|
39
|
+
fileName = path(makeFileName(name))
|
|
30
40
|
if (!hasExt(fileName)) fileName += '.ts'
|
|
31
41
|
makeFile(fileName, name.endsWith('.json') ? '{\n}' : 'export default {\n\n}\n')
|
|
32
42
|
break
|
|
@@ -36,7 +46,7 @@ export default defineCommand({
|
|
|
36
46
|
case 'route':
|
|
37
47
|
case 'action':
|
|
38
48
|
case 'endpoint':
|
|
39
|
-
fileName = path(
|
|
49
|
+
fileName = path(makeFileName(name))
|
|
40
50
|
if (!fileName.endsWith('.ts')) fileName += '.ts'
|
|
41
51
|
makeFile(fileName, stub.replace(stub.route, { R_NAME: camelCase(name) }))
|
|
42
52
|
break
|
|
@@ -3,9 +3,11 @@ import { spawn } from 'node:child_process'
|
|
|
3
3
|
import { join } from 'pathe'
|
|
4
4
|
import { Migrator } from 'forj'
|
|
5
5
|
import { gray } from 't0n/color'
|
|
6
|
-
import { getRuntime
|
|
6
|
+
import { getRuntime } from 't0n/cli'
|
|
7
|
+
import { wait, info, event, rn, error, log } from 't0n/log'
|
|
8
|
+
|
|
9
|
+
import { cleanDB, cleanDir } from '../utils'
|
|
7
10
|
import { _root } from '../../utils/paths'
|
|
8
|
-
import { wait, info, event, rn, error, log } from '../../utils/log'
|
|
9
11
|
|
|
10
12
|
export default defineCommand({
|
|
11
13
|
meta: {
|
|
@@ -2,8 +2,8 @@ import { join } from 'pathe'
|
|
|
2
2
|
import { defineCommand } from 'citty'
|
|
3
3
|
import { inspectRoutes } from 'hono/dev'
|
|
4
4
|
import { IMPORT } from 't0n'
|
|
5
|
+
import { rn } from 't0n/log'
|
|
5
6
|
import { _rajt } from '../../utils/paths'
|
|
6
|
-
import { rn } from '../../utils/log'
|
|
7
7
|
import { highlightedURI, highlightedMethod } from '../utils'
|
|
8
8
|
|
|
9
9
|
export default defineCommand({
|
package/src/cli/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineCommand, runMain, renderUsage } from 'citty'
|
|
2
2
|
import type { ArgsDef, CommandDef } from 'citty'
|
|
3
3
|
import { createConsola } from 'consola'
|
|
4
|
-
import { logo } from '
|
|
4
|
+
import { logo } from 't0n/log'
|
|
5
5
|
import { isColorSupported, gray } from 't0n/color'
|
|
6
6
|
import { version as rajtVersion } from '../../package.json'
|
|
7
7
|
|
package/src/cli/types.ts
CHANGED
package/src/cli/utils.ts
CHANGED
|
@@ -3,21 +3,21 @@ import esbuild from 'esbuild'
|
|
|
3
3
|
import { Miniflare } from 'miniflare'
|
|
4
4
|
import { mkdirSync, existsSync, statSync, readdirSync, rmSync, unlinkSync, copyFileSync, writeFileSync } from 'node:fs'
|
|
5
5
|
import { readFile, stat, writeFile } from 'node:fs/promises'
|
|
6
|
-
import { basename, dirname, join
|
|
6
|
+
import { basename, dirname, join } from 'pathe'
|
|
7
7
|
import { createHash, createHmac } from 'node:crypto'
|
|
8
8
|
|
|
9
9
|
import { findWranglerConfig, parseWranglerConfig, WRANGLER_CONFIG_FILES } from 'localflare-core'
|
|
10
10
|
import type { WranglerConfig, LocalflareManifest } from 'localflare-core'
|
|
11
11
|
|
|
12
|
-
import chokidar from 'chokidar'
|
|
13
12
|
import { gray, bold, italic, purple, yellow, red } from 't0n/color'
|
|
14
|
-
import
|
|
13
|
+
import { substep, event, error, warn } from 't0n/log'
|
|
15
14
|
|
|
16
15
|
import { cacheRoutes } from '../routes'
|
|
17
|
-
import { substep, event, error, wait as wwait, warn, log } from '../utils/log'
|
|
18
16
|
import { platforms } from './constants'
|
|
19
17
|
import { _rajt, _root } from '../utils/paths'
|
|
20
18
|
|
|
19
|
+
import type { Platform } from './types'
|
|
20
|
+
|
|
21
21
|
export function normalizePlatform(platform: Platform) {
|
|
22
22
|
platform = platform?.toLowerCase() as Platform
|
|
23
23
|
if (!platforms?.includes(platform)) return null
|
|
@@ -42,14 +42,6 @@ export function normalizePlatform(platform: Platform) {
|
|
|
42
42
|
const formatArgs = (...args: any[]) => args.flat().map(a => gray(italic(bold(a)))).join(', ')
|
|
43
43
|
export const platformError = () => error(`Provide a valid platform: ${formatArgs(platforms)}.\n`)
|
|
44
44
|
|
|
45
|
-
export function getRuntime() {
|
|
46
|
-
try {
|
|
47
|
-
return process?.isBun || typeof Bun !== 'undefined' ? 'bun' : 'node'
|
|
48
|
-
} catch {
|
|
49
|
-
return 'node'
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
45
|
export const formatSize = (bytes: number) => {
|
|
54
46
|
if (bytes < 1024) return `${bytes}b`
|
|
55
47
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)}kb`
|
|
@@ -398,64 +390,6 @@ export function createMiniflare(opts = {}) {
|
|
|
398
390
|
})
|
|
399
391
|
}
|
|
400
392
|
|
|
401
|
-
function getAssetChangeMessage(
|
|
402
|
-
e: ChokidarEventName,
|
|
403
|
-
path: string
|
|
404
|
-
): string {
|
|
405
|
-
path = relative(_root, path)
|
|
406
|
-
switch (e) {
|
|
407
|
-
case 'add':
|
|
408
|
-
return `File ${path} was added`
|
|
409
|
-
case 'addDir':
|
|
410
|
-
return `Directory ${path} was added`
|
|
411
|
-
case 'unlink':
|
|
412
|
-
return `File ${path} was removed`
|
|
413
|
-
case 'unlinkDir':
|
|
414
|
-
return `Directory ${path} was removed`
|
|
415
|
-
case 'change':
|
|
416
|
-
default:
|
|
417
|
-
return `${path} changed`
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export async function watch(cb: (e: ChokidarEventName | string, file: string) => Promise<void>) {
|
|
422
|
-
const codeWatcher = chokidar.watch([
|
|
423
|
-
join(_root, '{actions,features,routes,configs,enums,libs,locales,middlewares,models,utils}/**/*.ts'),
|
|
424
|
-
join(_root, '.env.dev'),
|
|
425
|
-
join(_root, '.env.prod'),
|
|
426
|
-
join(_root, 'package.json'),
|
|
427
|
-
...WRANGLER_CONFIG_FILES.map(f => join(_root, f)),
|
|
428
|
-
], {
|
|
429
|
-
ignored: /(^|[/\\])\../, // ignore hidden files
|
|
430
|
-
persistent: true,
|
|
431
|
-
ignoreInitial: true,
|
|
432
|
-
awaitWriteFinish: {
|
|
433
|
-
stabilityThreshold: 200,
|
|
434
|
-
pollInterval: 100,
|
|
435
|
-
},
|
|
436
|
-
})
|
|
437
|
-
let restartTimeout: NodeJS.Timeout | null = null
|
|
438
|
-
|
|
439
|
-
const watcher = (e: ChokidarEventName) => async (file: string) => {
|
|
440
|
-
log(getAssetChangeMessage(e, file))
|
|
441
|
-
|
|
442
|
-
if (restartTimeout)
|
|
443
|
-
clearTimeout(restartTimeout)
|
|
444
|
-
|
|
445
|
-
restartTimeout = setTimeout(async () => {
|
|
446
|
-
await cb(e, file)
|
|
447
|
-
}, 300)
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
codeWatcher.on('change', watcher('change'))
|
|
451
|
-
codeWatcher.on('add', watcher('add'))
|
|
452
|
-
codeWatcher.on('unlink', watcher('unlink'))
|
|
453
|
-
codeWatcher.on('addDir', watcher('addDir'))
|
|
454
|
-
codeWatcher.on('unlinkDir', watcher('unlinkDir'))
|
|
455
|
-
|
|
456
|
-
wwait('Watching for file changes')
|
|
457
|
-
}
|
|
458
|
-
|
|
459
393
|
export async function wait(ms: number) {
|
|
460
394
|
return new Promise(r => setTimeout(r, ms))
|
|
461
395
|
}
|
|
@@ -491,37 +425,6 @@ export function hasExt(path: string) {
|
|
|
491
425
|
return index > 0 && index < path.length - 1
|
|
492
426
|
}
|
|
493
427
|
|
|
494
|
-
function normalizeText(text: string, separator = '_') {
|
|
495
|
-
const validSeparators = ['_', '-']
|
|
496
|
-
const sep = validSeparators.includes(separator) ? separator : '_'
|
|
497
|
-
|
|
498
|
-
const lastDotIndex = text.lastIndexOf('.')
|
|
499
|
-
const hasExtension = lastDotIndex > 0 && lastDotIndex < text.length - 1
|
|
500
|
-
const fileName = hasExtension ? text.substring(0, lastDotIndex) : text
|
|
501
|
-
const extension = hasExtension ? text.substring(lastDotIndex + 1) : ''
|
|
502
|
-
|
|
503
|
-
const normalizedName = fileName
|
|
504
|
-
.replace(/([a-z])([A-Z])/g, `$1${sep}$2`)
|
|
505
|
-
.replace(/[\s\-_]+/g, sep)
|
|
506
|
-
.toLowerCase()
|
|
507
|
-
.replace(new RegExp(`[^\\w${sep}]+`, 'g'), '')
|
|
508
|
-
.replace(new RegExp(`${sep}{2,}`, 'g'), sep)
|
|
509
|
-
.replace(new RegExp(`^${sep}+|${sep}+$`, 'g'), '')
|
|
510
|
-
|
|
511
|
-
return hasExtension ? `${normalizedName}.${extension}` : normalizedName
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
export const snakeCase = (text: string) => normalizeText(text, '_')
|
|
515
|
-
export const kebabCase = (text: string) => normalizeText(text, '-')
|
|
516
|
-
|
|
517
|
-
export const camelCase = (text: string) =>
|
|
518
|
-
text.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
519
|
-
.trim()
|
|
520
|
-
.split(/\s+/)
|
|
521
|
-
.filter(word => word.length > 0)
|
|
522
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
523
|
-
.join('')
|
|
524
|
-
|
|
525
428
|
export const highlightedMethod = (method: string, str?: string | null, siblings: boolean = false): string => {
|
|
526
429
|
const val = str || method
|
|
527
430
|
|
package/src/dev-node.ts
CHANGED
package/src/routes.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { copyFileSync, existsSync, readdirSync, statSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { join, resolve, relative } from 'pathe'
|
|
3
3
|
|
|
4
|
-
import { IMPORT } from 't0n'
|
|
4
|
+
import { IMPORT, JSJSON } from 't0n'
|
|
5
|
+
import { rn, substep, warn } from 't0n/log'
|
|
5
6
|
import glob from 'tiny-glob'
|
|
6
7
|
import { config } from 'dotenv'
|
|
7
8
|
import { describeRoute, resolver, validator } from 'hono-openapi'
|
|
@@ -11,10 +12,8 @@ import { registerHandler, registerMiddleware } from './register'
|
|
|
11
12
|
import createApp from './create-app'
|
|
12
13
|
import _response from './response'
|
|
13
14
|
import _validator from './validator'
|
|
14
|
-
import { isAnonFn } from './utils/func'
|
|
15
15
|
import ensureDir from './utils/ensuredir'
|
|
16
16
|
import versionSHA from './utils/version-sha'
|
|
17
|
-
import { rn, substep, warn } from './utils/log'
|
|
18
17
|
import { _root, _rajt } from './utils/paths'
|
|
19
18
|
import { generateOpenAPI } from './open-api/spec'
|
|
20
19
|
import { verbAlias } from './http'
|
|
@@ -36,7 +35,7 @@ const walk = async (dir: string, baseDir: string, fn: Function, parentMw: string
|
|
|
36
35
|
const mod = await IMPORT(indexFile)
|
|
37
36
|
const group = mod.default
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
group?.name && group.name !== 'anonymous' && group?.mw?.length && currentMw.push(group.name)
|
|
40
39
|
fn(indexFile, baseDir, group, currentMw)
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -290,31 +289,6 @@ export async function getConfigs(
|
|
|
290
289
|
return configs
|
|
291
290
|
}
|
|
292
291
|
|
|
293
|
-
const IDENTIFIER_RE = /^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u
|
|
294
|
-
function stringifyToJS(value: unknown): string {
|
|
295
|
-
if (value === null) return 'null'
|
|
296
|
-
if (value === undefined) return 'undefined'
|
|
297
|
-
|
|
298
|
-
const type = typeof value
|
|
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()
|
|
304
|
-
|
|
305
|
-
if (Array.isArray(value))
|
|
306
|
-
return `[${value.map(stringifyToJS).join(',')}]`
|
|
307
|
-
|
|
308
|
-
if (type === 'object') {
|
|
309
|
-
const entries = Object.entries(value as Record<string, unknown>)
|
|
310
|
-
.map(([key, val]) => `${IDENTIFIER_RE.test(key) ? key : JSON.stringify(key)}:${stringifyToJS(val)}`)
|
|
311
|
-
|
|
312
|
-
return `{${entries.join(',')}}`
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return 'undefined'
|
|
316
|
-
}
|
|
317
|
-
|
|
318
292
|
export async function dependencyEntry(lib: string, root: string) {
|
|
319
293
|
const path = await import.meta.resolve(lib)
|
|
320
294
|
return relative(root, path.replace('file://', ''))
|
|
@@ -377,16 +351,16 @@ export async function cacheRoutes() {
|
|
|
377
351
|
|
|
378
352
|
const _rajtDir = await dependencyPath('rajt')
|
|
379
353
|
|
|
380
|
-
|
|
354
|
+
JSJSON(Object.fromEntries(routes.map(r => ([r.path + r.method, r.name]))))
|
|
381
355
|
|
|
382
356
|
writeFileSync(iPath, `// AUTO-GENERATED FILE - DO NOT EDIT
|
|
383
|
-
${env?.length ? `import { Envir } from '${await dependencyPath('t0n')}/src/envir'\nEnvir.add({${env.map(([key, val]) => key +':'+
|
|
384
|
-
${Object.entries(configs)?.length ? `import Config from '${_rajtDir}/src/config'\nConfig.add(${
|
|
357
|
+
${env?.length ? `import { Envir } from '${await dependencyPath('t0n')}/src/envir'\nEnvir.add({${env.map(([key, val]) => key +':'+ JSJSON(val)).join(',')}})` : ''}
|
|
358
|
+
${Object.entries(configs)?.length ? `import Config from '${_rajtDir}/src/config'\nConfig.add(${JSJSON})` : ''}
|
|
385
359
|
|
|
386
360
|
import { registerHandler, registerMiddleware } from '${_rajtDir}/src/register'
|
|
387
361
|
${handlers.map(([file, name, _export]) => `\nimport ${_export ? `{ ${name} }` : name} from '${_rajtDir}/src/${file}'\nregisterHandler('${name}', ${name})`).join('\n')}
|
|
388
362
|
|
|
389
|
-
${Object.entries(openApi)?.length ? `registerHandler('RAJT_OPENAPI', ${
|
|
363
|
+
${Object.entries(openApi)?.length ? `registerHandler('RAJT_OPENAPI', ${JSJSON(openApi)})` : ''}
|
|
390
364
|
|
|
391
365
|
${routes.map(r => `import ${r.name} from '../${normalizeImportPath(r.file)}'`).join('\n')}
|
|
392
366
|
${middlewares.map(r => `import ${r.name} from '../${normalizeImportPath(r.file)}'`).join('\n')}
|
package/src/utils/port.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import net from 'node:net'
|
|
2
2
|
import { exec } from 'node:child_process'
|
|
3
|
-
import { error, warn } from '
|
|
3
|
+
import { error, warn } from 't0n/log'
|
|
4
4
|
|
|
5
5
|
export function withPort(desiredPort: number, cb: (port: number) => void, maxAttempts = 10) {
|
|
6
6
|
getAvailablePort(desiredPort)
|
package/src/utils/func.ts
DELETED
package/src/utils/log.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { blue, bold, gray, green, magenta, red, yellow, white } from 't0n/color'
|
|
2
|
-
|
|
3
|
-
const _step = (color: Function, ...msg: any[]) => {
|
|
4
|
-
const length = msg.length
|
|
5
|
-
if (!length) return
|
|
6
|
-
if (length < 2)
|
|
7
|
-
return console.log(color('⁕') +' '+ msg[0])
|
|
8
|
-
|
|
9
|
-
const total = length - 1
|
|
10
|
-
for (let i: number = 0; i < length; i++) {
|
|
11
|
-
switch (i) {
|
|
12
|
-
case 0:
|
|
13
|
-
console.log(color('⁕') + ' ' + msg[i])
|
|
14
|
-
continue
|
|
15
|
-
case total:
|
|
16
|
-
console.log(` ${gray('⁕')} ${msg[i]}\t`)
|
|
17
|
-
continue
|
|
18
|
-
default:
|
|
19
|
-
console.log(` ${gray('⁕')} ` + msg[i])
|
|
20
|
-
continue
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const step = (...msg: any[]) => _step(blue, ...msg)
|
|
26
|
-
export const stepWarn = (...msg: any[]) => _step(yellow, ...msg)
|
|
27
|
-
|
|
28
|
-
export const substep = (...msg: any[]) => {
|
|
29
|
-
const length = msg.length
|
|
30
|
-
for (let i: number = 0; i < length; i++)
|
|
31
|
-
console.log(` ${gray('⁕')} ` + msg[i])
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const ln = () => console.log('\n')
|
|
35
|
-
export const rn = () => console.log('\t')
|
|
36
|
-
|
|
37
|
-
export const logo = gray(bold('λ'))
|
|
38
|
-
export const prefixes = {
|
|
39
|
-
wait: white(bold('○')),
|
|
40
|
-
error: red(bold('⨯')),
|
|
41
|
-
warn: yellow(bold('⚠')),
|
|
42
|
-
ready: logo,
|
|
43
|
-
info: white(bold(' ')),
|
|
44
|
-
event: green(bold('✓')),
|
|
45
|
-
trace: magenta(bold('»')),
|
|
46
|
-
log: gray(bold('⁕')),
|
|
47
|
-
} as const
|
|
48
|
-
|
|
49
|
-
const LOGGING_METHOD = {
|
|
50
|
-
log: 'log',
|
|
51
|
-
warn: 'warn',
|
|
52
|
-
error: 'error',
|
|
53
|
-
} as const
|
|
54
|
-
|
|
55
|
-
function prefixedLog(prefixType: keyof typeof prefixes, ...msg: any[]) {
|
|
56
|
-
const length = msg.length
|
|
57
|
-
if ((msg[0] === '' || msg[0] === undefined) && length === 1)
|
|
58
|
-
msg.shift()
|
|
59
|
-
|
|
60
|
-
const consoleMethod: keyof typeof LOGGING_METHOD =
|
|
61
|
-
prefixType in LOGGING_METHOD
|
|
62
|
-
? LOGGING_METHOD[prefixType as keyof typeof LOGGING_METHOD]
|
|
63
|
-
: 'log'
|
|
64
|
-
|
|
65
|
-
const prefix = prefixes[prefixType]
|
|
66
|
-
// If there's no message, don't print the prefix but a new line
|
|
67
|
-
if (length === 0) {
|
|
68
|
-
console[consoleMethod]('')
|
|
69
|
-
} else {
|
|
70
|
-
// Ensure if there's ANSI escape codes it's concatenated into one string.
|
|
71
|
-
// Chrome DevTool can only handle color if it's in one string.
|
|
72
|
-
if (length === 1 && typeof msg[0] === 'string') {
|
|
73
|
-
console[consoleMethod](prefix +' '+ msg[0])
|
|
74
|
-
} else {
|
|
75
|
-
console[consoleMethod](prefix, ...msg)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function log(...msg: any[]) {
|
|
81
|
-
prefixedLog('log', ...msg)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function wait(...msg: any[]) {
|
|
85
|
-
prefixedLog('wait', ...msg)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function error(...msg: any[]) {
|
|
89
|
-
prefixedLog('error', ...msg)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function warn(...msg: any[]) {
|
|
93
|
-
prefixedLog('warn', ...msg)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function ready(...msg: any[]) {
|
|
97
|
-
prefixedLog('ready', ...msg)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function info(...msg: any[]) {
|
|
101
|
-
prefixedLog('info', ...msg)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function event(...msg: any[]) {
|
|
105
|
-
prefixedLog('event', ...msg)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function trace(...msg: any[]) {
|
|
109
|
-
prefixedLog('trace', ...msg)
|
|
110
|
-
}
|
package/src/utils/shutdown.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default function shutdown(cb: (signal: string, e: unknown) => void | Promise<void>) {
|
|
2
|
-
if (!process) return
|
|
3
|
-
const down = (signal: string) => (e?: unknown) => {
|
|
4
|
-
try {
|
|
5
|
-
cb(signal, e)
|
|
6
|
-
setTimeout(() => process.exit(0), 100)
|
|
7
|
-
} catch (e) {
|
|
8
|
-
process.exit(1)
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process.on('SIGINT', down('SIGINT'))
|
|
13
|
-
process.on('SIGTERM', down('SIGTERM'))
|
|
14
|
-
process.on('SIGHUP', down('SIGHUP'))
|
|
15
|
-
process.on('unhandledRejection', down('UNCAUGHT_REJECTION'))
|
|
16
|
-
process.on('uncaughtException', down('UNCAUGHT_EXCEPTION'))
|
|
17
|
-
// process.on('beforeExit', down('BEFORE_EXIT'))
|
|
18
|
-
// process.on('exit', down('EXIT'))
|
|
19
|
-
}
|