jax-hono 1.0.19 → 1.0.21
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 +32 -32
- package/bin/jax.js +66 -66
- package/bin/jax.ts +8 -8
- package/build/build.ts +19 -19
- package/build/generate-config.ts +122 -122
- package/build/generate-registry.ts +902 -902
- package/build/generated-path.ts +20 -20
- package/config.ts +86 -83
- package/core/api-controller.ts +290 -290
- package/core/app.ts +207 -207
- package/core/controller.ts +85 -85
- package/core/generated.ts +118 -96
- package/core/hono.ts +63 -63
- package/core/service.ts +44 -44
- package/docs/agent.md +169 -167
- package/docs/jax.md +329 -327
- package/helpers/config.ts +23 -23
- package/helpers/crud.ts +27 -27
- package/helpers/index.ts +4 -4
- package/helpers/route.ts +7 -7
- package/index.ts +121 -121
- package/middleware/api-response.ts +44 -44
- package/middleware/jwt.ts +90 -90
- package/middleware/request-log.ts +3 -3
- package/package.json +129 -124
- package/plugins/config.ts +8 -8
- package/plugins/define.ts +5 -5
- package/plugins/mongoose/index.ts +57 -57
- package/plugins/mongoose/model.ts +322 -322
- package/plugins/mongoose/schema.ts +30 -30
- package/plugins/session/index.ts +86 -86
- package/setup.ts +105 -105
- package/types/config.ts +9 -9
- package/types/context.ts +9 -9
- package/types/index.ts +2 -2
- package/utils/array.ts +7 -7
- package/utils/async.ts +47 -47
- package/utils/crypto.ts +6 -6
- package/utils/http.ts +106 -0
- package/utils/index.ts +3 -2
- package/utils/regexp.ts +14 -14
- package/utils/transform.ts +3 -3
package/build/generated-path.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { mkdirSync } from 'node:fs'
|
|
2
|
-
import { cwd } from 'node:process'
|
|
3
|
-
import { join, resolve } from 'node:path'
|
|
4
|
-
|
|
5
|
-
export const packageDir = join(import.meta.dir, '..')
|
|
6
|
-
export const projectDir = cwd()
|
|
7
|
-
|
|
8
|
-
export function getGeneratedDir() {
|
|
9
|
-
const configuredDir = Bun.env.JAX_HONO_GENERATED_DIR
|
|
10
|
-
|
|
11
|
-
return configuredDir
|
|
12
|
-
? resolve(projectDir, configuredDir)
|
|
13
|
-
: join(projectDir, '.jax-hono')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const generatedDir = getGeneratedDir()
|
|
17
|
-
|
|
18
|
-
export function ensureGeneratedDir() {
|
|
19
|
-
mkdirSync(generatedDir, { recursive: true })
|
|
20
|
-
}
|
|
1
|
+
import { mkdirSync } from 'node:fs'
|
|
2
|
+
import { cwd } from 'node:process'
|
|
3
|
+
import { join, resolve } from 'node:path'
|
|
4
|
+
|
|
5
|
+
export const packageDir = join(import.meta.dir, '..')
|
|
6
|
+
export const projectDir = cwd()
|
|
7
|
+
|
|
8
|
+
export function getGeneratedDir() {
|
|
9
|
+
const configuredDir = Bun.env.JAX_HONO_GENERATED_DIR
|
|
10
|
+
|
|
11
|
+
return configuredDir
|
|
12
|
+
? resolve(projectDir, configuredDir)
|
|
13
|
+
: join(projectDir, '.jax-hono')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const generatedDir = getGeneratedDir()
|
|
17
|
+
|
|
18
|
+
export function ensureGeneratedDir() {
|
|
19
|
+
mkdirSync(generatedDir, { recursive: true })
|
|
20
|
+
}
|
package/config.ts
CHANGED
|
@@ -1,83 +1,86 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import merge from 'deepmerge';
|
|
4
|
-
import { config as loadDotenv } from 'dotenv';
|
|
5
|
-
import minimist from 'minimist';
|
|
6
|
-
import { requireGeneratedModule, type GeneratedProjectConfig } from './core/generated';
|
|
7
|
-
import type { JaxConfig } from './types/config';
|
|
8
|
-
|
|
9
|
-
type PlainConfig = Record<string, unknown>;
|
|
10
|
-
type ProjectConfig = GeneratedProjectConfig;
|
|
11
|
-
type ConfigModuleItem = {
|
|
12
|
-
name: string;
|
|
13
|
-
stage: string;
|
|
14
|
-
config: unknown;
|
|
15
|
-
};
|
|
16
|
-
export type { JaxConfig } from './types/config';
|
|
17
|
-
export type Config = JaxConfig & ProjectConfig;
|
|
18
|
-
|
|
19
|
-
const { configModules } = requireGeneratedModule<{ configModules: readonly ConfigModuleItem[] }>('config.ts');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import merge from 'deepmerge';
|
|
4
|
+
import { config as loadDotenv } from 'dotenv';
|
|
5
|
+
import minimist from 'minimist';
|
|
6
|
+
import { getProjectDir, requireGeneratedModule, type GeneratedProjectConfig } from './core/generated';
|
|
7
|
+
import type { JaxConfig } from './types/config';
|
|
8
|
+
|
|
9
|
+
type PlainConfig = Record<string, unknown>;
|
|
10
|
+
type ProjectConfig = GeneratedProjectConfig;
|
|
11
|
+
type ConfigModuleItem = {
|
|
12
|
+
name: string;
|
|
13
|
+
stage: string;
|
|
14
|
+
config: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type { JaxConfig } from './types/config';
|
|
17
|
+
export type Config = JaxConfig & ProjectConfig;
|
|
18
|
+
|
|
19
|
+
const { configModules } = requireGeneratedModule<{ configModules: readonly ConfigModuleItem[] }>('config.ts');
|
|
20
|
+
const projectDir = getProjectDir();
|
|
21
|
+
|
|
22
|
+
loadDotenvFile('.env');
|
|
23
|
+
|
|
24
|
+
const argv = minimist(Bun.argv.slice(2), {
|
|
25
|
+
string: ['env'],
|
|
26
|
+
alias: {
|
|
27
|
+
env: 'e'
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const env = argv.env || Bun.env.APP_ENV || Bun.env.NODE_ENV || 'prod';
|
|
32
|
+
|
|
33
|
+
console.log('env', env);
|
|
34
|
+
|
|
35
|
+
loadDotenvFile(`.env.${env}`);
|
|
36
|
+
|
|
37
|
+
function loadDotenvFile(file: string) {
|
|
38
|
+
const path = join(projectDir, file);
|
|
39
|
+
|
|
40
|
+
if (existsSync(path)) {
|
|
41
|
+
loadDotenv({ path, override: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isPlainConfig(value: unknown): value is PlainConfig {
|
|
46
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function shouldUseConfigStage(stage: string) {
|
|
50
|
+
return stage === 'base' || stage === 'default' || stage === env;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function parsePort(value: string | undefined) {
|
|
54
|
+
const port = Number(value);
|
|
55
|
+
|
|
56
|
+
return Number.isInteger(port) && port > 0 ? port : 3000;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function loadConfig(): Config {
|
|
60
|
+
const jaxConfig: JaxConfig = {
|
|
61
|
+
rootDir: projectDir,
|
|
62
|
+
port: parsePort(Bun.env.PORT),
|
|
63
|
+
env
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const configs = configModules
|
|
67
|
+
.filter((item) => shouldUseConfigStage(item.stage))
|
|
68
|
+
.map((item) => {
|
|
69
|
+
if (!isPlainConfig(item.config)) {
|
|
70
|
+
throw new TypeError(`Config file ${item.name} must export a plain object.`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return item.config;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return merge.all<PlainConfig>([jaxConfig, ...configs], {
|
|
77
|
+
arrayMerge: (_destination, source) => source
|
|
78
|
+
}) as Config;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const config = loadConfig();
|
|
82
|
+
|
|
83
|
+
console.log('port', config.port);
|
|
84
|
+
|
|
85
|
+
export { env };
|
|
86
|
+
export default config;
|