@innet/server 2.0.0-beta.1 → 2.0.0-beta.10
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 +385 -9
- package/handler/handler.d.ts +6 -9
- package/handler/handler.es6.js +3 -4
- package/handler/handler.js +2 -3
- package/hooks/index.d.ts +24 -23
- package/hooks/index.es6.js +24 -23
- package/hooks/index.js +24 -23
- package/hooks/useEffect/index.d.ts +1 -0
- package/hooks/useEffect/index.es6.js +1 -0
- package/hooks/useEffect/index.js +9 -0
- package/hooks/useEffect/useEffect.d.ts +2 -0
- package/hooks/useEffect/useEffect.es6.js +8 -0
- package/hooks/useEffect/useEffect.js +12 -0
- 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.d.ts +2 -2
- package/index.es6.js +88 -86
- package/index.js +201 -194
- package/package.json +16 -15
- package/plugins/handler/serverFn/serverFn.es6.js +2 -2
- package/plugins/handler/serverFn/serverFn.js +2 -6
- package/plugins/index.d.ts +2 -2
- package/plugins/index.es6.js +2 -2
- package/plugins/index.js +2 -2
- package/plugins/main/api/api.es6.js +74 -74
- package/plugins/main/api/api.js +75 -79
- package/plugins/main/body/body.es6.js +4 -4
- package/plugins/main/body/body.js +4 -8
- package/plugins/main/endpoint/endpoint.d.ts +5 -0
- package/plugins/main/endpoint/endpoint.es6.js +5 -5
- package/plugins/main/endpoint/endpoint.js +5 -9
- package/plugins/main/host/host.es6.js +4 -2
- package/plugins/main/host/host.js +4 -6
- package/plugins/main/index.d.ts +8 -8
- package/plugins/main/index.es6.js +8 -8
- package/plugins/main/index.js +8 -8
- package/plugins/main/param/param.es6.js +3 -4
- package/plugins/main/param/param.js +3 -8
- package/plugins/main/preset/preset.es6.js +1 -1
- package/plugins/main/preset/preset.js +1 -5
- package/plugins/main/response/response.es6.js +11 -4
- package/plugins/main/response/response.js +11 -8
- package/plugins/main/server/server.d.ts +0 -1
- package/plugins/main/server/server.es6.js +7 -10
- package/plugins/main/server/server.js +8 -12
- package/plugins/main/tag/index.es6.js +1 -1
- package/plugins/main/tag/index.js +1 -0
- package/plugins/main/tag/tag.d.ts +8 -1
- package/plugins/main/tag/tag.es6.js +20 -3
- package/plugins/main/tag/tag.js +20 -6
- package/plugins/main/variable/variable.es6.js +3 -4
- package/plugins/main/variable/variable.js +3 -4
- package/plugins/request/cms/cms.es6.js +1 -1
- package/plugins/request/cms/cms.js +2 -3
- 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 +2 -3
- package/plugins/request/file/file.js +2 -4
- package/plugins/request/index.d.ts +5 -5
- package/plugins/request/index.es6.js +5 -5
- package/plugins/request/index.js +5 -5
- package/plugins/request/proxy/proxy.d.ts +0 -1
- package/plugins/schema/array/array.d.ts +3 -0
- package/plugins/schema/array/array.es6.js +14 -6
- package/plugins/schema/array/array.js +15 -11
- package/plugins/schema/binary/binary.d.ts +4 -0
- package/plugins/schema/boolean/boolean.d.ts +1 -0
- package/plugins/schema/date/date.d.ts +2 -1
- package/plugins/schema/date/date.es6.js +8 -4
- package/plugins/schema/date/date.js +8 -4
- package/plugins/schema/field/field.d.ts +4 -0
- package/plugins/schema/field/field.es6.js +16 -3
- package/plugins/schema/field/field.js +16 -7
- package/plugins/schema/index.d.ts +8 -8
- package/plugins/schema/index.es6.js +8 -8
- package/plugins/schema/index.js +8 -8
- package/plugins/schema/integer/integer.d.ts +37 -0
- package/plugins/schema/integer/integer.es6.js +29 -9
- package/plugins/schema/integer/integer.js +29 -9
- package/plugins/schema/number/number.d.ts +32 -0
- package/plugins/schema/number/number.es6.js +21 -6
- package/plugins/schema/number/number.js +21 -6
- package/plugins/schema/object/object.es6.js +9 -8
- package/plugins/schema/object/object.js +9 -12
- package/plugins/schema/string/string.d.ts +27 -0
- package/plugins/schema/string/string.es6.js +9 -4
- package/plugins/schema/string/string.js +9 -4
- package/plugins/schema/tuple/tuple.es6.js +5 -6
- package/plugins/schema/tuple/tuple.js +5 -10
- package/plugins/schema/uuid/uuid.es6.js +5 -3
- package/plugins/schema/uuid/uuid.js +5 -3
- package/plugins/utils/dts/dts.es6.js +5 -2
- package/plugins/utils/dts/dts.js +5 -2
- package/plugins/utils/env/env.es6.js +1 -1
- package/plugins/utils/env/env.js +1 -5
- package/plugins/utils/index.d.ts +3 -2
- package/plugins/utils/index.es6.js +3 -2
- package/plugins/utils/index.js +3 -2
- package/plugins/utils/swagger/swagger.d.ts +1 -0
- package/plugins/utils/swagger/swagger.es6.js +1 -0
- package/plugins/utils/swagger/swagger.js +1 -0
- package/plugins/utils/ui/index.d.ts +1 -0
- package/plugins/utils/ui/index.es6.js +1 -0
- package/plugins/utils/ui/index.js +10 -0
- package/plugins/utils/ui/rapidoc.html.es6.js +3 -0
- package/plugins/utils/ui/rapidoc.html.js +7 -0
- package/plugins/utils/ui/redoc.html.es6.js +3 -0
- package/plugins/utils/ui/redoc.html.js +7 -0
- package/plugins/utils/ui/scalar.html.es6.js +3 -0
- package/plugins/utils/ui/scalar.html.js +7 -0
- package/plugins/utils/ui/swagger.html.es6.js +3 -0
- package/plugins/utils/ui/swagger.html.js +7 -0
- package/plugins/utils/ui/ui.d.ts +13 -0
- package/plugins/utils/ui/ui.es6.js +45 -0
- package/plugins/utils/ui/ui.js +50 -0
- package/types.d.ts +6 -0
- 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/getSafeSchema/getSafeSchema.d.ts +2 -0
- package/utils/getSafeSchema/getSafeSchema.es6.js +5 -0
- package/utils/getSafeSchema/getSafeSchema.js +9 -0
- package/utils/getSafeSchema/index.d.ts +1 -0
- package/utils/getSafeSchema/index.es6.js +1 -0
- package/utils/getSafeSchema/index.js +9 -0
- package/utils/index.d.ts +9 -8
- package/utils/index.es6.js +9 -8
- package/utils/index.js +9 -8
- 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/index.d.ts +17 -17
- package/utils/rules/index.es6.js +17 -17
- package/utils/rules/index.js +18 -18
- 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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var scalar = "<!doctype html>\n<html>\n<head>\n <title>API Reference</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />\n</head>\n<body>\n<div id=\"app\"></div>\n<script src=\"https://cdn.jsdelivr.net/npm/@scalar/api-reference\"></script>\n<script>\n Scalar.createApiReference('#app', {\n url: '{apiUrl}',\n ...{params}\n })\n</script>\n</body>\n</html>\n";
|
|
6
|
+
|
|
7
|
+
exports["default"] = scalar;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var swagger = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta\n name=\"description\"\n content=\"SwaggerUI\"\n />\n <title>SwaggerUI</title>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" />\n</head>\n<body>\n<div id=\"swagger-ui\"></div>\n<script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script>\n<script>\n window.onload = () => {\n window.ui = SwaggerUIBundle({\n url: \"{apiUrl}\",\n dom_id: '#swagger-ui',\n ...{params}\n });\n };\n</script>\n</body>\n</html>\n";
|
|
2
|
+
|
|
3
|
+
export { swagger as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var swagger = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <meta\n name=\"description\"\n content=\"SwaggerUI\"\n />\n <title>SwaggerUI</title>\n <link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" />\n</head>\n<body>\n<div id=\"swagger-ui\"></div>\n<script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script>\n<script>\n window.onload = () => {\n window.ui = SwaggerUIBundle({\n url: \"{apiUrl}\",\n dom_id: '#swagger-ui',\n ...{params}\n });\n };\n</script>\n</body>\n</html>\n";
|
|
6
|
+
|
|
7
|
+
exports["default"] = swagger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type HandlerPlugin } from 'innet';
|
|
2
|
+
export declare const uiPresets: {
|
|
3
|
+
rapidoc: string;
|
|
4
|
+
redoc: string;
|
|
5
|
+
scalar: string;
|
|
6
|
+
swagger: string;
|
|
7
|
+
};
|
|
8
|
+
export interface UiProps {
|
|
9
|
+
html?: string;
|
|
10
|
+
params?: Record<string, any>;
|
|
11
|
+
path?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const ui: HandlerPlugin;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { placeholder } from '@cantinc/utils';
|
|
2
|
+
import { useProps } from '@innet/jsx';
|
|
3
|
+
import '../../../hooks/index.es6.js';
|
|
4
|
+
import rapidoc from './rapidoc.html.es6.js';
|
|
5
|
+
import redoc from './redoc.html.es6.js';
|
|
6
|
+
import scalar from './scalar.html.es6.js';
|
|
7
|
+
import swagger from './swagger.html.es6.js';
|
|
8
|
+
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
9
|
+
import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
|
|
10
|
+
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
11
|
+
|
|
12
|
+
function camelToDash(str) {
|
|
13
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
14
|
+
}
|
|
15
|
+
const uiPresets = { rapidoc, redoc, scalar, swagger };
|
|
16
|
+
const ui = () => {
|
|
17
|
+
const { html = uiPresets.swagger, params = {}, path = process.env.INNET_UI_PATH || '/ui', } = useProps() || {};
|
|
18
|
+
const { docs, prefix, } = useApi();
|
|
19
|
+
let cache = '';
|
|
20
|
+
useServerPlugin(() => {
|
|
21
|
+
const action = useAction();
|
|
22
|
+
if (action.path === prefix + path) {
|
|
23
|
+
if (!cache) {
|
|
24
|
+
const attributes = Object
|
|
25
|
+
.keys(params)
|
|
26
|
+
.reduce((res, key) => {
|
|
27
|
+
return `${res} ${camelToDash(key)}='${String(params[key])}'`;
|
|
28
|
+
}, '');
|
|
29
|
+
cache = placeholder(html, {
|
|
30
|
+
apiUrl: prefix,
|
|
31
|
+
attributes,
|
|
32
|
+
docs: JSON.stringify(docs),
|
|
33
|
+
params: JSON.stringify(params),
|
|
34
|
+
...params,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
action.res.statusCode = 200;
|
|
38
|
+
action.res.write(cache);
|
|
39
|
+
action.res.end();
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { ui, uiPresets };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils = require('@cantinc/utils');
|
|
6
|
+
var jsx = require('@innet/jsx');
|
|
7
|
+
require('../../../hooks/index.js');
|
|
8
|
+
var rapidoc = require('./rapidoc.html.js');
|
|
9
|
+
var redoc = require('./redoc.html.js');
|
|
10
|
+
var scalar = require('./scalar.html.js');
|
|
11
|
+
var swagger = require('./swagger.html.js');
|
|
12
|
+
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
13
|
+
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
14
|
+
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
15
|
+
|
|
16
|
+
function camelToDash(str) {
|
|
17
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
18
|
+
}
|
|
19
|
+
const uiPresets = { rapidoc: rapidoc["default"], redoc: redoc["default"], scalar: scalar["default"], swagger: swagger["default"] };
|
|
20
|
+
const ui = () => {
|
|
21
|
+
const { html = uiPresets.swagger, params = {}, path = process.env.INNET_UI_PATH || '/ui', } = jsx.useProps() || {};
|
|
22
|
+
const { docs, prefix, } = useApi.useApi();
|
|
23
|
+
let cache = '';
|
|
24
|
+
useServerPlugin.useServerPlugin(() => {
|
|
25
|
+
const action = useAction.useAction();
|
|
26
|
+
if (action.path === prefix + path) {
|
|
27
|
+
if (!cache) {
|
|
28
|
+
const attributes = Object
|
|
29
|
+
.keys(params)
|
|
30
|
+
.reduce((res, key) => {
|
|
31
|
+
return `${res} ${camelToDash(key)}='${String(params[key])}'`;
|
|
32
|
+
}, '');
|
|
33
|
+
cache = utils.placeholder(html, {
|
|
34
|
+
apiUrl: prefix,
|
|
35
|
+
attributes,
|
|
36
|
+
docs: JSON.stringify(docs),
|
|
37
|
+
params: JSON.stringify(params),
|
|
38
|
+
...params,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
action.res.statusCode = 200;
|
|
42
|
+
action.res.write(cache);
|
|
43
|
+
action.res.end();
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.ui = ui;
|
|
50
|
+
exports.uiPresets = uiPresets;
|
package/types.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type ParameterObject = API.ParameterObject;
|
|
|
16
16
|
export type RequestBodyObject = API.RequestBodyObject;
|
|
17
17
|
export type ObjectType = ArraySchemaObjectType | NonArraySchemaObjectType;
|
|
18
18
|
export type RefSchemaObject = ReferenceObject | SchemaObject;
|
|
19
|
+
export type Effect = () => void;
|
|
19
20
|
export interface IValidationErrorData extends Record<string, any> {
|
|
20
21
|
error: RulesErrors;
|
|
21
22
|
}
|
|
@@ -58,11 +59,16 @@ export interface ServerStartParams {
|
|
|
58
59
|
}
|
|
59
60
|
export interface BaseSchemaProps<T> {
|
|
60
61
|
default?: T;
|
|
62
|
+
deprecated?: boolean;
|
|
61
63
|
description?: string;
|
|
62
64
|
example?: T;
|
|
63
65
|
examples?: T[];
|
|
66
|
+
readOnly?: boolean;
|
|
64
67
|
ref?: string;
|
|
68
|
+
title?: string;
|
|
69
|
+
writeOnly?: boolean;
|
|
65
70
|
}
|
|
66
71
|
export interface ValuesSchemaProps<T> extends BaseSchemaProps<T> {
|
|
72
|
+
const?: T;
|
|
67
73
|
values?: T[];
|
|
68
74
|
}
|
package/utils/action/Action.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { type CookieSerializeOptions } from 'cookie';
|
|
1
|
+
import { type Cookies, type SerializeOptions } from 'cookie';
|
|
3
2
|
import { type IncomingHttpHeaders, type IncomingMessage, type ServerResponse } from 'http';
|
|
4
3
|
import { type ParsedQs } from 'qs';
|
|
5
4
|
import { type BodyType } from '../../types';
|
|
@@ -15,14 +14,14 @@ export declare class Action {
|
|
|
15
14
|
body?: object;
|
|
16
15
|
constructor(req: IncomingMessage, res: ServerResponse);
|
|
17
16
|
parseBody(): Promise<void>;
|
|
18
|
-
setCookie(name: string, value?: string, options?:
|
|
17
|
+
setCookie(name: string, value?: string, options?: SerializeOptions): void;
|
|
19
18
|
get bodyType(): BodyType | undefined;
|
|
20
19
|
get clientIp(): string | null;
|
|
21
|
-
get cookies():
|
|
20
|
+
get cookies(): Cookies;
|
|
22
21
|
set cookies(value: Record<string, string>);
|
|
23
22
|
get headers(): IncomingHttpHeaders;
|
|
24
23
|
set headers(value: IncomingHttpHeaders);
|
|
25
|
-
get originCookies():
|
|
24
|
+
get originCookies(): Cookies;
|
|
26
25
|
get originHeaders(): IncomingHttpHeaders;
|
|
27
26
|
get originSearch(): ParsedQs;
|
|
28
27
|
get parsedUrl(): ParsedUrl;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __runInitializers,
|
|
1
|
+
import { __runInitializers, __classPrivateFieldGet, __classPrivateFieldSet, __esDecorate } from 'tslib';
|
|
2
2
|
import cookieLib from 'cookie';
|
|
3
3
|
import { getClientIp } from 'request-ip';
|
|
4
4
|
import '../decorators/index.es6.js';
|
|
@@ -29,21 +29,19 @@ let Action = (() => {
|
|
|
29
29
|
_Action_headers.set(this, {});
|
|
30
30
|
_Action_search.set(this, void 0);
|
|
31
31
|
}
|
|
32
|
-
parseBody() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
});
|
|
32
|
+
async parseBody() {
|
|
33
|
+
if (!this.bodyType) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (this.bodyType === 'multipart/form-data') {
|
|
37
|
+
this.body = await parseFormBody(this.req);
|
|
38
|
+
}
|
|
39
|
+
if (this.bodyType === 'application/x-www-form-urlencoded') {
|
|
40
|
+
this.body = parseSearch(await parseBody(this.req));
|
|
41
|
+
}
|
|
42
|
+
if (this.bodyType === 'application/json') {
|
|
43
|
+
this.body = JSON.parse(await parseBody(this.req));
|
|
44
|
+
}
|
|
47
45
|
}
|
|
48
46
|
setCookie(name, value, options) {
|
|
49
47
|
let cookies = this.res.getHeader('Set-Cookie');
|
package/utils/action/Action.js
CHANGED
|
@@ -37,21 +37,19 @@ let Action = (() => {
|
|
|
37
37
|
_Action_headers.set(this, {});
|
|
38
38
|
_Action_search.set(this, void 0);
|
|
39
39
|
}
|
|
40
|
-
parseBody() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
});
|
|
40
|
+
async parseBody() {
|
|
41
|
+
if (!this.bodyType) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (this.bodyType === 'multipart/form-data') {
|
|
45
|
+
this.body = await parseFormBody.parseFormBody(this.req);
|
|
46
|
+
}
|
|
47
|
+
if (this.bodyType === 'application/x-www-form-urlencoded') {
|
|
48
|
+
this.body = parseSearch.parseSearch(await parseBody.parseBody(this.req));
|
|
49
|
+
}
|
|
50
|
+
if (this.bodyType === 'application/json') {
|
|
51
|
+
this.body = JSON.parse(await parseBody.parseBody(this.req));
|
|
52
|
+
}
|
|
55
53
|
}
|
|
56
54
|
setCookie(name, value, options) {
|
|
57
55
|
let cookies = this.res.getHeader('Set-Cookie');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getSafeSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getSafeSchema } from './getSafeSchema.es6.js';
|
package/utils/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './FileData';
|
|
2
|
+
export * from './JSONString';
|
|
3
|
+
export * from './action';
|
|
4
|
+
export * from './decorators';
|
|
5
|
+
export * from './generateTypes';
|
|
4
6
|
export * from './getEndpoint';
|
|
5
7
|
export * from './getOrAdd';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
+
export * from './getSafeSchema';
|
|
9
|
+
export * from './httpOnStart';
|
|
8
10
|
export * from './parseBody';
|
|
9
11
|
export * from './parseFormBody';
|
|
12
|
+
export * from './parseSearch';
|
|
10
13
|
export * from './rules';
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './FileData';
|
|
13
|
-
export * from './generateTypes';
|
|
14
|
+
export * from './stringifySearch';
|
package/utils/index.es6.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import './
|
|
2
|
-
import './
|
|
3
|
-
import './
|
|
1
|
+
import './FileData/index.es6.js';
|
|
2
|
+
import './JSONString/index.es6.js';
|
|
3
|
+
import './action/index.es6.js';
|
|
4
|
+
import './decorators/index.es6.js';
|
|
5
|
+
import './generateTypes/index.es6.js';
|
|
4
6
|
import './getEndpoint/index.es6.js';
|
|
5
7
|
import './getOrAdd/index.es6.js';
|
|
6
|
-
import './
|
|
7
|
-
import './
|
|
8
|
+
import './getSafeSchema/index.es6.js';
|
|
9
|
+
import './httpOnStart/index.es6.js';
|
|
8
10
|
import './parseBody/index.es6.js';
|
|
9
11
|
import './parseFormBody/index.es6.js';
|
|
12
|
+
import './parseSearch/index.es6.js';
|
|
10
13
|
import './rules/index.es6.js';
|
|
11
|
-
import './
|
|
12
|
-
import './FileData/index.es6.js';
|
|
13
|
-
import './generateTypes/index.es6.js';
|
|
14
|
+
import './stringifySearch/index.es6.js';
|
package/utils/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./
|
|
4
|
-
require('./
|
|
5
|
-
require('./
|
|
3
|
+
require('./FileData/index.js');
|
|
4
|
+
require('./JSONString/index.js');
|
|
5
|
+
require('./action/index.js');
|
|
6
|
+
require('./decorators/index.js');
|
|
7
|
+
require('./generateTypes/index.js');
|
|
6
8
|
require('./getEndpoint/index.js');
|
|
7
9
|
require('./getOrAdd/index.js');
|
|
8
|
-
require('./
|
|
9
|
-
require('./
|
|
10
|
+
require('./getSafeSchema/index.js');
|
|
11
|
+
require('./httpOnStart/index.js');
|
|
10
12
|
require('./parseBody/index.js');
|
|
11
13
|
require('./parseFormBody/index.js');
|
|
14
|
+
require('./parseSearch/index.js');
|
|
12
15
|
require('./rules/index.js');
|
|
13
|
-
require('./
|
|
14
|
-
require('./FileData/index.js');
|
|
15
|
-
require('./generateTypes/index.js');
|
|
16
|
+
require('./stringifySearch/index.js');
|
|
16
17
|
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
1
|
import { StringDecoder } from 'node:string_decoder';
|
|
3
2
|
|
|
4
|
-
function parseBody(req) {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
reject(err);
|
|
18
|
-
});
|
|
3
|
+
async function parseBody(req) {
|
|
4
|
+
return await new Promise((resolve, reject) => {
|
|
5
|
+
const decoder = new StringDecoder('utf-8');
|
|
6
|
+
let buffer = '';
|
|
7
|
+
req.on('data', chunk => {
|
|
8
|
+
buffer += decoder.write(chunk);
|
|
9
|
+
});
|
|
10
|
+
req.on('end', () => {
|
|
11
|
+
buffer += decoder.end();
|
|
12
|
+
resolve(buffer);
|
|
13
|
+
});
|
|
14
|
+
req.on('error', err => {
|
|
15
|
+
reject(err);
|
|
19
16
|
});
|
|
20
17
|
});
|
|
21
18
|
}
|
|
@@ -2,24 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var node_string_decoder = require('node:string_decoder');
|
|
7
6
|
|
|
8
|
-
function parseBody(req) {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
reject(err);
|
|
22
|
-
});
|
|
7
|
+
async function parseBody(req) {
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
const decoder = new node_string_decoder.StringDecoder('utf-8');
|
|
10
|
+
let buffer = '';
|
|
11
|
+
req.on('data', chunk => {
|
|
12
|
+
buffer += decoder.write(chunk);
|
|
13
|
+
});
|
|
14
|
+
req.on('end', () => {
|
|
15
|
+
buffer += decoder.end();
|
|
16
|
+
resolve(buffer);
|
|
17
|
+
});
|
|
18
|
+
req.on('error', err => {
|
|
19
|
+
reject(err);
|
|
23
20
|
});
|
|
24
21
|
});
|
|
25
22
|
}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { __awaiter, __rest } from 'tslib';
|
|
2
1
|
import { Form } from 'multiparty';
|
|
3
2
|
import '../FileData/index.es6.js';
|
|
4
3
|
import '../parseSearch/index.es6.js';
|
|
5
4
|
import { Bin } from '../FileData/Bin.es6.js';
|
|
6
5
|
import { parseSearch } from '../parseSearch/parseSearch.es6.js';
|
|
7
6
|
|
|
8
|
-
function parseFormBody(req) {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
query += '&';
|
|
23
|
-
}
|
|
24
|
-
query += `${key}=${value.replaceAll('=', '%26')}`;
|
|
7
|
+
async function parseFormBody(req) {
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
const form = new Form();
|
|
10
|
+
form.parse(req, (error, fields, files) => {
|
|
11
|
+
if (error) {
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let query = '';
|
|
16
|
+
const queryFiles = [];
|
|
17
|
+
for (const key in fields) {
|
|
18
|
+
for (const value of fields[key]) {
|
|
19
|
+
if (query) {
|
|
20
|
+
query += '&';
|
|
25
21
|
}
|
|
22
|
+
query += `${key}=${value.replaceAll('=', '%26')}`;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
query += `${key}==${queryFiles.length}`;
|
|
34
|
-
const { headers } = value, options = __rest(value, ["headers"]);
|
|
35
|
-
options.type = headers['content-type'];
|
|
36
|
-
options.disposition = headers['content-disposition'];
|
|
37
|
-
queryFiles.push(new Bin(options));
|
|
24
|
+
}
|
|
25
|
+
for (const key in files) {
|
|
26
|
+
const values = files[key];
|
|
27
|
+
for (const value of values) {
|
|
28
|
+
if (query) {
|
|
29
|
+
query += '&';
|
|
38
30
|
}
|
|
31
|
+
query += `${key}==${queryFiles.length}`;
|
|
32
|
+
const { headers, ...options } = value;
|
|
33
|
+
const binOptions = {
|
|
34
|
+
...options,
|
|
35
|
+
disposition: headers['content-disposition'],
|
|
36
|
+
type: headers['content-type'],
|
|
37
|
+
};
|
|
38
|
+
queryFiles.push(new Bin(binOptions));
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
});
|
|
40
|
+
}
|
|
41
|
+
resolve(parseSearch(query, {
|
|
42
|
+
decoder(value, decoder, charset, type) {
|
|
43
|
+
if (type === 'key') {
|
|
44
|
+
return decoder(value, decoder, charset);
|
|
45
|
+
}
|
|
46
|
+
if (value.startsWith('=')) {
|
|
47
|
+
return queryFiles[Number(value.slice(1))];
|
|
48
|
+
}
|
|
49
|
+
return value.replaceAll('%26', '=');
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
}
|