@innet/server 2.0.0-beta.1 → 2.0.0-beta.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.
- 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/README.md
CHANGED
|
@@ -1396,6 +1396,28 @@ export default (
|
|
|
1396
1396
|
)
|
|
1397
1397
|
```
|
|
1398
1398
|
|
|
1399
|
+
#### operationId
|
|
1400
|
+
|
|
1401
|
+
`operationId` is an optional unique string used to identify an operation.
|
|
1402
|
+
If provided, these IDs must be unique among all operations described in your API.
|
|
1403
|
+
|
|
1404
|
+
Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions.
|
|
1405
|
+
|
|
1406
|
+
*src/app.tsx*
|
|
1407
|
+
```typescript jsx
|
|
1408
|
+
export default (
|
|
1409
|
+
<server>
|
|
1410
|
+
<api>
|
|
1411
|
+
<endpoint
|
|
1412
|
+
method='get'
|
|
1413
|
+
path='/users'
|
|
1414
|
+
operationId='getUsers'
|
|
1415
|
+
/>
|
|
1416
|
+
</api>
|
|
1417
|
+
</server>
|
|
1418
|
+
)
|
|
1419
|
+
```
|
|
1420
|
+
|
|
1399
1421
|
### \<tag>
|
|
1400
1422
|
|
|
1401
1423
|
[← back](#endpoints)
|
package/handler/handler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type JSXElement } from '@innet/jsx';
|
|
2
2
|
import { arraySync, async } from '@innet/utils';
|
|
3
3
|
import { type AnyProps, type ApiProps, type ArrayProps, type BinaryProps, blacklist, type BlacklistProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DtsProps, type EndpointProps, type EnvProps, type ErrorProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, preset, type PresetProps, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type ResponseProps, type ReturnProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps, whitelist, type WhitelistProps } from '../plugins';
|
|
4
4
|
export declare const arrayPlugins: (typeof arraySync)[];
|
|
@@ -12,7 +12,6 @@ export declare const JSXPlugins: {
|
|
|
12
12
|
boolean: import("innet").HandlerPlugin;
|
|
13
13
|
cms: typeof cms;
|
|
14
14
|
contact: import("innet").HandlerPlugin;
|
|
15
|
-
context: typeof context;
|
|
16
15
|
cookie: import("innet").HandlerPlugin;
|
|
17
16
|
date: import("innet").HandlerPlugin;
|
|
18
17
|
dts: import("innet").HandlerPlugin;
|
|
@@ -36,8 +35,6 @@ export declare const JSXPlugins: {
|
|
|
36
35
|
response: import("innet").HandlerPlugin;
|
|
37
36
|
return: import("innet").HandlerPlugin;
|
|
38
37
|
server: import("innet").HandlerPlugin;
|
|
39
|
-
slot: typeof slot;
|
|
40
|
-
slots: typeof slots;
|
|
41
38
|
string: import("innet").HandlerPlugin;
|
|
42
39
|
success: import("innet").HandlerPlugin;
|
|
43
40
|
swagger: import("innet").HandlerPlugin;
|
|
@@ -70,7 +67,6 @@ declare global {
|
|
|
70
67
|
boolean: BooleanProps;
|
|
71
68
|
cms: CmsProps;
|
|
72
69
|
contact: ContactProps;
|
|
73
|
-
context: ContextProps;
|
|
74
70
|
cookie: CookieProps;
|
|
75
71
|
date: DateProps;
|
|
76
72
|
dts: DtsProps;
|
|
@@ -94,8 +90,6 @@ declare global {
|
|
|
94
90
|
response: ResponseProps;
|
|
95
91
|
return: ReturnProps;
|
|
96
92
|
server: ServerProps;
|
|
97
|
-
slot: SlotProps;
|
|
98
|
-
slots: SlotsProps;
|
|
99
93
|
string: StringProps;
|
|
100
94
|
success: SuccessProps;
|
|
101
95
|
swagger: SwaggerProps;
|
package/handler/handler.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHandler } from 'innet';
|
|
2
|
-
import {
|
|
2
|
+
import { jsxPlugins, jsxComponent } from '@innet/jsx';
|
|
3
3
|
import { arraySync, async, promise, array as array$1, nullish, object as object$1, fn } from '@innet/utils';
|
|
4
4
|
import '../plugins/index.es6.js';
|
|
5
5
|
import { any } from '../plugins/schema/any/any.es6.js';
|
|
@@ -57,7 +57,6 @@ const JSXPlugins = {
|
|
|
57
57
|
boolean,
|
|
58
58
|
cms,
|
|
59
59
|
contact,
|
|
60
|
-
context,
|
|
61
60
|
cookie,
|
|
62
61
|
date,
|
|
63
62
|
dts,
|
|
@@ -81,8 +80,6 @@ const JSXPlugins = {
|
|
|
81
80
|
response,
|
|
82
81
|
return: returnPlugin,
|
|
83
82
|
server,
|
|
84
|
-
slot,
|
|
85
|
-
slots,
|
|
86
83
|
string,
|
|
87
84
|
success,
|
|
88
85
|
swagger,
|
package/handler/handler.js
CHANGED
|
@@ -61,7 +61,6 @@ const JSXPlugins = {
|
|
|
61
61
|
boolean: boolean.boolean,
|
|
62
62
|
cms: cms.cms,
|
|
63
63
|
contact: contact.contact,
|
|
64
|
-
context: jsx.context,
|
|
65
64
|
cookie: cookie.cookie,
|
|
66
65
|
date: date.date,
|
|
67
66
|
dts: dts.dts,
|
|
@@ -85,8 +84,6 @@ const JSXPlugins = {
|
|
|
85
84
|
response: response.response,
|
|
86
85
|
return: _return.returnPlugin,
|
|
87
86
|
server: server.server,
|
|
88
|
-
slot: jsx.slot,
|
|
89
|
-
slots: jsx.slots,
|
|
90
87
|
string: string.string,
|
|
91
88
|
success: success.success,
|
|
92
89
|
swagger: swagger.swagger,
|
|
@@ -15,7 +15,7 @@ function useNewSchema(schema = Object.create(null)) {
|
|
|
15
15
|
parentSchema.oneOf.push(schema);
|
|
16
16
|
}
|
|
17
17
|
else if (parentSchema.type || '$ref' in parentSchema) {
|
|
18
|
-
const oldSchema =
|
|
18
|
+
const oldSchema = { ...parentSchema };
|
|
19
19
|
for (const key in parentSchema) {
|
|
20
20
|
// @ts-expect-error: FIXME
|
|
21
21
|
delete parentSchema[key];
|
|
@@ -19,7 +19,7 @@ function useNewSchema(schema = Object.create(null)) {
|
|
|
19
19
|
parentSchema.oneOf.push(schema);
|
|
20
20
|
}
|
|
21
21
|
else if (parentSchema.type || '$ref' in parentSchema) {
|
|
22
|
-
const oldSchema =
|
|
22
|
+
const oldSchema = { ...parentSchema };
|
|
23
23
|
for (const key in parentSchema) {
|
|
24
24
|
// @ts-expect-error: FIXME
|
|
25
25
|
delete parentSchema[key];
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import '../useApi/index.es6.js';
|
|
3
2
|
import '../useNewSchema/index.es6.js';
|
|
4
3
|
import { useApi } from '../useApi/useApi.es6.js';
|
|
5
4
|
import { useNewSchema } from '../useNewSchema/useNewSchema.es6.js';
|
|
6
5
|
|
|
7
|
-
function useSchemaType(type,
|
|
8
|
-
var
|
|
9
|
-
var { example, examples, ref, values } = _a, options = __rest(_a, ["example", "examples", "ref", "values"]);
|
|
6
|
+
function useSchemaType(type, { example, examples, ref, values, ...options } = {}) {
|
|
7
|
+
var _a;
|
|
10
8
|
if (ref) {
|
|
11
9
|
const { docs } = useApi();
|
|
12
10
|
if (!docs.components) {
|
|
@@ -18,14 +16,24 @@ function useSchemaType(type, _a = {}) {
|
|
|
18
16
|
useNewSchema({
|
|
19
17
|
$ref: `#/components/schemas/${ref}`,
|
|
20
18
|
});
|
|
21
|
-
if ((
|
|
19
|
+
if ((_a = docs.components.schemas) === null || _a === void 0 ? void 0 : _a[ref]) {
|
|
22
20
|
return;
|
|
23
21
|
}
|
|
24
|
-
return (docs.components.schemas[ref] =
|
|
25
|
-
|
|
22
|
+
return (docs.components.schemas[ref] = {
|
|
23
|
+
...options,
|
|
24
|
+
enum: values,
|
|
25
|
+
example,
|
|
26
|
+
examples,
|
|
27
|
+
type: type === 'any' ? undefined : type,
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
|
-
return useNewSchema(
|
|
28
|
-
|
|
30
|
+
return useNewSchema({
|
|
31
|
+
...options,
|
|
32
|
+
enum: values,
|
|
33
|
+
example,
|
|
34
|
+
examples,
|
|
35
|
+
type: type === 'any' ? undefined : type,
|
|
36
|
+
});
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
export { useSchemaType };
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
require('../useApi/index.js');
|
|
7
6
|
require('../useNewSchema/index.js');
|
|
8
7
|
var useApi = require('../useApi/useApi.js');
|
|
9
8
|
var useNewSchema = require('../useNewSchema/useNewSchema.js');
|
|
10
9
|
|
|
11
|
-
function useSchemaType(type,
|
|
12
|
-
var
|
|
13
|
-
var { example, examples, ref, values } = _a, options = tslib.__rest(_a, ["example", "examples", "ref", "values"]);
|
|
10
|
+
function useSchemaType(type, { example, examples, ref, values, ...options } = {}) {
|
|
11
|
+
var _a;
|
|
14
12
|
if (ref) {
|
|
15
13
|
const { docs } = useApi.useApi();
|
|
16
14
|
if (!docs.components) {
|
|
@@ -22,14 +20,24 @@ function useSchemaType(type, _a = {}) {
|
|
|
22
20
|
useNewSchema.useNewSchema({
|
|
23
21
|
$ref: `#/components/schemas/${ref}`,
|
|
24
22
|
});
|
|
25
|
-
if ((
|
|
23
|
+
if ((_a = docs.components.schemas) === null || _a === void 0 ? void 0 : _a[ref]) {
|
|
26
24
|
return;
|
|
27
25
|
}
|
|
28
|
-
return (docs.components.schemas[ref] =
|
|
29
|
-
|
|
26
|
+
return (docs.components.schemas[ref] = {
|
|
27
|
+
...options,
|
|
28
|
+
enum: values,
|
|
29
|
+
example,
|
|
30
|
+
examples,
|
|
31
|
+
type: type === 'any' ? undefined : type,
|
|
32
|
+
});
|
|
30
33
|
}
|
|
31
|
-
return useNewSchema.useNewSchema(
|
|
32
|
-
|
|
34
|
+
return useNewSchema.useNewSchema({
|
|
35
|
+
...options,
|
|
36
|
+
enum: values,
|
|
37
|
+
example,
|
|
38
|
+
examples,
|
|
39
|
+
type: type === 'any' ? undefined : type,
|
|
40
|
+
});
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
exports.useSchemaType = useSchemaType;
|
package/index.es6.js
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innet/server",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "Create server-side application with innet",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.es6.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/d8corp/innet-server.git"
|
|
24
|
+
"url": "git+https://github.com/d8corp/innet-server.git"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"innet",
|
|
@@ -35,23 +35,23 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/d8corp/innet-server",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@cantinc/utils": "^1.4.
|
|
39
|
-
"@innet/jsx": "
|
|
40
|
-
"@innet/utils": "
|
|
41
|
-
"@types/cookie": "^0.
|
|
42
|
-
"@types/multiparty": "^
|
|
43
|
-
"@types/qs": "^6.
|
|
44
|
-
"cookie": "^
|
|
38
|
+
"@cantinc/utils": "^1.4.4",
|
|
39
|
+
"@innet/jsx": "2.0.0-beta.4",
|
|
40
|
+
"@innet/utils": "2.0.0-alpha.1",
|
|
41
|
+
"@types/cookie": "^1.0.0",
|
|
42
|
+
"@types/multiparty": "^4.2.1",
|
|
43
|
+
"@types/qs": "^6.15.0",
|
|
44
|
+
"cookie": "^1.1.1",
|
|
45
45
|
"http-proxy": "^1.18.1",
|
|
46
|
-
"innet": "
|
|
47
|
-
"mime": "^
|
|
46
|
+
"innet": "2.0.0-alpha.3",
|
|
47
|
+
"mime": "^4.1.0",
|
|
48
48
|
"multiparty": "^4.2.3",
|
|
49
49
|
"openapi-types": "^12.1.3",
|
|
50
|
-
"qs": "^6.
|
|
50
|
+
"qs": "^6.15.0",
|
|
51
51
|
"request-ip": "^3.3.0",
|
|
52
52
|
"string_decoder": "^1.3.0",
|
|
53
|
-
"tslib": "^2.
|
|
54
|
-
"uuid": "^
|
|
55
|
-
"watch-state": "^3.
|
|
53
|
+
"tslib": "^2.8.1",
|
|
54
|
+
"uuid": "^13.0.0",
|
|
55
|
+
"watch-state": "^3.6.2"
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest, __awaiter } from 'tslib';
|
|
2
1
|
import innet, { useNewHandler } from 'innet';
|
|
3
2
|
import { useProps } from '@innet/jsx';
|
|
4
3
|
import '../../../hooks/index.es6.js';
|
|
@@ -15,8 +14,8 @@ import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
|
|
|
15
14
|
const api = () => {
|
|
16
15
|
const handler = useNewHandler();
|
|
17
16
|
const props = useProps();
|
|
18
|
-
const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0'
|
|
19
|
-
const info =
|
|
17
|
+
const { children, exclude, include, prefix = process.env.INNET_API_PREFIX || '', title = '', version = process.env.INNET_API_VERSION || '0.0.0', ...rest } = props;
|
|
18
|
+
const info = { ...rest, title, version };
|
|
20
19
|
const endpoints = {};
|
|
21
20
|
const docs = {
|
|
22
21
|
info,
|
|
@@ -38,7 +37,7 @@ const api = () => {
|
|
|
38
37
|
};
|
|
39
38
|
serverPlugins.set(handler, plugins);
|
|
40
39
|
apiContext.set(handler, context);
|
|
41
|
-
useServerPlugin(() =>
|
|
40
|
+
useServerPlugin(async () => {
|
|
42
41
|
var _a, _b, _c, _d, _e, _f;
|
|
43
42
|
const action = useAction();
|
|
44
43
|
if (!condition(action))
|
|
@@ -62,91 +61,92 @@ const api = () => {
|
|
|
62
61
|
const [deep, currentEndpoint, params] = endpointQueue.shift();
|
|
63
62
|
const key = splitPath[deep];
|
|
64
63
|
if (deep + 1 === splitPath.length) {
|
|
65
|
-
function run(runEndpoint, params) {
|
|
64
|
+
async function run(runEndpoint, params) {
|
|
66
65
|
var _a, _b, _c, _d, _e;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Object.assign(params, pathRules(params, { in: 'path' }));
|
|
76
|
-
}
|
|
77
|
-
catch (_f) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
66
|
+
const pathRules = (_a = runEndpoint.rules) === null || _a === void 0 ? void 0 : _a.path;
|
|
67
|
+
const headerRules = (_b = runEndpoint.rules) === null || _b === void 0 ? void 0 : _b.header;
|
|
68
|
+
const cookieRules = (_c = runEndpoint.rules) === null || _c === void 0 ? void 0 : _c.cookie;
|
|
69
|
+
const searchRules = (_d = runEndpoint.rules) === null || _d === void 0 ? void 0 : _d.search;
|
|
70
|
+
const bodyRules = (_e = runEndpoint.rules) === null || _e === void 0 ? void 0 : _e.body;
|
|
71
|
+
if (pathRules) {
|
|
72
|
+
try {
|
|
73
|
+
Object.assign(params, pathRules(params, { in: 'path' }));
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
if (rules) {
|
|
83
|
-
try {
|
|
84
|
-
action[key] = rules(action[key]);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
res.setHeader('Content-Type', 'application/json');
|
|
88
|
-
if (e instanceof RulesError) {
|
|
89
|
-
res.statusCode = 400;
|
|
90
|
-
res.write(JSONString({
|
|
91
|
-
data: Object.assign(Object.assign({}, e.data), { in: key }),
|
|
92
|
-
error: 'requestValidation',
|
|
93
|
-
}));
|
|
94
|
-
res.end();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
console.error(e);
|
|
98
|
-
res.statusCode = 500;
|
|
99
|
-
res.write(JSONString({
|
|
100
|
-
data: { in: key },
|
|
101
|
-
error: 'unknown',
|
|
102
|
-
}));
|
|
103
|
-
res.end();
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
75
|
+
catch (_f) {
|
|
108
76
|
return false;
|
|
109
77
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
yield action.parseBody();
|
|
118
|
-
if (!action.body) {
|
|
119
|
-
res.statusCode = 400;
|
|
78
|
+
}
|
|
79
|
+
function checkActionRules(rules, key = 'search') {
|
|
80
|
+
if (rules) {
|
|
81
|
+
try {
|
|
82
|
+
action[key] = rules(action[key]);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
120
85
|
res.setHeader('Content-Type', 'application/json');
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
86
|
+
if (e instanceof RulesError) {
|
|
87
|
+
res.statusCode = 400;
|
|
88
|
+
res.write(JSONString({
|
|
89
|
+
data: {
|
|
90
|
+
...e.data,
|
|
91
|
+
in: key,
|
|
92
|
+
},
|
|
93
|
+
error: 'requestValidation',
|
|
94
|
+
}));
|
|
95
|
+
res.end();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.error(e);
|
|
99
|
+
res.statusCode = 500;
|
|
100
|
+
res.write(JSONString({
|
|
101
|
+
data: { in: key },
|
|
102
|
+
error: 'unknown',
|
|
103
|
+
}));
|
|
104
|
+
res.end();
|
|
105
|
+
}
|
|
125
106
|
return true;
|
|
126
107
|
}
|
|
127
|
-
if (checkActionRules(bodyRules, 'body'))
|
|
128
|
-
return true;
|
|
129
108
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (checkActionRules(headerRules, 'headers'))
|
|
112
|
+
return true;
|
|
113
|
+
if (checkActionRules(cookieRules, 'cookies'))
|
|
114
|
+
return true;
|
|
115
|
+
if (checkActionRules(searchRules, 'search'))
|
|
116
|
+
return true;
|
|
117
|
+
if (bodyRules) {
|
|
118
|
+
await action.parseBody();
|
|
119
|
+
if (!action.body) {
|
|
120
|
+
res.statusCode = 400;
|
|
121
|
+
res.setHeader('Content-Type', 'application/json');
|
|
122
|
+
res.write(JSONString({
|
|
123
|
+
error: 'requestBodyContentType',
|
|
124
|
+
}));
|
|
125
|
+
res.end();
|
|
136
126
|
return true;
|
|
137
127
|
}
|
|
128
|
+
if (checkActionRules(bodyRules, 'body'))
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
paramsContext.set(actionHandler, params);
|
|
132
|
+
for (const plugin of runEndpoint.plugins) {
|
|
133
|
+
const result = await plugin();
|
|
134
|
+
if (result === undefined)
|
|
135
|
+
continue;
|
|
136
|
+
innet(result, actionHandler);
|
|
138
137
|
return true;
|
|
139
|
-
}
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
140
|
}
|
|
141
141
|
if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
|
|
142
|
-
if (!
|
|
142
|
+
if (!await run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params))
|
|
143
143
|
continue;
|
|
144
144
|
return null;
|
|
145
145
|
}
|
|
146
146
|
if (currentEndpoint.dynamic) {
|
|
147
147
|
for (const dynamicEndpoint of currentEndpoint.dynamic) {
|
|
148
148
|
if (dynamicEndpoint.plugins) {
|
|
149
|
-
if (!
|
|
149
|
+
if (!await run(dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }))
|
|
150
150
|
continue;
|
|
151
151
|
return null;
|
|
152
152
|
}
|
|
@@ -159,12 +159,12 @@ const api = () => {
|
|
|
159
159
|
}
|
|
160
160
|
if (currentEndpoint.dynamic) {
|
|
161
161
|
for (const dynamicEndpoint of currentEndpoint.dynamic) {
|
|
162
|
-
endpointQueue.push([deep + 1, dynamicEndpoint,
|
|
162
|
+
endpointQueue.push([deep + 1, dynamicEndpoint, { ...params, [dynamicEndpoint.key.slice(1, -1)]: key }]);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
for (const plugin of plugins) {
|
|
167
|
-
const result =
|
|
167
|
+
const result = await plugin();
|
|
168
168
|
if (result === undefined)
|
|
169
169
|
continue;
|
|
170
170
|
const newHandler = Object.create(handler);
|
|
@@ -172,7 +172,7 @@ const api = () => {
|
|
|
172
172
|
innet(result, newHandler);
|
|
173
173
|
return null;
|
|
174
174
|
}
|
|
175
|
-
})
|
|
175
|
+
});
|
|
176
176
|
innet(children, handler);
|
|
177
177
|
};
|
|
178
178
|
|