@innet/server 2.0.0-beta.1 → 2.0.0-beta.2
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 +22 -0
- package/handler/handler.d.ts +1 -7
- package/handler/handler.es6.js +1 -4
- package/handler/handler.js +0 -3
- package/hooks/useHeaders/useHeaders.d.ts +0 -1
- package/hooks/useNewSchema/useNewSchema.es6.js +1 -1
- package/hooks/useNewSchema/useNewSchema.js +1 -1
- package/hooks/useRequest/useRequest.d.ts +0 -1
- package/hooks/useResponse/useResponse.d.ts +0 -1
- package/hooks/useSchemaType/useSchemaType.es6.js +17 -9
- package/hooks/useSchemaType/useSchemaType.js +17 -9
- package/hooks/useServer/useServer.d.ts +0 -2
- package/index.es6.js +0 -1
- package/index.js +0 -1
- package/package.json +15 -15
- package/plugins/handler/serverFn/serverFn.es6.js +1 -1
- package/plugins/handler/serverFn/serverFn.js +1 -1
- package/plugins/main/api/api.es6.js +73 -73
- package/plugins/main/api/api.js +73 -73
- package/plugins/main/endpoint/endpoint.d.ts +5 -0
- package/plugins/main/endpoint/endpoint.es6.js +4 -4
- package/plugins/main/endpoint/endpoint.js +4 -4
- package/plugins/main/host/host.es6.js +3 -1
- package/plugins/main/host/host.js +3 -1
- package/plugins/main/param/param.es6.js +2 -3
- package/plugins/main/param/param.js +2 -3
- package/plugins/main/response/response.es6.js +10 -3
- package/plugins/main/response/response.js +10 -3
- package/plugins/main/server/server.d.ts +0 -1
- package/plugins/main/server/server.es6.js +6 -9
- package/plugins/main/server/server.js +6 -9
- package/plugins/main/variable/variable.es6.js +3 -4
- package/plugins/main/variable/variable.js +3 -4
- package/plugins/request/cookie/cookie.d.ts +2 -2
- package/plugins/request/cookie/cookie.es6.js +1 -2
- package/plugins/request/cookie/cookie.js +1 -2
- package/plugins/request/error/error.es6.js +1 -2
- package/plugins/request/error/error.js +1 -2
- package/plugins/request/file/file.es6.js +1 -2
- package/plugins/request/file/file.js +1 -2
- package/plugins/request/proxy/proxy.d.ts +0 -1
- package/plugins/schema/array/array.es6.js +1 -2
- package/plugins/schema/array/array.js +1 -2
- package/plugins/schema/date/date.es6.js +8 -4
- package/plugins/schema/date/date.js +8 -4
- package/plugins/schema/integer/integer.es6.js +8 -3
- package/plugins/schema/integer/integer.js +8 -3
- package/plugins/schema/number/number.es6.js +1 -2
- package/plugins/schema/number/number.js +1 -2
- package/plugins/schema/object/object.es6.js +1 -2
- package/plugins/schema/object/object.js +1 -2
- package/plugins/schema/string/string.es6.js +1 -2
- package/plugins/schema/string/string.js +1 -2
- package/plugins/schema/tuple/tuple.es6.js +1 -2
- package/plugins/schema/tuple/tuple.js +1 -2
- package/plugins/schema/uuid/uuid.es6.js +5 -3
- package/plugins/schema/uuid/uuid.js +5 -3
- package/utils/action/Action.d.ts +4 -5
- package/utils/action/Action.es6.js +14 -16
- package/utils/action/Action.js +13 -15
- package/utils/parseBody/parseBody.d.ts +0 -1
- package/utils/parseBody/parseBody.es6.js +13 -16
- package/utils/parseBody/parseBody.js +13 -16
- package/utils/parseFormBody/parseFormBody.d.ts +0 -1
- package/utils/parseFormBody/parseFormBody.es6.js +41 -41
- package/utils/parseFormBody/parseFormBody.js +41 -41
- package/utils/parseSearch/parseSearch.es6.js +4 -1
- package/utils/parseSearch/parseSearch.js +4 -1
- package/utils/rules/arrayOf/arrayOf.es6.js +1 -1
- package/utils/rules/arrayOf/arrayOf.js +1 -1
- package/utils/rules/bin/bin.es6.js +4 -1
- package/utils/rules/bin/bin.js +4 -1
- package/utils/rules/binaryAccept/binaryAccept.es6.js +5 -2
- package/utils/rules/binaryAccept/binaryAccept.js +5 -2
- package/utils/rules/dateTo/dateTo.es6.js +4 -1
- package/utils/rules/dateTo/dateTo.js +4 -1
- package/utils/rules/helpers.es6.js +4 -1
- package/utils/rules/helpers.js +4 -1
- package/utils/rules/int/int.es6.js +17 -4
- package/utils/rules/int/int.js +17 -4
- package/utils/rules/max/max.es6.js +9 -3
- package/utils/rules/max/max.js +9 -3
- package/utils/rules/maxBin/maxBin.es6.js +5 -2
- package/utils/rules/maxBin/maxBin.js +5 -2
- package/utils/rules/maxDate/maxDate.es6.js +5 -1
- package/utils/rules/maxDate/maxDate.js +5 -1
- package/utils/rules/maxLength/maxLength.es6.js +5 -2
- package/utils/rules/maxLength/maxLength.js +5 -2
- package/utils/rules/min/min.es6.js +9 -3
- package/utils/rules/min/min.js +9 -3
- package/utils/rules/minBin/minBin.es6.js +5 -2
- package/utils/rules/minBin/minBin.js +5 -2
- package/utils/rules/minDate/minDate.es6.js +5 -1
- package/utils/rules/minDate/minDate.js +5 -1
- package/utils/rules/minLength/minLength.es6.js +5 -2
- package/utils/rules/minLength/minLength.js +5 -2
- package/utils/rules/num/num.es6.js +4 -1
- package/utils/rules/num/num.js +4 -1
- package/utils/rules/objectOf/objectOf.es6.js +6 -3
- package/utils/rules/objectOf/objectOf.js +6 -3
- package/utils/rules/pattern/pattern.es6.js +6 -2
- package/utils/rules/pattern/pattern.js +6 -2
- package/utils/rules/tupleOf/tupleOf.es6.js +1 -1
- package/utils/rules/tupleOf/tupleOf.js +1 -1
- package/utils/rules/values/values.es6.js +5 -2
- package/utils/rules/values/values.js +5 -2
- package/utils/stringifySearch/stringifySearch.es6.js +4 -1
- package/utils/stringifySearch/stringifySearch.js +4 -1
- package/_virtual/_rollup-plugin-process-env.es6.js +0 -10
- package/_virtual/_rollup-plugin-process-env.js +0 -12
package/plugins/main/api/api.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var innet = require('innet');
|
|
7
6
|
var jsx = require('@innet/jsx');
|
|
8
7
|
require('../../../hooks/index.js');
|
|
@@ -23,8 +22,8 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
23
22
|
const api = () => {
|
|
24
23
|
const handler = innet.useNewHandler();
|
|
25
24
|
const props = jsx.useProps();
|
|
26
|
-
const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0'
|
|
27
|
-
const info =
|
|
25
|
+
const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0', ...rest } = props;
|
|
26
|
+
const info = { ...rest, title, version };
|
|
28
27
|
const endpoints = {};
|
|
29
28
|
const docs = {
|
|
30
29
|
info,
|
|
@@ -46,7 +45,7 @@ const api = () => {
|
|
|
46
45
|
};
|
|
47
46
|
useServerPlugins.serverPlugins.set(handler, plugins);
|
|
48
47
|
useApi.apiContext.set(handler, context);
|
|
49
|
-
useServerPlugin.useServerPlugin(() =>
|
|
48
|
+
useServerPlugin.useServerPlugin(async () => {
|
|
50
49
|
var _a, _b, _c, _d, _e, _f;
|
|
51
50
|
const action = useAction.useAction();
|
|
52
51
|
if (!condition(action))
|
|
@@ -70,91 +69,92 @@ const api = () => {
|
|
|
70
69
|
const [deep, currentEndpoint, params] = endpointQueue.shift();
|
|
71
70
|
const key = splitPath[deep];
|
|
72
71
|
if (deep + 1 === splitPath.length) {
|
|
73
|
-
function run(runEndpoint, params) {
|
|
72
|
+
async function run(runEndpoint, params) {
|
|
74
73
|
var _a, _b, _c, _d, _e;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Object.assign(params, pathRules(params, { in: 'path' }));
|
|
84
|
-
}
|
|
85
|
-
catch (_f) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
74
|
+
const pathRules = (_a = runEndpoint.rules) === null || _a === void 0 ? void 0 : _a.path;
|
|
75
|
+
const headerRules = (_b = runEndpoint.rules) === null || _b === void 0 ? void 0 : _b.header;
|
|
76
|
+
const cookieRules = (_c = runEndpoint.rules) === null || _c === void 0 ? void 0 : _c.cookie;
|
|
77
|
+
const searchRules = (_d = runEndpoint.rules) === null || _d === void 0 ? void 0 : _d.search;
|
|
78
|
+
const bodyRules = (_e = runEndpoint.rules) === null || _e === void 0 ? void 0 : _e.body;
|
|
79
|
+
if (pathRules) {
|
|
80
|
+
try {
|
|
81
|
+
Object.assign(params, pathRules(params, { in: 'path' }));
|
|
88
82
|
}
|
|
89
|
-
|
|
90
|
-
if (rules) {
|
|
91
|
-
try {
|
|
92
|
-
action[key] = rules(action[key]);
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
res.setHeader('Content-Type', 'application/json');
|
|
96
|
-
if (e instanceof helpers.RulesError) {
|
|
97
|
-
res.statusCode = 400;
|
|
98
|
-
res.write(JSONString.JSONString({
|
|
99
|
-
data: Object.assign(Object.assign({}, e.data), { in: key }),
|
|
100
|
-
error: 'requestValidation',
|
|
101
|
-
}));
|
|
102
|
-
res.end();
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
console.error(e);
|
|
106
|
-
res.statusCode = 500;
|
|
107
|
-
res.write(JSONString.JSONString({
|
|
108
|
-
data: { in: key },
|
|
109
|
-
error: 'unknown',
|
|
110
|
-
}));
|
|
111
|
-
res.end();
|
|
112
|
-
}
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
83
|
+
catch (_f) {
|
|
116
84
|
return false;
|
|
117
85
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
yield action.parseBody();
|
|
126
|
-
if (!action.body) {
|
|
127
|
-
res.statusCode = 400;
|
|
86
|
+
}
|
|
87
|
+
function checkActionRules(rules, key = 'search') {
|
|
88
|
+
if (rules) {
|
|
89
|
+
try {
|
|
90
|
+
action[key] = rules(action[key]);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
128
93
|
res.setHeader('Content-Type', 'application/json');
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
94
|
+
if (e instanceof helpers.RulesError) {
|
|
95
|
+
res.statusCode = 400;
|
|
96
|
+
res.write(JSONString.JSONString({
|
|
97
|
+
data: {
|
|
98
|
+
...e.data,
|
|
99
|
+
in: key,
|
|
100
|
+
},
|
|
101
|
+
error: 'requestValidation',
|
|
102
|
+
}));
|
|
103
|
+
res.end();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.error(e);
|
|
107
|
+
res.statusCode = 500;
|
|
108
|
+
res.write(JSONString.JSONString({
|
|
109
|
+
data: { in: key },
|
|
110
|
+
error: 'unknown',
|
|
111
|
+
}));
|
|
112
|
+
res.end();
|
|
113
|
+
}
|
|
133
114
|
return true;
|
|
134
115
|
}
|
|
135
|
-
if (checkActionRules(bodyRules, 'body'))
|
|
136
|
-
return true;
|
|
137
116
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (checkActionRules(headerRules, 'headers'))
|
|
120
|
+
return true;
|
|
121
|
+
if (checkActionRules(cookieRules, 'cookies'))
|
|
122
|
+
return true;
|
|
123
|
+
if (checkActionRules(searchRules, 'search'))
|
|
124
|
+
return true;
|
|
125
|
+
if (bodyRules) {
|
|
126
|
+
await action.parseBody();
|
|
127
|
+
if (!action.body) {
|
|
128
|
+
res.statusCode = 400;
|
|
129
|
+
res.setHeader('Content-Type', 'application/json');
|
|
130
|
+
res.write(JSONString.JSONString({
|
|
131
|
+
error: 'requestBodyContentType',
|
|
132
|
+
}));
|
|
133
|
+
res.end();
|
|
144
134
|
return true;
|
|
145
135
|
}
|
|
136
|
+
if (checkActionRules(bodyRules, 'body'))
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
useParams.paramsContext.set(actionHandler, params);
|
|
140
|
+
for (const plugin of runEndpoint.plugins) {
|
|
141
|
+
const result = await plugin();
|
|
142
|
+
if (result === undefined)
|
|
143
|
+
continue;
|
|
144
|
+
innet__default["default"](result, actionHandler);
|
|
146
145
|
return true;
|
|
147
|
-
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
148
|
}
|
|
149
149
|
if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
|
|
150
|
-
if (!
|
|
150
|
+
if (!await run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params))
|
|
151
151
|
continue;
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
154
|
if (currentEndpoint.dynamic) {
|
|
155
155
|
for (const dynamicEndpoint of currentEndpoint.dynamic) {
|
|
156
156
|
if (dynamicEndpoint.plugins) {
|
|
157
|
-
if (!
|
|
157
|
+
if (!await run(dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }))
|
|
158
158
|
continue;
|
|
159
159
|
return null;
|
|
160
160
|
}
|
|
@@ -167,12 +167,12 @@ const api = () => {
|
|
|
167
167
|
}
|
|
168
168
|
if (currentEndpoint.dynamic) {
|
|
169
169
|
for (const dynamicEndpoint of currentEndpoint.dynamic) {
|
|
170
|
-
endpointQueue.push([deep + 1, dynamicEndpoint,
|
|
170
|
+
endpointQueue.push([deep + 1, dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }]);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
for (const plugin of plugins) {
|
|
175
|
-
const result =
|
|
175
|
+
const result = await plugin();
|
|
176
176
|
if (result === undefined)
|
|
177
177
|
continue;
|
|
178
178
|
const newHandler = Object.create(handler);
|
|
@@ -180,7 +180,7 @@ const api = () => {
|
|
|
180
180
|
innet__default["default"](result, newHandler);
|
|
181
181
|
return null;
|
|
182
182
|
}
|
|
183
|
-
})
|
|
183
|
+
});
|
|
184
184
|
innet__default["default"](children, handler);
|
|
185
185
|
};
|
|
186
186
|
|
|
@@ -17,6 +17,11 @@ export interface EndpointProps {
|
|
|
17
17
|
* A method of the endpoint.
|
|
18
18
|
* */
|
|
19
19
|
method: EndpointsMethods;
|
|
20
|
+
/**
|
|
21
|
+
* `operationId` is an optional unique string used to identify an operation.
|
|
22
|
+
* If provided, these IDs must be unique among all operations described in your API.
|
|
23
|
+
* */
|
|
24
|
+
operationId?: string;
|
|
20
25
|
/**
|
|
21
26
|
* A relative path to an individual endpoint.
|
|
22
27
|
* The property MUST begin with a forward slash (/).
|
|
@@ -13,14 +13,13 @@ const endpoint = () => {
|
|
|
13
13
|
const tag = useTag();
|
|
14
14
|
const props = useProps();
|
|
15
15
|
const { docs, endpoints, } = useApi();
|
|
16
|
-
const { children, deprecated, description, method, path, private: privateMode, summary, } = props;
|
|
16
|
+
const { children, deprecated, description, method, operationId, path, private: privateMode, summary, } = props;
|
|
17
17
|
const { paths } = docs;
|
|
18
18
|
if (!paths)
|
|
19
19
|
throw Error('cannot find paths in docs');
|
|
20
20
|
if (!paths[path]) {
|
|
21
21
|
paths[path] = {};
|
|
22
22
|
}
|
|
23
|
-
// @ts-expect-error: it's always an object
|
|
24
23
|
if (paths[path][method]) {
|
|
25
24
|
throw Error(`You cannot use the same endpoints ${method}:${path}`);
|
|
26
25
|
}
|
|
@@ -28,6 +27,9 @@ const endpoint = () => {
|
|
|
28
27
|
if (summary) {
|
|
29
28
|
operation.summary = summary;
|
|
30
29
|
}
|
|
30
|
+
if (operationId) {
|
|
31
|
+
operation.operationId = operationId;
|
|
32
|
+
}
|
|
31
33
|
if (description) {
|
|
32
34
|
operation.description = description;
|
|
33
35
|
}
|
|
@@ -38,13 +40,11 @@ const endpoint = () => {
|
|
|
38
40
|
operation.tags = [tag.name];
|
|
39
41
|
}
|
|
40
42
|
if (!privateMode) {
|
|
41
|
-
// @ts-expect-error: it's always an object
|
|
42
43
|
paths[path][method] = operation;
|
|
43
44
|
}
|
|
44
45
|
if (!endpoints[method]) {
|
|
45
46
|
endpoints[method] = { key: '', plugins: new Set() };
|
|
46
47
|
}
|
|
47
|
-
// @ts-expect-error: it's always an object
|
|
48
48
|
const endpoint = getEndpoint(path, endpoints[method]);
|
|
49
49
|
// @ts-expect-error: it's always an object
|
|
50
50
|
endpointContext.set(handler, { endpoint, operation, props });
|
|
@@ -21,14 +21,13 @@ const endpoint = () => {
|
|
|
21
21
|
const tag = useTag.useTag();
|
|
22
22
|
const props = jsx.useProps();
|
|
23
23
|
const { docs, endpoints, } = useApi.useApi();
|
|
24
|
-
const { children, deprecated, description, method, path, private: privateMode, summary, } = props;
|
|
24
|
+
const { children, deprecated, description, method, operationId, path, private: privateMode, summary, } = props;
|
|
25
25
|
const { paths } = docs;
|
|
26
26
|
if (!paths)
|
|
27
27
|
throw Error('cannot find paths in docs');
|
|
28
28
|
if (!paths[path]) {
|
|
29
29
|
paths[path] = {};
|
|
30
30
|
}
|
|
31
|
-
// @ts-expect-error: it's always an object
|
|
32
31
|
if (paths[path][method]) {
|
|
33
32
|
throw Error(`You cannot use the same endpoints ${method}:${path}`);
|
|
34
33
|
}
|
|
@@ -36,6 +35,9 @@ const endpoint = () => {
|
|
|
36
35
|
if (summary) {
|
|
37
36
|
operation.summary = summary;
|
|
38
37
|
}
|
|
38
|
+
if (operationId) {
|
|
39
|
+
operation.operationId = operationId;
|
|
40
|
+
}
|
|
39
41
|
if (description) {
|
|
40
42
|
operation.description = description;
|
|
41
43
|
}
|
|
@@ -46,13 +48,11 @@ const endpoint = () => {
|
|
|
46
48
|
operation.tags = [tag.name];
|
|
47
49
|
}
|
|
48
50
|
if (!privateMode) {
|
|
49
|
-
// @ts-expect-error: it's always an object
|
|
50
51
|
paths[path][method] = operation;
|
|
51
52
|
}
|
|
52
53
|
if (!endpoints[method]) {
|
|
53
54
|
endpoints[method] = { key: '', plugins: new Set() };
|
|
54
55
|
}
|
|
55
|
-
// @ts-expect-error: it's always an object
|
|
56
56
|
const endpoint = getEndpoint.getEndpoint(path, endpoints[method]);
|
|
57
57
|
// @ts-expect-error: it's always an object
|
|
58
58
|
useEndpoint.endpointContext.set(handler, { endpoint, operation, props });
|
|
@@ -16,7 +16,9 @@ const host = () => {
|
|
|
16
16
|
target.servers = [];
|
|
17
17
|
}
|
|
18
18
|
const { servers } = operation || docs;
|
|
19
|
-
const server =
|
|
19
|
+
const server = {
|
|
20
|
+
...props,
|
|
21
|
+
};
|
|
20
22
|
// @ts-expect-error: FIXME
|
|
21
23
|
servers.push(server);
|
|
22
24
|
handler[hostContext.key] = { server };
|
|
@@ -24,7 +24,9 @@ const host = () => {
|
|
|
24
24
|
target.servers = [];
|
|
25
25
|
}
|
|
26
26
|
const { servers } = operation || docs;
|
|
27
|
-
const server =
|
|
27
|
+
const server = {
|
|
28
|
+
...props,
|
|
29
|
+
};
|
|
28
30
|
// @ts-expect-error: FIXME
|
|
29
31
|
servers.push(server);
|
|
30
32
|
handler[useHost.hostContext.key] = { server };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import innet, { useNewHandler } from 'innet';
|
|
3
2
|
import { useProps } from '@innet/jsx';
|
|
4
3
|
import '../../../hooks/index.es6.js';
|
|
@@ -25,8 +24,8 @@ const param = () => {
|
|
|
25
24
|
if (!operation.parameters) {
|
|
26
25
|
operation.parameters = [];
|
|
27
26
|
}
|
|
28
|
-
const
|
|
29
|
-
const params =
|
|
27
|
+
const { children, ...props } = useProps();
|
|
28
|
+
const params = { ...props };
|
|
30
29
|
if (props.in === 'path') {
|
|
31
30
|
params.required = (_a = params.required) !== null && _a !== void 0 ? _a : true;
|
|
32
31
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var innet = require('innet');
|
|
7
6
|
var jsx = require('@innet/jsx');
|
|
8
7
|
require('../../../hooks/index.js');
|
|
@@ -33,8 +32,8 @@ const param = () => {
|
|
|
33
32
|
if (!operation.parameters) {
|
|
34
33
|
operation.parameters = [];
|
|
35
34
|
}
|
|
36
|
-
const
|
|
37
|
-
const params =
|
|
35
|
+
const { children, ...props } = jsx.useProps();
|
|
36
|
+
const params = { ...props };
|
|
38
37
|
if (props.in === 'path') {
|
|
39
38
|
params.required = (_a = params.required) !== null && _a !== void 0 ? _a : true;
|
|
40
39
|
}
|
|
@@ -12,7 +12,11 @@ import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.
|
|
|
12
12
|
import { getOrAdd } from '../../../utils/getOrAdd/getOrAdd.es6.js';
|
|
13
13
|
import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
|
|
14
14
|
|
|
15
|
-
const statuses =
|
|
15
|
+
const statuses = {
|
|
16
|
+
...errorStatuses,
|
|
17
|
+
...redirectStatuses,
|
|
18
|
+
...successStatuses,
|
|
19
|
+
};
|
|
16
20
|
const response = () => {
|
|
17
21
|
var _a;
|
|
18
22
|
let { children, description = '', status = 'default', type = 'application/json', } = useProps() || {};
|
|
@@ -37,9 +41,12 @@ const response = () => {
|
|
|
37
41
|
description,
|
|
38
42
|
};
|
|
39
43
|
if (schema) {
|
|
40
|
-
response.content =
|
|
44
|
+
response.content = {
|
|
45
|
+
...defaultResponse === null || defaultResponse === void 0 ? void 0 : defaultResponse.content,
|
|
46
|
+
[type]: {
|
|
41
47
|
schema,
|
|
42
|
-
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
43
50
|
}
|
|
44
51
|
operation.responses[status] = response;
|
|
45
52
|
schemaContext.set(handler, schema);
|
|
@@ -20,7 +20,11 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
20
|
|
|
21
21
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
22
22
|
|
|
23
|
-
const statuses =
|
|
23
|
+
const statuses = {
|
|
24
|
+
...error.errorStatuses,
|
|
25
|
+
...redirect.redirectStatuses,
|
|
26
|
+
...success.successStatuses,
|
|
27
|
+
};
|
|
24
28
|
const response = () => {
|
|
25
29
|
var _a;
|
|
26
30
|
let { children, description = '', status = 'default', type = 'application/json', } = jsx.useProps() || {};
|
|
@@ -45,9 +49,12 @@ const response = () => {
|
|
|
45
49
|
description,
|
|
46
50
|
};
|
|
47
51
|
if (schema) {
|
|
48
|
-
response.content =
|
|
52
|
+
response.content = {
|
|
53
|
+
...defaultResponse === null || defaultResponse === void 0 ? void 0 : defaultResponse.content,
|
|
54
|
+
[type]: {
|
|
49
55
|
schema,
|
|
50
|
-
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
51
58
|
}
|
|
52
59
|
operation.responses[status] = response;
|
|
53
60
|
useSchemaContext.schemaContext.set(handler, schema);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
1
|
import innet, { useNewHandler } from 'innet';
|
|
3
2
|
import { useProps } from '@innet/jsx';
|
|
4
3
|
import fs from 'node:fs';
|
|
@@ -56,15 +55,13 @@ const server = () => {
|
|
|
56
55
|
const requestHandler = Object.create(handler);
|
|
57
56
|
actionContext.set(requestHandler, action);
|
|
58
57
|
requestHandlerContext.set(requestHandler, requestHandler);
|
|
59
|
-
function server() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
58
|
+
async function server() {
|
|
59
|
+
for (const plugin of plugins) {
|
|
60
|
+
const result = await plugin();
|
|
61
|
+
if (result !== undefined) {
|
|
62
|
+
return result;
|
|
66
63
|
}
|
|
67
|
-
}
|
|
64
|
+
}
|
|
68
65
|
}
|
|
69
66
|
innet({ props, type: server }, requestHandler);
|
|
70
67
|
});
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var innet = require('innet');
|
|
7
6
|
var jsx = require('@innet/jsx');
|
|
8
7
|
var fs = require('node:fs');
|
|
@@ -67,15 +66,13 @@ const server = () => {
|
|
|
67
66
|
const requestHandler = Object.create(handler);
|
|
68
67
|
useAction.actionContext.set(requestHandler, action);
|
|
69
68
|
useRequestHandler.requestHandlerContext.set(requestHandler, requestHandler);
|
|
70
|
-
function server() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
69
|
+
async function server() {
|
|
70
|
+
for (const plugin of plugins) {
|
|
71
|
+
const result = await plugin();
|
|
72
|
+
if (result !== undefined) {
|
|
73
|
+
return result;
|
|
77
74
|
}
|
|
78
|
-
}
|
|
75
|
+
}
|
|
79
76
|
}
|
|
80
77
|
innet__default["default"]({ props, type: server }, requestHandler);
|
|
81
78
|
});
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { useProps } from '@innet/jsx';
|
|
3
2
|
import '../../../hooks/index.es6.js';
|
|
4
3
|
import { useHost } from '../../../hooks/useHost/useHost.es6.js';
|
|
5
4
|
|
|
6
5
|
const variable = () => {
|
|
7
6
|
const { server } = useHost();
|
|
8
|
-
const
|
|
7
|
+
const { key, values,
|
|
9
8
|
// predefine
|
|
10
|
-
value = values === null || values === void 0 ? void 0 : values[0]
|
|
9
|
+
value = values === null || values === void 0 ? void 0 : values[0], ...rest } = useProps();
|
|
11
10
|
if (!server.variables) {
|
|
12
11
|
server.variables = {};
|
|
13
12
|
}
|
|
14
13
|
// @ts-expect-error: FIXME
|
|
15
|
-
server.variables[key] =
|
|
14
|
+
server.variables[key] = { ...rest, default: value, enum: values };
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
export { variable };
|
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var jsx = require('@innet/jsx');
|
|
7
6
|
require('../../../hooks/index.js');
|
|
8
7
|
var useHost = require('../../../hooks/useHost/useHost.js');
|
|
9
8
|
|
|
10
9
|
const variable = () => {
|
|
11
10
|
const { server } = useHost.useHost();
|
|
12
|
-
const
|
|
11
|
+
const { key, values,
|
|
13
12
|
// predefine
|
|
14
|
-
value = values === null || values === void 0 ? void 0 : values[0]
|
|
13
|
+
value = values === null || values === void 0 ? void 0 : values[0], ...rest } = jsx.useProps();
|
|
15
14
|
if (!server.variables) {
|
|
16
15
|
server.variables = {};
|
|
17
16
|
}
|
|
18
17
|
// @ts-expect-error: FIXME
|
|
19
|
-
server.variables[key] =
|
|
18
|
+
server.variables[key] = { ...rest, default: value, enum: values };
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
exports.variable = variable;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
import { type
|
|
3
|
-
export interface CookieProps extends
|
|
2
|
+
import { type Cookies } from 'cookie';
|
|
3
|
+
export interface CookieProps extends Cookies {
|
|
4
4
|
key: string;
|
|
5
5
|
value?: string;
|
|
6
6
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { useProps } from '@innet/jsx';
|
|
3
2
|
import '../../../hooks/index.es6.js';
|
|
4
3
|
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
5
4
|
|
|
6
5
|
const cookie = () => {
|
|
7
6
|
const action = useAction();
|
|
8
|
-
const
|
|
7
|
+
const { key, value, ...opt } = useProps();
|
|
9
8
|
action.setCookie(key, value, opt);
|
|
10
9
|
};
|
|
11
10
|
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var jsx = require('@innet/jsx');
|
|
7
6
|
require('../../../hooks/index.js');
|
|
8
7
|
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
9
8
|
|
|
10
9
|
const cookie = () => {
|
|
11
10
|
const action = useAction.useAction();
|
|
12
|
-
const
|
|
11
|
+
const { key, value, ...opt } = jsx.useProps();
|
|
13
12
|
action.setCookie(key, value, opt);
|
|
14
13
|
};
|
|
15
14
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { useProps } from '@innet/jsx';
|
|
3
2
|
import '../../../hooks/index.es6.js';
|
|
4
3
|
import '../../../utils/index.es6.js';
|
|
@@ -59,7 +58,7 @@ const errorStatuses = {
|
|
|
59
58
|
webServerIsDown: 521,
|
|
60
59
|
};
|
|
61
60
|
const error = () => {
|
|
62
|
-
const
|
|
61
|
+
const { children, ...props } = useProps();
|
|
63
62
|
const res = useResponse();
|
|
64
63
|
if (!res) {
|
|
65
64
|
throw Error('<error> MUST be in <request>');
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var jsx = require('@innet/jsx');
|
|
7
6
|
require('../../../hooks/index.js');
|
|
8
7
|
require('../../../utils/index.js');
|
|
@@ -63,7 +62,7 @@ const errorStatuses = {
|
|
|
63
62
|
webServerIsDown: 521,
|
|
64
63
|
};
|
|
65
64
|
const error = () => {
|
|
66
|
-
const
|
|
65
|
+
const { children, ...props } = jsx.useProps();
|
|
67
66
|
const res = useResponse.useResponse();
|
|
68
67
|
if (!res) {
|
|
69
68
|
throw Error('<error> MUST be in <request>');
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import innet, { useHandler } from 'innet';
|
|
3
2
|
import { useProps } from '@innet/jsx';
|
|
4
3
|
import fs from 'node:fs';
|
|
@@ -9,7 +8,7 @@ import { useThrow } from '../../../hooks/useThrow/useThrow.es6.js';
|
|
|
9
8
|
|
|
10
9
|
function file() {
|
|
11
10
|
const handler = useHandler();
|
|
12
|
-
const
|
|
11
|
+
const { children, ...props } = useProps();
|
|
13
12
|
const res = useResponse();
|
|
14
13
|
if (!res) {
|
|
15
14
|
useThrow('<{type}> MUST be in <request> or <fallback>');
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var innet = require('innet');
|
|
7
6
|
var jsx = require('@innet/jsx');
|
|
8
7
|
var fs = require('node:fs');
|
|
@@ -19,7 +18,7 @@ var mime__default = /*#__PURE__*/_interopDefaultLegacy(mime);
|
|
|
19
18
|
|
|
20
19
|
function file() {
|
|
21
20
|
const handler = innet.useHandler();
|
|
22
|
-
const
|
|
21
|
+
const { children, ...props } = jsx.useProps();
|
|
23
22
|
const res = useResponse.useResponse();
|
|
24
23
|
if (!res) {
|
|
25
24
|
useThrow.useThrow('<{type}> MUST be in <request> or <fallback>');
|