@modern-js/plugin-bff 3.10.1 → 3.10.3
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.
|
@@ -72,7 +72,17 @@ const handleResponseMeta = (c, handler)=>{
|
|
|
72
72
|
}
|
|
73
73
|
return null;
|
|
74
74
|
};
|
|
75
|
-
const
|
|
75
|
+
const getParamNames = (routePath)=>{
|
|
76
|
+
const paramNames = routePath.match(/:\w+/g)?.map((s)=>s.slice(1)) || [];
|
|
77
|
+
return Object.keys(Object.fromEntries(paramNames.map((name)=>[
|
|
78
|
+
name,
|
|
79
|
+
true
|
|
80
|
+
])));
|
|
81
|
+
};
|
|
82
|
+
const createHonoHandler = (handler)=>{
|
|
83
|
+
let cachedRoutePath;
|
|
84
|
+
let paramNames = [];
|
|
85
|
+
return async (c)=>{
|
|
76
86
|
const input = await getHonoInput(c);
|
|
77
87
|
if ((0, bff_core_namespaceObject.isWithMetaHandler)(handler)) try {
|
|
78
88
|
const response = handleResponseMeta(c, handler);
|
|
@@ -92,12 +102,12 @@ const createHonoHandler = (handler)=>async (c)=>{
|
|
|
92
102
|
}
|
|
93
103
|
else {
|
|
94
104
|
const routePath = c.req.routePath;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
if (routePath !== cachedRoutePath) {
|
|
106
|
+
cachedRoutePath = routePath;
|
|
107
|
+
paramNames = getParamNames(routePath);
|
|
108
|
+
}
|
|
109
|
+
const args = paramNames.map((name)=>input.params[name]);
|
|
110
|
+
args.push(input);
|
|
101
111
|
const body = await handler(...args);
|
|
102
112
|
if (c.finalized) return await Promise.resolve();
|
|
103
113
|
if (void 0 !== body) {
|
|
@@ -106,6 +116,7 @@ const createHonoHandler = (handler)=>async (c)=>{
|
|
|
106
116
|
}
|
|
107
117
|
}
|
|
108
118
|
};
|
|
119
|
+
};
|
|
109
120
|
const getHonoInput = async (c)=>{
|
|
110
121
|
const draft = {
|
|
111
122
|
params: c.req.param(),
|
|
@@ -115,15 +126,16 @@ const getHonoInput = async (c)=>{
|
|
|
115
126
|
};
|
|
116
127
|
try {
|
|
117
128
|
const contentType = c.req.header('content-type') || '';
|
|
118
|
-
|
|
119
|
-
'application/json'
|
|
120
|
-
|
|
121
|
-
else if (external_type_is_default().is(contentType, [
|
|
122
|
-
'multipart/form-data'
|
|
123
|
-
])) draft.formData = await c.req.parseBody();
|
|
124
|
-
else if (external_type_is_default().is(contentType, [
|
|
129
|
+
const type = external_type_is_default().is(contentType, [
|
|
130
|
+
'application/json',
|
|
131
|
+
'multipart/form-data',
|
|
125
132
|
'application/x-www-form-urlencoded'
|
|
126
|
-
])
|
|
133
|
+
]);
|
|
134
|
+
const { method } = c.req;
|
|
135
|
+
if ('multipart/form-data' === type) draft.formData = await c.req.parseBody();
|
|
136
|
+
else if ('application/x-www-form-urlencoded' === type) draft.formUrlencoded = await c.req.parseBody();
|
|
137
|
+
else if ('GET' === method || 'HEAD' === method) draft.body = null;
|
|
138
|
+
else if ('application/json' === type) draft.data = await c.req.json();
|
|
127
139
|
else draft.body = await c.req.json();
|
|
128
140
|
} catch (error) {
|
|
129
141
|
draft.body = null;
|
|
@@ -29,7 +29,17 @@ const handleResponseMeta = (c, handler)=>{
|
|
|
29
29
|
}
|
|
30
30
|
return null;
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const getParamNames = (routePath)=>{
|
|
33
|
+
const paramNames = routePath.match(/:\w+/g)?.map((s)=>s.slice(1)) || [];
|
|
34
|
+
return Object.keys(Object.fromEntries(paramNames.map((name)=>[
|
|
35
|
+
name,
|
|
36
|
+
true
|
|
37
|
+
])));
|
|
38
|
+
};
|
|
39
|
+
const createHonoHandler = (handler)=>{
|
|
40
|
+
let cachedRoutePath;
|
|
41
|
+
let paramNames = [];
|
|
42
|
+
return async (c)=>{
|
|
33
43
|
const input = await getHonoInput(c);
|
|
34
44
|
if (isWithMetaHandler(handler)) try {
|
|
35
45
|
const response = handleResponseMeta(c, handler);
|
|
@@ -49,12 +59,12 @@ const createHonoHandler = (handler)=>async (c)=>{
|
|
|
49
59
|
}
|
|
50
60
|
else {
|
|
51
61
|
const routePath = c.req.routePath;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
if (routePath !== cachedRoutePath) {
|
|
63
|
+
cachedRoutePath = routePath;
|
|
64
|
+
paramNames = getParamNames(routePath);
|
|
65
|
+
}
|
|
66
|
+
const args = paramNames.map((name)=>input.params[name]);
|
|
67
|
+
args.push(input);
|
|
58
68
|
const body = await handler(...args);
|
|
59
69
|
if (c.finalized) return await Promise.resolve();
|
|
60
70
|
if (void 0 !== body) {
|
|
@@ -63,6 +73,7 @@ const createHonoHandler = (handler)=>async (c)=>{
|
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
};
|
|
76
|
+
};
|
|
66
77
|
const getHonoInput = async (c)=>{
|
|
67
78
|
const draft = {
|
|
68
79
|
params: c.req.param(),
|
|
@@ -72,15 +83,16 @@ const getHonoInput = async (c)=>{
|
|
|
72
83
|
};
|
|
73
84
|
try {
|
|
74
85
|
const contentType = c.req.header('content-type') || '';
|
|
75
|
-
|
|
76
|
-
'application/json'
|
|
77
|
-
|
|
78
|
-
else if (type_is.is(contentType, [
|
|
79
|
-
'multipart/form-data'
|
|
80
|
-
])) draft.formData = await c.req.parseBody();
|
|
81
|
-
else if (type_is.is(contentType, [
|
|
86
|
+
const type = type_is.is(contentType, [
|
|
87
|
+
'application/json',
|
|
88
|
+
'multipart/form-data',
|
|
82
89
|
'application/x-www-form-urlencoded'
|
|
83
|
-
])
|
|
90
|
+
]);
|
|
91
|
+
const { method } = c.req;
|
|
92
|
+
if ('multipart/form-data' === type) draft.formData = await c.req.parseBody();
|
|
93
|
+
else if ('application/x-www-form-urlencoded' === type) draft.formUrlencoded = await c.req.parseBody();
|
|
94
|
+
else if ('GET' === method || 'HEAD' === method) draft.body = null;
|
|
95
|
+
else if ('application/json' === type) draft.data = await c.req.json();
|
|
84
96
|
else draft.body = await c.req.json();
|
|
85
97
|
} catch (error) {
|
|
86
98
|
draft.body = null;
|
|
@@ -30,7 +30,17 @@ const handleResponseMeta = (c, handler)=>{
|
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
};
|
|
33
|
-
const
|
|
33
|
+
const getParamNames = (routePath)=>{
|
|
34
|
+
const paramNames = routePath.match(/:\w+/g)?.map((s)=>s.slice(1)) || [];
|
|
35
|
+
return Object.keys(Object.fromEntries(paramNames.map((name)=>[
|
|
36
|
+
name,
|
|
37
|
+
true
|
|
38
|
+
])));
|
|
39
|
+
};
|
|
40
|
+
const createHonoHandler = (handler)=>{
|
|
41
|
+
let cachedRoutePath;
|
|
42
|
+
let paramNames = [];
|
|
43
|
+
return async (c)=>{
|
|
34
44
|
const input = await getHonoInput(c);
|
|
35
45
|
if (isWithMetaHandler(handler)) try {
|
|
36
46
|
const response = handleResponseMeta(c, handler);
|
|
@@ -50,12 +60,12 @@ const createHonoHandler = (handler)=>async (c)=>{
|
|
|
50
60
|
}
|
|
51
61
|
else {
|
|
52
62
|
const routePath = c.req.routePath;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
if (routePath !== cachedRoutePath) {
|
|
64
|
+
cachedRoutePath = routePath;
|
|
65
|
+
paramNames = getParamNames(routePath);
|
|
66
|
+
}
|
|
67
|
+
const args = paramNames.map((name)=>input.params[name]);
|
|
68
|
+
args.push(input);
|
|
59
69
|
const body = await handler(...args);
|
|
60
70
|
if (c.finalized) return await Promise.resolve();
|
|
61
71
|
if (void 0 !== body) {
|
|
@@ -64,6 +74,7 @@ const createHonoHandler = (handler)=>async (c)=>{
|
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
};
|
|
77
|
+
};
|
|
67
78
|
const getHonoInput = async (c)=>{
|
|
68
79
|
const draft = {
|
|
69
80
|
params: c.req.param(),
|
|
@@ -73,15 +84,16 @@ const getHonoInput = async (c)=>{
|
|
|
73
84
|
};
|
|
74
85
|
try {
|
|
75
86
|
const contentType = c.req.header('content-type') || '';
|
|
76
|
-
|
|
77
|
-
'application/json'
|
|
78
|
-
|
|
79
|
-
else if (type_is.is(contentType, [
|
|
80
|
-
'multipart/form-data'
|
|
81
|
-
])) draft.formData = await c.req.parseBody();
|
|
82
|
-
else if (type_is.is(contentType, [
|
|
87
|
+
const type = type_is.is(contentType, [
|
|
88
|
+
'application/json',
|
|
89
|
+
'multipart/form-data',
|
|
83
90
|
'application/x-www-form-urlencoded'
|
|
84
|
-
])
|
|
91
|
+
]);
|
|
92
|
+
const { method } = c.req;
|
|
93
|
+
if ('multipart/form-data' === type) draft.formData = await c.req.parseBody();
|
|
94
|
+
else if ('application/x-www-form-urlencoded' === type) draft.formUrlencoded = await c.req.parseBody();
|
|
95
|
+
else if ('GET' === method || 'HEAD' === method) draft.body = null;
|
|
96
|
+
else if ('application/json' === type) draft.data = await c.req.json();
|
|
85
97
|
else draft.body = await c.req.json();
|
|
86
98
|
} catch (error) {
|
|
87
99
|
draft.body = null;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.10.
|
|
18
|
+
"version": "3.10.3",
|
|
19
19
|
"types": "./dist/types/cli.d.ts",
|
|
20
20
|
"main": "./dist/cjs/cli.js",
|
|
21
21
|
"exports": {
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"@swc/helpers": "^0.5.17",
|
|
80
80
|
"qs": "^6.16.1",
|
|
81
81
|
"type-is": "^1.6.18",
|
|
82
|
-
"@modern-js/
|
|
83
|
-
"@modern-js/
|
|
84
|
-
"@modern-js/
|
|
85
|
-
"@modern-js/server-
|
|
86
|
-
"@modern-js/
|
|
87
|
-
"@modern-js/utils": "3.10.
|
|
82
|
+
"@modern-js/builder": "3.10.3",
|
|
83
|
+
"@modern-js/bff-core": "3.10.3",
|
|
84
|
+
"@modern-js/server-core": "3.10.3",
|
|
85
|
+
"@modern-js/server-utils": "3.10.3",
|
|
86
|
+
"@modern-js/create-request": "3.10.3",
|
|
87
|
+
"@modern-js/utils": "3.10.3"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@rsbuild/core": "2.2.13",
|
|
@@ -94,13 +94,13 @@
|
|
|
94
94
|
"memfs": "^3.5.3",
|
|
95
95
|
"typescript": "^5",
|
|
96
96
|
"zod": "^3.25.76",
|
|
97
|
-
"@modern-js/app-tools": "3.10.
|
|
98
|
-
"@modern-js/bff-runtime": "3.10.
|
|
99
|
-
"@modern-js/plugin": "3.10.
|
|
100
|
-
"@modern-js/rslib": "
|
|
101
|
-
"@modern-js/
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@scripts/rstest-config": "2.66.
|
|
97
|
+
"@modern-js/app-tools": "3.10.3",
|
|
98
|
+
"@modern-js/bff-runtime": "3.10.3",
|
|
99
|
+
"@modern-js/plugin": "3.10.3",
|
|
100
|
+
"@modern-js/rslib": "3.10.3",
|
|
101
|
+
"@modern-js/types": "3.10.3",
|
|
102
|
+
"@modern-js/runtime": "3.10.3",
|
|
103
|
+
"@scripts/rstest-config": "2.66.2"
|
|
104
104
|
},
|
|
105
105
|
"sideEffects": false,
|
|
106
106
|
"publishConfig": {
|