rajt 0.0.57 → 0.0.58
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 +10 -7
- package/package.json +31 -11
- package/src/bin/rajt.js +123 -0
- package/src/cli/commands/dev/index.ts +294 -0
- package/src/cli/commands/dev/utils.ts +206 -0
- package/src/cli/index.ts +69 -0
- package/src/cli/types.ts +1 -0
- package/src/create-app.ts +8 -2
- package/src/dev.ts +18 -15
- package/src/dynamodb/compact.ts +3 -3
- package/src/dynamodb/decorators.ts +12 -12
- package/src/dynamodb/model.ts +2 -2
- package/src/dynamodb/repository.ts +1 -1
- package/src/esbuild.mjs +11 -9
- package/src/http.ts +3 -3
- package/src/index.ts +1 -1
- package/src/prod-aws.ts +2 -17
- package/src/prod-cf.ts +1 -18
- package/src/prod.ts +16 -0
- package/src/scripts/cache-routes.ts +1 -1
- package/src/utils/environment.ts +3 -2
- package/src/utils/func.ts +2 -2
- package/src/utils/local-date.ts +13 -0
- package/src/utils/logger.ts +61 -0
- package/src/utils/port.ts +1 -3
- package/src/utils/resolve.ts +2 -2
- package/src/utils/shutdown.ts +19 -0
- package/src/enum.ts +0 -75
- package/src/utils/lenght.ts +0 -32
package/src/utils/func.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const isAsyncFn = (fn: any) => {
|
|
2
|
-
return fn?.constructor?.name
|
|
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
|
|
7
|
+
return fn?.name === '' || fn?.name == 'anonymous'
|
|
8
8
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const getFullYear = Date.prototype.getFullYear
|
|
2
|
+
const getMonth = Date.prototype.getMonth
|
|
3
|
+
const getDate = Date.prototype.getDate
|
|
4
|
+
const getHours = Date.prototype.getHours
|
|
5
|
+
const getMinutes = Date.prototype.getMinutes
|
|
6
|
+
const getSeconds = Date.prototype.getSeconds
|
|
7
|
+
const pad = (n: number) => n > 9 ? n : '0' + n
|
|
8
|
+
|
|
9
|
+
export const getLocalDateTime = (date = new Date()) =>
|
|
10
|
+
getFullYear.call(date) + '-' + pad(getMonth.call(date) + 1) + '-' + pad(getDate.call(date))
|
|
11
|
+
+ ' ' + pad(getHours.call(date)) + ':' + pad(getMinutes.call(date)) + ':' + pad(getSeconds.call(date))
|
|
12
|
+
|
|
13
|
+
export default getLocalDateTime
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import colors from 'picocolors'
|
|
2
|
+
|
|
3
|
+
const _console = { ...console }
|
|
4
|
+
|
|
5
|
+
export interface ILogger {
|
|
6
|
+
write(...data: Array<string | ArrayBufferView | ArrayBuffer>): number;
|
|
7
|
+
error(...data: any[]): void;
|
|
8
|
+
info(...data: any[]): void;
|
|
9
|
+
log(...data: any[]): void;
|
|
10
|
+
// TODO: table(tabularData?: any, properties?: string[]): void;
|
|
11
|
+
trace(...data: any[]): void;
|
|
12
|
+
warn(...data: any[]): void;
|
|
13
|
+
// custom
|
|
14
|
+
step(...data: any[]): void;
|
|
15
|
+
substep(...data: any[]): void;
|
|
16
|
+
ln(): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const logger = {
|
|
20
|
+
step(...args: any[]) {
|
|
21
|
+
if (args?.length && args.length < 2) return _console.log(colors.blue('⁕') +` ${args[0]}\n`)
|
|
22
|
+
const length = args.length - 1
|
|
23
|
+
args.forEach((arg, index) => {
|
|
24
|
+
switch (index) {
|
|
25
|
+
case 0:
|
|
26
|
+
return _console.log(colors.blue('⁕') + ' ' + arg)
|
|
27
|
+
// return _console.log(colors.blue('⁕') +` ${arg} \n`)
|
|
28
|
+
case length:
|
|
29
|
+
return _console.log(` ${colors.gray('⁕')} ${arg}\n`)
|
|
30
|
+
default:
|
|
31
|
+
return _console.log(` ${colors.gray('⁕')} ` + arg)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
substep(...args: any[]) {
|
|
36
|
+
args.forEach(arg => _console.log(` ${colors.gray('⁕')} ` + arg))
|
|
37
|
+
},
|
|
38
|
+
ln() {
|
|
39
|
+
_console.log('\n')
|
|
40
|
+
},
|
|
41
|
+
log(...args: any[]) {
|
|
42
|
+
_console.log(...args)
|
|
43
|
+
},
|
|
44
|
+
info(...args: any[]) {
|
|
45
|
+
_console.info(...args)
|
|
46
|
+
},
|
|
47
|
+
warn(...args: any[]) {
|
|
48
|
+
_console.warn(...args)
|
|
49
|
+
},
|
|
50
|
+
error(...args: any[]) {
|
|
51
|
+
_console.error(...args)
|
|
52
|
+
},
|
|
53
|
+
trace(...args: any[]) {
|
|
54
|
+
_console.trace(...args)
|
|
55
|
+
},
|
|
56
|
+
write(...args: any[]) {
|
|
57
|
+
_console.write(...args)
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default logger
|
package/src/utils/port.ts
CHANGED
package/src/utils/resolve.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Action, { ActionType } from '../action'
|
|
|
2
2
|
import { MiddlewareType } from '../middleware'
|
|
3
3
|
|
|
4
4
|
export function resolve(obj: ActionType, id: string) {
|
|
5
|
-
if (typeof obj
|
|
5
|
+
if (typeof obj == 'function' && obj?.length == 2)
|
|
6
6
|
return [obj]
|
|
7
7
|
|
|
8
8
|
if (obj?.run)
|
|
@@ -22,7 +22,7 @@ export function resolve(obj: ActionType, id: string) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function resolveMiddleware(obj: MiddlewareType) {
|
|
25
|
-
if (typeof obj
|
|
25
|
+
if (typeof obj == 'function' && obj.length == 2)
|
|
26
26
|
return obj
|
|
27
27
|
|
|
28
28
|
if (obj?.factory)
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
package/src/enum.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
type EnumType<T> = T extends string[]
|
|
2
|
-
? { [K in T[number]]: K }
|
|
3
|
-
: T extends Record<string, string | number>
|
|
4
|
-
? T
|
|
5
|
-
: never
|
|
6
|
-
|
|
7
|
-
type EnumValue<T> = T extends string[]
|
|
8
|
-
? T[number]
|
|
9
|
-
: T extends Record<string, infer V>
|
|
10
|
-
? V
|
|
11
|
-
: never
|
|
12
|
-
|
|
13
|
-
type EnumStatic<T> = {
|
|
14
|
-
has(search: string | number): boolean
|
|
15
|
-
key(search: string | number): string | null
|
|
16
|
-
value(search: string | number): EnumValue<T> | null
|
|
17
|
-
readonly keys: string[]
|
|
18
|
-
readonly values: Array<EnumValue<T>>
|
|
19
|
-
toObject(): EnumType<T>
|
|
20
|
-
} & EnumType<T>
|
|
21
|
-
|
|
22
|
-
export default function Enum<T extends string[] | Record<string, string | number>>(definition: T): EnumStatic<T> {
|
|
23
|
-
const enumObj = Array.isArray(definition)
|
|
24
|
-
? Object.fromEntries(definition.map(key => [key, key])) as EnumType<T>
|
|
25
|
-
: definition as EnumType<T>
|
|
26
|
-
|
|
27
|
-
const keyToValueMap = new Map<string | number, string | number>()
|
|
28
|
-
const valueToKeyMap = new Map<string | number, string>()
|
|
29
|
-
|
|
30
|
-
Object.entries(enumObj).forEach(([key, value]) => {
|
|
31
|
-
keyToValueMap.set(key, value)
|
|
32
|
-
valueToKeyMap.set(String(value), key)
|
|
33
|
-
if (typeof value === 'number') valueToKeyMap.set(value.toString(), key)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const GeneratedEnum = class {
|
|
37
|
-
static has(search: string | number): boolean {
|
|
38
|
-
return keyToValueMap.has(search as string) || valueToKeyMap.has(String(search))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static key(search: string | number): string | null {
|
|
42
|
-
if (keyToValueMap.has(search as string))
|
|
43
|
-
return search as string
|
|
44
|
-
|
|
45
|
-
return valueToKeyMap.get(String(search)) || null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static value(search: string | number): EnumValue<T> | null {
|
|
49
|
-
if (keyToValueMap.has(search as string))
|
|
50
|
-
return keyToValueMap.get(search as string) as EnumValue<T>
|
|
51
|
-
|
|
52
|
-
return valueToKeyMap.has(String(search))
|
|
53
|
-
? keyToValueMap.get(valueToKeyMap.get(String(search))!) as EnumValue<T>
|
|
54
|
-
: null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static get keys(): string[] {
|
|
58
|
-
return Object.keys(enumObj)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static get values(): Array<EnumValue<T>> {
|
|
62
|
-
return Object.values(enumObj) as Array<EnumValue<T>>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static toObject(): EnumType<T> {
|
|
66
|
-
return { ...enumObj }
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Object.entries(enumObj).forEach(([key, value]) => {
|
|
71
|
-
(GeneratedEnum as any)[key] = value
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
return GeneratedEnum as unknown as EnumStatic<T>
|
|
75
|
-
}
|
package/src/utils/lenght.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export default function getLength(item: any, type?: string): number {
|
|
2
|
-
if (!type) type = typeof item
|
|
3
|
-
|
|
4
|
-
switch (type) {
|
|
5
|
-
case 'string':
|
|
6
|
-
return item.length
|
|
7
|
-
|
|
8
|
-
case 'number':
|
|
9
|
-
case 'bigint':
|
|
10
|
-
// case 'function':
|
|
11
|
-
return item.toString().length
|
|
12
|
-
|
|
13
|
-
// case 'boolean':
|
|
14
|
-
// return item ? 1 : 0
|
|
15
|
-
|
|
16
|
-
// case 'symbol':
|
|
17
|
-
// return item.toString().length - 8
|
|
18
|
-
|
|
19
|
-
case 'object':
|
|
20
|
-
if (item === null)
|
|
21
|
-
return 0
|
|
22
|
-
|
|
23
|
-
if (Array.isArray(item))
|
|
24
|
-
return item.length
|
|
25
|
-
|
|
26
|
-
return Object.keys(item).length
|
|
27
|
-
|
|
28
|
-
case 'undefined':
|
|
29
|
-
default:
|
|
30
|
-
return 0
|
|
31
|
-
}
|
|
32
|
-
}
|