jax-hono 1.0.20 → 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 +68 -68
- package/core/api-controller.ts +290 -290
- package/core/app.ts +207 -207
- package/core/controller.ts +85 -85
- package/core/generated.ts +73 -73
- package/core/hono.ts +63 -63
- package/core/service.ts +44 -44
- package/docs/agent.md +164 -164
- package/docs/jax.md +326 -326
- 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/package.json
CHANGED
|
@@ -1,125 +1,130 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "jax-hono",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Lightweight framework layer on top of Hono, built for Bun",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./index.ts",
|
|
7
|
-
"types": "./index.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./index.ts",
|
|
11
|
-
"types": "./index.ts"
|
|
12
|
-
},
|
|
13
|
-
"./setup": {
|
|
14
|
-
"import": "./setup.ts",
|
|
15
|
-
"types": "./setup.ts"
|
|
16
|
-
},
|
|
17
|
-
"./config": {
|
|
18
|
-
"import": "./config.ts",
|
|
19
|
-
"types": "./config.ts"
|
|
20
|
-
},
|
|
21
|
-
"./core/*": {
|
|
22
|
-
"import": "./core/*.ts",
|
|
23
|
-
"types": "./core/*.ts"
|
|
24
|
-
},
|
|
25
|
-
"./helpers": {
|
|
26
|
-
"import": "./helpers/index.ts",
|
|
27
|
-
"types": "./helpers/index.ts"
|
|
28
|
-
},
|
|
29
|
-
"./helpers/*": {
|
|
30
|
-
"import": "./helpers/*.ts",
|
|
31
|
-
"types": "./helpers/*.ts"
|
|
32
|
-
},
|
|
33
|
-
"./middleware/*": {
|
|
34
|
-
"import": "./middleware/*.ts",
|
|
35
|
-
"types": "./middleware/*.ts"
|
|
36
|
-
},
|
|
37
|
-
"./plugins/*": {
|
|
38
|
-
"import": "./plugins/*/index.ts",
|
|
39
|
-
"types": "./plugins/*/index.ts"
|
|
40
|
-
},
|
|
41
|
-
"./plugins/*/*": {
|
|
42
|
-
"import": "./plugins/*/*.ts",
|
|
43
|
-
"types": "./plugins/*/*.ts"
|
|
44
|
-
},
|
|
45
|
-
"./utils": {
|
|
46
|
-
"import": "./utils/index.ts",
|
|
47
|
-
"types": "./utils/index.ts"
|
|
48
|
-
},
|
|
49
|
-
"./utils/*": {
|
|
50
|
-
"import": "./utils/*.ts",
|
|
51
|
-
"types": "./utils/*.ts"
|
|
52
|
-
},
|
|
53
|
-
"./types": {
|
|
54
|
-
"import": "./types/index.ts",
|
|
55
|
-
"types": "./types/index.ts"
|
|
56
|
-
},
|
|
57
|
-
"./types/*": {
|
|
58
|
-
"import": "./types/*.ts",
|
|
59
|
-
"types": "./types/*.ts"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"bin": {
|
|
63
|
-
"jax": "./bin/jax.js"
|
|
64
|
-
},
|
|
65
|
-
"files": [
|
|
66
|
-
"index.ts",
|
|
67
|
-
"setup.ts",
|
|
68
|
-
"config.ts",
|
|
69
|
-
"bin/",
|
|
70
|
-
"core/",
|
|
71
|
-
"middleware/",
|
|
72
|
-
"plugins/",
|
|
73
|
-
"helpers/",
|
|
74
|
-
"utils/",
|
|
75
|
-
"types/",
|
|
76
|
-
"build/",
|
|
77
|
-
"docs/",
|
|
78
|
-
"README.md"
|
|
79
|
-
],
|
|
80
|
-
"scripts": {
|
|
81
|
-
"postinstall": "echo 'jax-hono requires Bun. Visit https://bun.sh to install.'"
|
|
82
|
-
},
|
|
83
|
-
"dependencies": {
|
|
84
|
-
"@hono/session": "^0.2.1",
|
|
85
|
-
"@types/lodash-es": "^4.17.12",
|
|
86
|
-
"cac": "^7.0.0",
|
|
87
|
-
"lodash-es": "^4.18.1",
|
|
88
|
-
"p-limit": "^7.3.0"
|
|
89
|
-
},
|
|
90
|
-
"peerDependencies": {
|
|
91
|
-
"hono": "^4.12.27",
|
|
92
|
-
"dayjs": "*",
|
|
93
|
-
"deepmerge": "^4.3.1",
|
|
94
|
-
"dotenv": "^17.4.2",
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "jax-hono",
|
|
3
|
+
"version": "1.0.21",
|
|
4
|
+
"description": "Lightweight framework layer on top of Hono, built for Bun",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.ts",
|
|
7
|
+
"types": "./index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./index.ts",
|
|
11
|
+
"types": "./index.ts"
|
|
12
|
+
},
|
|
13
|
+
"./setup": {
|
|
14
|
+
"import": "./setup.ts",
|
|
15
|
+
"types": "./setup.ts"
|
|
16
|
+
},
|
|
17
|
+
"./config": {
|
|
18
|
+
"import": "./config.ts",
|
|
19
|
+
"types": "./config.ts"
|
|
20
|
+
},
|
|
21
|
+
"./core/*": {
|
|
22
|
+
"import": "./core/*.ts",
|
|
23
|
+
"types": "./core/*.ts"
|
|
24
|
+
},
|
|
25
|
+
"./helpers": {
|
|
26
|
+
"import": "./helpers/index.ts",
|
|
27
|
+
"types": "./helpers/index.ts"
|
|
28
|
+
},
|
|
29
|
+
"./helpers/*": {
|
|
30
|
+
"import": "./helpers/*.ts",
|
|
31
|
+
"types": "./helpers/*.ts"
|
|
32
|
+
},
|
|
33
|
+
"./middleware/*": {
|
|
34
|
+
"import": "./middleware/*.ts",
|
|
35
|
+
"types": "./middleware/*.ts"
|
|
36
|
+
},
|
|
37
|
+
"./plugins/*": {
|
|
38
|
+
"import": "./plugins/*/index.ts",
|
|
39
|
+
"types": "./plugins/*/index.ts"
|
|
40
|
+
},
|
|
41
|
+
"./plugins/*/*": {
|
|
42
|
+
"import": "./plugins/*/*.ts",
|
|
43
|
+
"types": "./plugins/*/*.ts"
|
|
44
|
+
},
|
|
45
|
+
"./utils": {
|
|
46
|
+
"import": "./utils/index.ts",
|
|
47
|
+
"types": "./utils/index.ts"
|
|
48
|
+
},
|
|
49
|
+
"./utils/*": {
|
|
50
|
+
"import": "./utils/*.ts",
|
|
51
|
+
"types": "./utils/*.ts"
|
|
52
|
+
},
|
|
53
|
+
"./types": {
|
|
54
|
+
"import": "./types/index.ts",
|
|
55
|
+
"types": "./types/index.ts"
|
|
56
|
+
},
|
|
57
|
+
"./types/*": {
|
|
58
|
+
"import": "./types/*.ts",
|
|
59
|
+
"types": "./types/*.ts"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"bin": {
|
|
63
|
+
"jax": "./bin/jax.js"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"index.ts",
|
|
67
|
+
"setup.ts",
|
|
68
|
+
"config.ts",
|
|
69
|
+
"bin/",
|
|
70
|
+
"core/",
|
|
71
|
+
"middleware/",
|
|
72
|
+
"plugins/",
|
|
73
|
+
"helpers/",
|
|
74
|
+
"utils/",
|
|
75
|
+
"types/",
|
|
76
|
+
"build/",
|
|
77
|
+
"docs/",
|
|
78
|
+
"README.md"
|
|
79
|
+
],
|
|
80
|
+
"scripts": {
|
|
81
|
+
"postinstall": "echo 'jax-hono requires Bun. Visit https://bun.sh to install.'"
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@hono/session": "^0.2.1",
|
|
85
|
+
"@types/lodash-es": "^4.17.12",
|
|
86
|
+
"cac": "^7.0.0",
|
|
87
|
+
"lodash-es": "^4.18.1",
|
|
88
|
+
"p-limit": "^7.3.0"
|
|
89
|
+
},
|
|
90
|
+
"peerDependencies": {
|
|
91
|
+
"hono": "^4.12.27",
|
|
92
|
+
"dayjs": "*",
|
|
93
|
+
"deepmerge": "^4.3.1",
|
|
94
|
+
"dotenv": "^17.4.2",
|
|
95
|
+
"axios": "^1.18.1",
|
|
96
|
+
"jsonwebtoken": "*",
|
|
97
|
+
"minimist": "^1.2.8",
|
|
98
|
+
"mongoose": "*"
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"axios": "^1.18.1",
|
|
102
|
+
"@types/bun": "^1.3.14",
|
|
103
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
104
|
+
"dayjs": "^1.11.21",
|
|
105
|
+
"deepmerge": "^4.3.1",
|
|
106
|
+
"dotenv": "^17.4.2",
|
|
107
|
+
"hono": "^4.12.27",
|
|
108
|
+
"jsonwebtoken": "^9.0.3",
|
|
109
|
+
"minimist": "^1.2.8",
|
|
110
|
+
"mongoose": "^8.24.1"
|
|
111
|
+
},
|
|
112
|
+
"peerDependenciesMeta": {
|
|
113
|
+
"axios": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"dayjs": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"mongoose": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"jsonwebtoken": {
|
|
123
|
+
"optional": true
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"engines": {
|
|
127
|
+
"bun": ">=1.0.0"
|
|
128
|
+
},
|
|
129
|
+
"license": "MIT"
|
|
125
130
|
}
|
package/plugins/config.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { definePluginConfig } from "../helpers/config";
|
|
2
|
-
|
|
3
|
-
export default definePluginConfig({
|
|
4
|
-
session: {
|
|
5
|
-
enable: true,
|
|
6
|
-
package: "jax-hono/plugins/session",
|
|
7
|
-
},
|
|
8
|
-
});
|
|
1
|
+
import { definePluginConfig } from "../helpers/config";
|
|
2
|
+
|
|
3
|
+
export default definePluginConfig({
|
|
4
|
+
session: {
|
|
5
|
+
enable: true,
|
|
6
|
+
package: "jax-hono/plugins/session",
|
|
7
|
+
},
|
|
8
|
+
});
|
package/plugins/define.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppPlugin } from '../core/app';
|
|
2
|
-
|
|
3
|
-
export function definePlugin<TPlugin extends AppPlugin>(plugin: TPlugin) {
|
|
4
|
-
return plugin;
|
|
5
|
-
}
|
|
1
|
+
import type { AppPlugin } from '../core/app';
|
|
2
|
+
|
|
3
|
+
export function definePlugin<TPlugin extends AppPlugin>(plugin: TPlugin) {
|
|
4
|
+
return plugin;
|
|
5
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
import { definePlugin } from '../define';
|
|
3
|
-
|
|
4
|
-
export type JaxPluginContext = {
|
|
5
|
-
mongoose?: typeof mongoose;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type MongoosePluginOptions = {
|
|
9
|
-
uri?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
async function connectMongoose(config: any, options: unknown) {
|
|
13
|
-
const uri = getMongooseUri(config, options);
|
|
14
|
-
|
|
15
|
-
if (!uri) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
'Mongoose plugin requires options.uri, config.mongoose.uri, config.mongo.uri, or config.mongodb.'
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// mongoose.set('strictQuery', true); // 严格查询模式
|
|
22
|
-
|
|
23
|
-
mongoose.set('toJSON', { virtuals: true, getters: true });
|
|
24
|
-
mongoose.set('debug', (collectionName, methodName, query, doc) => {
|
|
25
|
-
if (['request_log'].some((item) => collectionName.includes(item))) return;
|
|
26
|
-
console.log(`Mongoose: ${collectionName}.${methodName}`, JSON.stringify(query), doc);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
await mongoose.connect(uri);
|
|
30
|
-
|
|
31
|
-
console.log('Mongoose connected');
|
|
32
|
-
|
|
33
|
-
return mongoose;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getMongooseUri(config: any, options: unknown) {
|
|
37
|
-
const pluginOptions = isMongoosePluginOptions(options) ? options : {};
|
|
38
|
-
|
|
39
|
-
return pluginOptions.uri ?? config.mongoose?.uri ?? config.mongo?.uri ?? config.mongodb;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function isMongoosePluginOptions(options: unknown): options is MongoosePluginOptions {
|
|
43
|
-
return Boolean(options && typeof options === 'object' && !Array.isArray(options));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default definePlugin({
|
|
47
|
-
async setup(ctx, options) {
|
|
48
|
-
ctx.plugin.mongoose = await connectMongoose(ctx.config, options);
|
|
49
|
-
},
|
|
50
|
-
async close() {
|
|
51
|
-
if (mongoose.connection.readyState !== 0) {
|
|
52
|
-
await mongoose.disconnect();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
export * from './model';
|
|
57
|
-
export * from './schema';
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { definePlugin } from '../define';
|
|
3
|
+
|
|
4
|
+
export type JaxPluginContext = {
|
|
5
|
+
mongoose?: typeof mongoose;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type MongoosePluginOptions = {
|
|
9
|
+
uri?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
async function connectMongoose(config: any, options: unknown) {
|
|
13
|
+
const uri = getMongooseUri(config, options);
|
|
14
|
+
|
|
15
|
+
if (!uri) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
'Mongoose plugin requires options.uri, config.mongoose.uri, config.mongo.uri, or config.mongodb.'
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// mongoose.set('strictQuery', true); // 严格查询模式
|
|
22
|
+
|
|
23
|
+
mongoose.set('toJSON', { virtuals: true, getters: true });
|
|
24
|
+
mongoose.set('debug', (collectionName, methodName, query, doc) => {
|
|
25
|
+
if (['request_log'].some((item) => collectionName.includes(item))) return;
|
|
26
|
+
console.log(`Mongoose: ${collectionName}.${methodName}`, JSON.stringify(query), doc);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await mongoose.connect(uri);
|
|
30
|
+
|
|
31
|
+
console.log('Mongoose connected');
|
|
32
|
+
|
|
33
|
+
return mongoose;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getMongooseUri(config: any, options: unknown) {
|
|
37
|
+
const pluginOptions = isMongoosePluginOptions(options) ? options : {};
|
|
38
|
+
|
|
39
|
+
return pluginOptions.uri ?? config.mongoose?.uri ?? config.mongo?.uri ?? config.mongodb;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isMongoosePluginOptions(options: unknown): options is MongoosePluginOptions {
|
|
43
|
+
return Boolean(options && typeof options === 'object' && !Array.isArray(options));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default definePlugin({
|
|
47
|
+
async setup(ctx, options) {
|
|
48
|
+
ctx.plugin.mongoose = await connectMongoose(ctx.config, options);
|
|
49
|
+
},
|
|
50
|
+
async close() {
|
|
51
|
+
if (mongoose.connection.readyState !== 0) {
|
|
52
|
+
await mongoose.disconnect();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export * from './model';
|
|
57
|
+
export * from './schema';
|