@innet/server 1.4.0 → 1.4.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/action/Action/Action.d.ts +3 -2
- package/action/Action/Action.es6.js +3 -20
- package/action/Action/Action.js +3 -31
- package/index.d.ts +1 -0
- package/index.es6.js +2 -0
- package/index.js +4 -0
- package/package.json +3 -1
- package/plugins/redirect/redirect.d.ts +1 -0
- package/plugins/redirect/redirect.es6.js +2 -2
- package/plugins/redirect/redirect.js +2 -2
- package/utils/index.d.ts +2 -0
- package/utils/index.es6.js +2 -0
- package/utils/index.js +11 -0
- package/utils/parseSearch/index.d.ts +1 -0
- package/utils/parseSearch/index.es6.js +1 -0
- package/utils/parseSearch/index.js +9 -0
- package/utils/parseSearch/parseSearch.d.ts +2 -0
- package/utils/parseSearch/parseSearch.es6.js +7 -0
- package/utils/parseSearch/parseSearch.js +16 -0
- package/utils/stringifySearch/index.d.ts +1 -0
- package/utils/stringifySearch/index.es6.js +1 -0
- package/utils/stringifySearch/index.js +9 -0
- package/utils/stringifySearch/stringifySearch.d.ts +2 -0
- package/utils/stringifySearch/stringifySearch.es6.js +7 -0
- package/utils/stringifySearch/stringifySearch.js +16 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { CookieSerializeOptions } from 'cookie';
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
+
import { ParsedQs } from 'qs';
|
|
4
5
|
export declare const ACTION: string;
|
|
5
|
-
export declare type Resources = 'search' | 'body' | 'cookies' | 'files';
|
|
6
6
|
export declare type Body = Record<string, any>;
|
|
7
|
-
export declare type Search =
|
|
7
|
+
export declare type Search = ParsedQs;
|
|
8
8
|
export declare type Cookies = Record<string, string | string[]>;
|
|
9
9
|
export interface File {
|
|
10
10
|
fieldName: string;
|
|
@@ -22,6 +22,7 @@ export interface ActionOptions {
|
|
|
22
22
|
cookies?: Cookies;
|
|
23
23
|
files?: Files;
|
|
24
24
|
}
|
|
25
|
+
export declare type Resources = Exclude<keyof ActionOptions, undefined>;
|
|
25
26
|
export declare const URL_PARSER: RegExp;
|
|
26
27
|
export declare class Action<O extends ActionOptions = ActionOptions> {
|
|
27
28
|
readonly req: Request;
|
|
@@ -3,6 +3,8 @@ import { once } from '@cantinc/utils';
|
|
|
3
3
|
import { useHandler } from '@innet/jsx';
|
|
4
4
|
import cookie from 'cookie';
|
|
5
5
|
import multiparty from 'multiparty';
|
|
6
|
+
import { parseSearch } from '../../utils/parseSearch/parseSearch.es6.js';
|
|
7
|
+
import 'qs';
|
|
6
8
|
|
|
7
9
|
const ACTION = Symbol('Action');
|
|
8
10
|
const URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
|
|
@@ -53,26 +55,7 @@ class Action {
|
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
get search() {
|
|
56
|
-
|
|
57
|
-
const search = this.parsedUrl.search || '';
|
|
58
|
-
for (const option of search.split('&')) {
|
|
59
|
-
const [key, ...value] = option.split('=');
|
|
60
|
-
if (key) {
|
|
61
|
-
const normValue = value.join('=');
|
|
62
|
-
if (key in result) {
|
|
63
|
-
if (Array.isArray(result[key])) {
|
|
64
|
-
result[key].push(normValue);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
result[key] = [result[key], normValue];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
result[key] = normValue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
58
|
+
return parseSearch(this.parsedUrl.search);
|
|
76
59
|
}
|
|
77
60
|
get parsedUrl() {
|
|
78
61
|
const match = this.req.url.match(URL_PARSER);
|
package/action/Action/Action.js
CHANGED
|
@@ -7,6 +7,8 @@ var utils = require('@cantinc/utils');
|
|
|
7
7
|
var jsx = require('@innet/jsx');
|
|
8
8
|
var cookie = require('cookie');
|
|
9
9
|
var multiparty = require('multiparty');
|
|
10
|
+
var parseSearch = require('../../utils/parseSearch/parseSearch.js');
|
|
11
|
+
require('qs');
|
|
10
12
|
|
|
11
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
14
|
|
|
@@ -68,37 +70,7 @@ var Action = /** @class */ (function () {
|
|
|
68
70
|
};
|
|
69
71
|
Object.defineProperty(Action.prototype, "search", {
|
|
70
72
|
get: function () {
|
|
71
|
-
|
|
72
|
-
var result = Object.create(null);
|
|
73
|
-
var search = this.parsedUrl.search || '';
|
|
74
|
-
try {
|
|
75
|
-
for (var _b = tslib.__values(search.split('&')), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
76
|
-
var option = _c.value;
|
|
77
|
-
var _d = tslib.__read(option.split('=')), key = _d[0], value = _d.slice(1);
|
|
78
|
-
if (key) {
|
|
79
|
-
var normValue = value.join('=');
|
|
80
|
-
if (key in result) {
|
|
81
|
-
if (Array.isArray(result[key])) {
|
|
82
|
-
result[key].push(normValue);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
result[key] = [result[key], normValue];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
result[key] = normValue;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
95
|
-
finally {
|
|
96
|
-
try {
|
|
97
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
98
|
-
}
|
|
99
|
-
finally { if (e_1) throw e_1.error; }
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
73
|
+
return parseSearch.parseSearch(this.parsedUrl.search);
|
|
102
74
|
},
|
|
103
75
|
enumerable: false,
|
|
104
76
|
configurable: true
|
package/index.d.ts
CHANGED
package/index.es6.js
CHANGED
|
@@ -10,3 +10,5 @@ export { file } from './plugins/file/file.es6.js';
|
|
|
10
10
|
export { proxy } from './plugins/proxy/proxy.es6.js';
|
|
11
11
|
export { redirect, redirectStatuses } from './plugins/redirect/redirect.es6.js';
|
|
12
12
|
export { ACTION, Action, URL_PARSER, useAction } from './action/Action/Action.es6.js';
|
|
13
|
+
export { parseSearch } from './utils/parseSearch/parseSearch.es6.js';
|
|
14
|
+
export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
|
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@ var file = require('./plugins/file/file.js');
|
|
|
14
14
|
var proxy = require('./plugins/proxy/proxy.js');
|
|
15
15
|
var redirect = require('./plugins/redirect/redirect.js');
|
|
16
16
|
var Action = require('./action/Action/Action.js');
|
|
17
|
+
var parseSearch = require('./utils/parseSearch/parseSearch.js');
|
|
18
|
+
var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
|
|
@@ -44,3 +46,5 @@ exports.ACTION = Action.ACTION;
|
|
|
44
46
|
exports.Action = Action.Action;
|
|
45
47
|
exports.URL_PARSER = Action.URL_PARSER;
|
|
46
48
|
exports.useAction = Action.useAction;
|
|
49
|
+
exports.parseSearch = parseSearch.parseSearch;
|
|
50
|
+
exports.stringifySearch = stringifySearch.stringifySearch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innet/server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Create server-side application with innet",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.es6.js",
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
"@innet/switch": "^1.0.0",
|
|
29
29
|
"@innet/utils": "^1.1.1",
|
|
30
30
|
"@types/cookie": "^0.5.1",
|
|
31
|
+
"@types/qs": "^6.9.7",
|
|
31
32
|
"cookie": "^0.5.0",
|
|
32
33
|
"http-proxy": "^1.18.1",
|
|
33
34
|
"innet": "^1.0.0",
|
|
34
35
|
"is-invalid-path": "^1.0.2",
|
|
35
36
|
"mime": "^3.0.0",
|
|
36
37
|
"multiparty": "^4.2.3",
|
|
38
|
+
"qs": "^6.11.0",
|
|
37
39
|
"tslib": "^2.4.0",
|
|
38
40
|
"watch-state": "^3.4.4"
|
|
39
41
|
}
|
|
@@ -17,9 +17,9 @@ function getStatus(status) {
|
|
|
17
17
|
}
|
|
18
18
|
function redirect({ props, children }, handler) {
|
|
19
19
|
const { res } = handler[ACTION];
|
|
20
|
-
const { to, status = 301 } = props;
|
|
20
|
+
const { to, status = 301, decode } = props;
|
|
21
21
|
res.writeHead(getStatus(status), {
|
|
22
|
-
location: to,
|
|
22
|
+
location: decode ? decodeURI(to) : to,
|
|
23
23
|
});
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
@@ -22,9 +22,9 @@ function getStatus(status) {
|
|
|
22
22
|
function redirect(_a, handler) {
|
|
23
23
|
var props = _a.props; _a.children;
|
|
24
24
|
var res = handler[Action.ACTION].res;
|
|
25
|
-
var to = props.to, _b = props.status, status = _b === void 0 ? 301 : _b;
|
|
25
|
+
var to = props.to, _b = props.status, status = _b === void 0 ? 301 : _b, decode = props.decode;
|
|
26
26
|
res.writeHead(getStatus(status), {
|
|
27
|
-
location: to,
|
|
27
|
+
location: decode ? decodeURI(to) : to,
|
|
28
28
|
});
|
|
29
29
|
return null;
|
|
30
30
|
}
|
package/utils/index.d.ts
ADDED
package/utils/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var parseSearch = require('./parseSearch/parseSearch.js');
|
|
6
|
+
var stringifySearch = require('./stringifySearch/stringifySearch.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.parseSearch = parseSearch.parseSearch;
|
|
11
|
+
exports.stringifySearch = stringifySearch.stringifySearch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './parseSearch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseSearch } from './parseSearch.es6.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var qs = require('qs');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
11
|
+
|
|
12
|
+
function parseSearch(search, options) {
|
|
13
|
+
return qs__default["default"].parse(search, tslib.__assign({ ignoreQueryPrefix: true }, options));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.parseSearch = parseSearch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stringifySearch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { stringifySearch } from './stringifySearch.es6.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var qs = require('qs');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
11
|
+
|
|
12
|
+
function stringifySearch(search, options) {
|
|
13
|
+
return qs__default["default"].stringify(search, tslib.__assign({ encode: false }, options));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.stringifySearch = stringifySearch;
|