@innet/server 1.3.0 → 1.4.0
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 +39 -33
- package/action/Action/Action.d.ts +8 -7
- package/action/Action/Action.es6.js +6 -2
- package/action/Action/Action.js +6 -1
- package/action/Action/index.es6.js +1 -1
- package/action/Action/index.js +1 -0
- package/action/index.d.ts +0 -2
- package/action/index.es6.js +1 -3
- package/action/index.js +1 -4
- package/experimental/serverFn/serverFn.es6.js +1 -1
- package/experimental/serverFn/serverFn.js +1 -1
- package/handler/handler.d.ts +3 -4
- package/handler/handler.es6.js +6 -6
- package/handler/handler.js +4 -4
- package/handler/index.d.ts +0 -1
- package/handler/index.es6.js +1 -1
- package/handler/index.js +1 -1
- package/index.d.ts +1 -1
- package/index.es6.js +3 -5
- package/index.js +4 -7
- package/package.json +9 -9
- package/plugins/cms/cms.d.ts +1 -2
- package/plugins/cms/cms.es6.js +1 -1
- package/plugins/cms/cms.js +1 -1
- package/plugins/cookie/cookie.d.ts +1 -1
- package/plugins/index.es6.js +1 -1
- package/plugins/index.js +1 -2
- package/plugins/redirect/redirect.d.ts +4 -4
- package/plugins/router/index.es6.js +1 -1
- package/plugins/router/index.js +1 -2
- package/plugins/router/router.d.ts +1 -11
- package/plugins/router/router.es6.js +4 -11
- package/plugins/router/router.js +4 -16
- package/server/server.es6.js +2 -2
- package/server/server.js +3 -3
- package/action/getAction/getAction.d.ts +0 -3
- package/action/getAction/getAction.es6.js +0 -7
- package/action/getAction/getAction.js +0 -11
- package/action/getAction/index.d.ts +0 -1
- package/action/getAction/index.es6.js +0 -1
- package/action/getAction/index.js +0 -9
- package/action/withAction/index.d.ts +0 -1
- package/action/withAction/index.es6.js +0 -1
- package/action/withAction/index.js +0 -9
- package/action/withAction/withAction.d.ts +0 -11
- package/action/withAction/withAction.es6.js +0 -12
- package/action/withAction/withAction.js +0 -20
package/README.md
CHANGED
|
@@ -496,18 +496,24 @@ export default <Server cmsPrefix='/cms' />
|
|
|
496
496
|
You can use it with any other functionality, for example with `html`.
|
|
497
497
|
|
|
498
498
|
```typescript jsx
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
499
|
+
import { useChildren } from '@innet/jsx'
|
|
500
|
+
|
|
501
|
+
function Html ({ title }) {
|
|
502
|
+
const children = useChildren()
|
|
503
|
+
|
|
504
|
+
return (
|
|
505
|
+
<header name='content-type' value='text/html'>
|
|
506
|
+
<html>
|
|
502
507
|
<head>
|
|
503
508
|
<title>{title}</title>
|
|
504
509
|
</head>
|
|
505
510
|
<body>
|
|
506
511
|
{children}
|
|
507
512
|
</body>
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
)
|
|
513
|
+
</html>
|
|
514
|
+
</header>
|
|
515
|
+
)
|
|
516
|
+
}
|
|
511
517
|
|
|
512
518
|
export default (
|
|
513
519
|
<server>
|
|
@@ -676,18 +682,17 @@ export default (
|
|
|
676
682
|
)
|
|
677
683
|
```
|
|
678
684
|
|
|
679
|
-
##
|
|
685
|
+
## useAction
|
|
680
686
|
Action is an object which contains `request` and `response`.
|
|
681
687
|
Also, it contains a couple of fields and methods.
|
|
682
688
|
|
|
683
689
|
Action available in components.
|
|
684
690
|
|
|
685
691
|
```typescript jsx
|
|
686
|
-
import {
|
|
692
|
+
import { useAction } from '@innet/server'
|
|
687
693
|
|
|
688
|
-
|
|
689
|
-
const
|
|
690
|
-
const { req, res } = action
|
|
694
|
+
function Test () {
|
|
695
|
+
const { req, res } = useAction()
|
|
691
696
|
|
|
692
697
|
console.log(req, res)
|
|
693
698
|
}
|
|
@@ -697,10 +702,10 @@ const Test = (props, child, handler) => {
|
|
|
697
702
|
You can get cookies as an object from an action.
|
|
698
703
|
|
|
699
704
|
```typescript jsx
|
|
700
|
-
import {
|
|
705
|
+
import { useAction } from '@innet/server'
|
|
701
706
|
|
|
702
|
-
|
|
703
|
-
const { cookies } =
|
|
707
|
+
function Cookies () {
|
|
708
|
+
const { cookies } = useAction()
|
|
704
709
|
|
|
705
710
|
return <success>{cookies}</success>
|
|
706
711
|
}
|
|
@@ -710,11 +715,12 @@ const Cookies = (props, child, handler) => {
|
|
|
710
715
|
You can set cookie with action.
|
|
711
716
|
|
|
712
717
|
```typescript jsx
|
|
713
|
-
import {
|
|
718
|
+
import { useAction } from '@innet/server'
|
|
719
|
+
|
|
720
|
+
function Login () {
|
|
721
|
+
const action = useAction()
|
|
714
722
|
|
|
715
|
-
|
|
716
|
-
getAction(handler)
|
|
717
|
-
.setCookie('user', 'token')
|
|
723
|
+
action.setCookie('user', 'token')
|
|
718
724
|
}
|
|
719
725
|
```
|
|
720
726
|
|
|
@@ -722,10 +728,10 @@ const Login = (props, child, handler) => {
|
|
|
722
728
|
You can get current path with action.
|
|
723
729
|
|
|
724
730
|
```typescript jsx
|
|
725
|
-
import {
|
|
731
|
+
import { useAction } from '@innet/server'
|
|
726
732
|
|
|
727
|
-
|
|
728
|
-
const { path } =
|
|
733
|
+
function Path () {
|
|
734
|
+
const { path } = useAction()
|
|
729
735
|
|
|
730
736
|
return path
|
|
731
737
|
}
|
|
@@ -735,10 +741,10 @@ const Path = (props, child, handler) => {
|
|
|
735
741
|
You can get current search as an object.
|
|
736
742
|
|
|
737
743
|
```typescript jsx
|
|
738
|
-
import {
|
|
744
|
+
import { useAction } from '@innet/server'
|
|
739
745
|
|
|
740
|
-
|
|
741
|
-
const { search } =
|
|
746
|
+
function Search () {
|
|
747
|
+
const { search } = useAction()
|
|
742
748
|
|
|
743
749
|
return <success>{search}</success>
|
|
744
750
|
}
|
|
@@ -748,10 +754,10 @@ const Search = (props, child, handler) => {
|
|
|
748
754
|
You can parse body, and get values.
|
|
749
755
|
|
|
750
756
|
```typescript jsx
|
|
751
|
-
import {
|
|
757
|
+
import { useAction } from '@innet/server'
|
|
752
758
|
|
|
753
|
-
|
|
754
|
-
const action =
|
|
759
|
+
async function Body () {
|
|
760
|
+
const action = useAction()
|
|
755
761
|
|
|
756
762
|
await action.parseBody()
|
|
757
763
|
|
|
@@ -763,10 +769,10 @@ const Body = async (props, child, handler) => {
|
|
|
763
769
|
You can get files from a user.
|
|
764
770
|
|
|
765
771
|
```typescript jsx
|
|
766
|
-
import {
|
|
772
|
+
import { useAction } from '@innet/server'
|
|
767
773
|
|
|
768
|
-
|
|
769
|
-
const action =
|
|
774
|
+
async function Body () {
|
|
775
|
+
const action = useAction()
|
|
770
776
|
|
|
771
777
|
await action.parseBody()
|
|
772
778
|
|
|
@@ -779,10 +785,10 @@ const Body = async (props, child, handler) => {
|
|
|
779
785
|
You can get router data in a component
|
|
780
786
|
|
|
781
787
|
```typescript jsx
|
|
782
|
-
import {
|
|
788
|
+
import { useRouter } from '@innet/server'
|
|
783
789
|
|
|
784
|
-
|
|
785
|
-
const { prefix, params } =
|
|
790
|
+
async function Router () {
|
|
791
|
+
const { prefix, params } = useRouter()
|
|
786
792
|
|
|
787
793
|
return <success>{{ prefix, params }}</success>
|
|
788
794
|
}
|
|
@@ -6,6 +6,13 @@ export declare type Resources = 'search' | 'body' | 'cookies' | 'files';
|
|
|
6
6
|
export declare type Body = Record<string, any>;
|
|
7
7
|
export declare type Search = Record<string, any>;
|
|
8
8
|
export declare type Cookies = Record<string, string | string[]>;
|
|
9
|
+
export interface File {
|
|
10
|
+
fieldName: string;
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
originalFilename: string;
|
|
13
|
+
path: string;
|
|
14
|
+
size: number;
|
|
15
|
+
}
|
|
9
16
|
export declare type Files = Record<string, File | File[]>;
|
|
10
17
|
export declare type Request = IncomingMessage;
|
|
11
18
|
export declare type Response = ServerResponse;
|
|
@@ -15,13 +22,6 @@ export interface ActionOptions {
|
|
|
15
22
|
cookies?: Cookies;
|
|
16
23
|
files?: Files;
|
|
17
24
|
}
|
|
18
|
-
export interface File {
|
|
19
|
-
fieldName: string;
|
|
20
|
-
headers: Record<string, string>;
|
|
21
|
-
originalFilename: string;
|
|
22
|
-
path: string;
|
|
23
|
-
size: number;
|
|
24
|
-
}
|
|
25
25
|
export declare const URL_PARSER: RegExp;
|
|
26
26
|
export declare class Action<O extends ActionOptions = ActionOptions> {
|
|
27
27
|
readonly req: Request;
|
|
@@ -39,3 +39,4 @@ export declare class Action<O extends ActionOptions = ActionOptions> {
|
|
|
39
39
|
};
|
|
40
40
|
get path(): string;
|
|
41
41
|
}
|
|
42
|
+
export declare function useAction<O extends ActionOptions>(): Action<O>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { once } from '@cantinc/utils';
|
|
3
|
+
import { useHandler } from '@innet/jsx';
|
|
3
4
|
import cookie from 'cookie';
|
|
4
5
|
import multiparty from 'multiparty';
|
|
5
6
|
|
|
@@ -92,6 +93,9 @@ __decorate([
|
|
|
92
93
|
], Action.prototype, "search", null);
|
|
93
94
|
__decorate([
|
|
94
95
|
once
|
|
95
|
-
], Action.prototype, "parsedUrl", null);
|
|
96
|
+
], Action.prototype, "parsedUrl", null);
|
|
97
|
+
function useAction() {
|
|
98
|
+
return useHandler()[ACTION];
|
|
99
|
+
}
|
|
96
100
|
|
|
97
|
-
export { ACTION, Action, URL_PARSER };
|
|
101
|
+
export { ACTION, Action, URL_PARSER, useAction };
|
package/action/Action/Action.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var utils = require('@cantinc/utils');
|
|
7
|
+
var jsx = require('@innet/jsx');
|
|
7
8
|
var cookie = require('cookie');
|
|
8
9
|
var multiparty = require('multiparty');
|
|
9
10
|
|
|
@@ -130,8 +131,12 @@ var Action = /** @class */ (function () {
|
|
|
130
131
|
utils.once
|
|
131
132
|
], Action.prototype, "parsedUrl", null);
|
|
132
133
|
return Action;
|
|
133
|
-
}());
|
|
134
|
+
}());
|
|
135
|
+
function useAction() {
|
|
136
|
+
return jsx.useHandler()[ACTION];
|
|
137
|
+
}
|
|
134
138
|
|
|
135
139
|
exports.ACTION = ACTION;
|
|
136
140
|
exports.Action = Action;
|
|
137
141
|
exports.URL_PARSER = URL_PARSER;
|
|
142
|
+
exports.useAction = useAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ACTION, Action, URL_PARSER } from './Action.es6.js';
|
|
1
|
+
export { ACTION, Action, URL_PARSER, useAction } from './Action.es6.js';
|
package/action/Action/index.js
CHANGED
package/action/index.d.ts
CHANGED
package/action/index.es6.js
CHANGED
package/action/index.js
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var Action = require('./Action/Action.js');
|
|
6
|
-
var withAction = require('./withAction/withAction.js');
|
|
7
|
-
var getAction = require('./getAction/getAction.js');
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
exports.ACTION = Action.ACTION;
|
|
12
10
|
exports.Action = Action.Action;
|
|
13
11
|
exports.URL_PARSER = Action.URL_PARSER;
|
|
14
|
-
exports.
|
|
15
|
-
exports.getAction = getAction.getAction;
|
|
12
|
+
exports.useAction = Action.useAction;
|
|
@@ -12,7 +12,7 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
|
12
12
|
function serverFn() {
|
|
13
13
|
return function (fn, next, handler) {
|
|
14
14
|
var result;
|
|
15
|
-
new watchState.Watch(function (update) { return result = innet__default["default"](fn(update), handler); });
|
|
15
|
+
new watchState.Watch(function (update) { return (result = innet__default["default"](fn(update), handler)); });
|
|
16
16
|
return result;
|
|
17
17
|
};
|
|
18
18
|
}
|
package/handler/handler.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import html from '@innet/html';
|
|
2
2
|
import { switchAsync, SwitchProps } from '@innet/switch';
|
|
3
3
|
import { arrayAsync, async } from '@innet/utils';
|
|
4
|
-
import { cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, header, HeaderProps, proxy, ProxyProps, router, RouterProps, success, SuccessProps, redirect, RedirectProps } from '../plugins';
|
|
5
|
-
import { server, ServerProps } from '../server';
|
|
6
4
|
import { serverFn } from '../experimental/serverFn';
|
|
5
|
+
import { cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, header, HeaderProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, success, SuccessProps } from '../plugins';
|
|
6
|
+
import { server, ServerProps } from '../server';
|
|
7
7
|
export declare const arrayPlugins: (typeof arrayAsync)[];
|
|
8
8
|
export declare const JSXPlugins: {
|
|
9
9
|
server: typeof server;
|
|
@@ -22,8 +22,7 @@ export declare const JSXPlugins: {
|
|
|
22
22
|
export declare const fnPlugins: (typeof serverFn)[];
|
|
23
23
|
export declare const objectPlugins: ((handler: any) => import("innet").PluginHandler)[];
|
|
24
24
|
export declare const promisePlugins: (typeof async)[];
|
|
25
|
-
declare const
|
|
26
|
-
export default _default;
|
|
25
|
+
export declare const handler: import("innet").Handler;
|
|
27
26
|
declare global {
|
|
28
27
|
namespace JSX {
|
|
29
28
|
interface IntrinsicElements {
|
package/handler/handler.es6.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { createHandler } from 'innet';
|
|
1
2
|
import html from '@innet/html';
|
|
2
|
-
import { jsxPlugins,
|
|
3
|
+
import { jsxPlugins, jsxComponent } from '@innet/jsx';
|
|
3
4
|
import { switchAsync } from '@innet/switch';
|
|
4
5
|
import { promise, array, object, fn, arrayAsync, arrayClear, arraySingleLess, async } from '@innet/utils';
|
|
5
|
-
import {
|
|
6
|
+
import { serverFn } from '../experimental/serverFn/serverFn.es6.js';
|
|
6
7
|
import { cookie } from '../plugins/cookie/cookie.es6.js';
|
|
7
8
|
import { header } from '../plugins/header/header.es6.js';
|
|
8
9
|
import { router } from '../plugins/router/router.es6.js';
|
|
@@ -13,7 +14,6 @@ import { file } from '../plugins/file/file.es6.js';
|
|
|
13
14
|
import { proxy } from '../plugins/proxy/proxy.es6.js';
|
|
14
15
|
import { redirect } from '../plugins/redirect/redirect.es6.js';
|
|
15
16
|
import { server } from '../server/server.es6.js';
|
|
16
|
-
import { serverFn } from '../experimental/serverFn/serverFn.es6.js';
|
|
17
17
|
|
|
18
18
|
const arrayPlugins = [
|
|
19
19
|
arrayAsync,
|
|
@@ -39,16 +39,16 @@ const fnPlugins = [
|
|
|
39
39
|
];
|
|
40
40
|
const objectPlugins = [
|
|
41
41
|
jsxPlugins(JSXPlugins),
|
|
42
|
-
|
|
42
|
+
jsxComponent,
|
|
43
43
|
];
|
|
44
44
|
const promisePlugins = [
|
|
45
45
|
async,
|
|
46
46
|
];
|
|
47
|
-
|
|
47
|
+
const handler = createHandler([
|
|
48
48
|
promise(promisePlugins),
|
|
49
49
|
array(arrayPlugins),
|
|
50
50
|
object(objectPlugins),
|
|
51
51
|
fn(fnPlugins),
|
|
52
52
|
]);
|
|
53
53
|
|
|
54
|
-
export { JSXPlugins, arrayPlugins,
|
|
54
|
+
export { JSXPlugins, arrayPlugins, fnPlugins, handler, objectPlugins, promisePlugins };
|
package/handler/handler.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var innet = require('innet');
|
|
5
6
|
var html = require('@innet/html');
|
|
6
7
|
var jsx = require('@innet/jsx');
|
|
7
8
|
var _switch = require('@innet/switch');
|
|
8
9
|
var utils = require('@innet/utils');
|
|
9
|
-
var
|
|
10
|
+
var serverFn = require('../experimental/serverFn/serverFn.js');
|
|
10
11
|
var cookie = require('../plugins/cookie/cookie.js');
|
|
11
12
|
var header = require('../plugins/header/header.js');
|
|
12
13
|
var router = require('../plugins/router/router.js');
|
|
@@ -17,7 +18,6 @@ var file = require('../plugins/file/file.js');
|
|
|
17
18
|
var proxy = require('../plugins/proxy/proxy.js');
|
|
18
19
|
var redirect = require('../plugins/redirect/redirect.js');
|
|
19
20
|
var server = require('../server/server.js');
|
|
20
|
-
var serverFn = require('../experimental/serverFn/serverFn.js');
|
|
21
21
|
|
|
22
22
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
23
|
|
|
@@ -47,7 +47,7 @@ var fnPlugins = [
|
|
|
47
47
|
];
|
|
48
48
|
var objectPlugins = [
|
|
49
49
|
jsx.jsxPlugins(JSXPlugins),
|
|
50
|
-
jsx.
|
|
50
|
+
jsx.jsxComponent,
|
|
51
51
|
];
|
|
52
52
|
var promisePlugins = [
|
|
53
53
|
utils.async,
|
|
@@ -61,7 +61,7 @@ var handler = innet.createHandler([
|
|
|
61
61
|
|
|
62
62
|
exports.JSXPlugins = JSXPlugins;
|
|
63
63
|
exports.arrayPlugins = arrayPlugins;
|
|
64
|
-
exports["default"] = handler;
|
|
65
64
|
exports.fnPlugins = fnPlugins;
|
|
65
|
+
exports.handler = handler;
|
|
66
66
|
exports.objectPlugins = objectPlugins;
|
|
67
67
|
exports.promisePlugins = promisePlugins;
|
package/handler/index.d.ts
CHANGED
package/handler/index.es6.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { JSXPlugins, arrayPlugins,
|
|
1
|
+
export { JSXPlugins, arrayPlugins, fnPlugins, handler, objectPlugins, promisePlugins } from './handler.es6.js';
|
package/handler/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var handler = require('./handler.js');
|
|
|
8
8
|
|
|
9
9
|
exports.JSXPlugins = handler.JSXPlugins;
|
|
10
10
|
exports.arrayPlugins = handler.arrayPlugins;
|
|
11
|
-
exports["default"] = handler["default"];
|
|
12
11
|
exports.fnPlugins = handler.fnPlugins;
|
|
12
|
+
exports.handler = handler.handler;
|
|
13
13
|
exports.objectPlugins = handler.objectPlugins;
|
|
14
14
|
exports.promisePlugins = handler.promisePlugins;
|
package/index.d.ts
CHANGED
package/index.es6.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
export { JSXPlugins, arrayPlugins, default, fnPlugins, objectPlugins, promisePlugins } from './handler/handler.es6.js';
|
|
1
|
+
export { JSXPlugins, arrayPlugins, handler as default, fnPlugins, handler, objectPlugins, promisePlugins } from './handler/handler.es6.js';
|
|
2
2
|
export { server } from './server/server.es6.js';
|
|
3
3
|
export { cookie } from './plugins/cookie/cookie.es6.js';
|
|
4
4
|
export { header } from './plugins/header/header.es6.js';
|
|
5
|
-
export { ROUTER, getMatchReg,
|
|
5
|
+
export { ROUTER, getMatchReg, router, useRouter } from './plugins/router/router.es6.js';
|
|
6
6
|
export { success, successStatuses } from './plugins/success/success.es6.js';
|
|
7
7
|
export { error, errorStatuses } from './plugins/error/error.es6.js';
|
|
8
8
|
export { cms } from './plugins/cms/cms.es6.js';
|
|
9
9
|
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
|
-
export { ACTION, Action, URL_PARSER } from './action/Action/Action.es6.js';
|
|
13
|
-
export { withAction } from './action/withAction/withAction.es6.js';
|
|
14
|
-
export { getAction } from './action/getAction/getAction.es6.js';
|
|
12
|
+
export { ACTION, Action, URL_PARSER, useAction } from './action/Action/Action.es6.js';
|
package/index.js
CHANGED
|
@@ -14,15 +14,14 @@ 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 withAction = require('./action/withAction/withAction.js');
|
|
18
|
-
var getAction = require('./action/getAction/getAction.js');
|
|
19
17
|
|
|
20
18
|
|
|
21
19
|
|
|
22
20
|
exports.JSXPlugins = handler.JSXPlugins;
|
|
23
21
|
exports.arrayPlugins = handler.arrayPlugins;
|
|
24
|
-
exports["default"] = handler
|
|
22
|
+
exports["default"] = handler.handler;
|
|
25
23
|
exports.fnPlugins = handler.fnPlugins;
|
|
24
|
+
exports.handler = handler.handler;
|
|
26
25
|
exports.objectPlugins = handler.objectPlugins;
|
|
27
26
|
exports.promisePlugins = handler.promisePlugins;
|
|
28
27
|
exports.server = server.server;
|
|
@@ -30,9 +29,8 @@ exports.cookie = cookie.cookie;
|
|
|
30
29
|
exports.header = header.header;
|
|
31
30
|
exports.ROUTER = router.ROUTER;
|
|
32
31
|
exports.getMatchReg = router.getMatchReg;
|
|
33
|
-
exports.getRouter = router.getRouter;
|
|
34
32
|
exports.router = router.router;
|
|
35
|
-
exports.
|
|
33
|
+
exports.useRouter = router.useRouter;
|
|
36
34
|
exports.success = success.success;
|
|
37
35
|
exports.successStatuses = success.successStatuses;
|
|
38
36
|
exports.error = error.error;
|
|
@@ -45,5 +43,4 @@ exports.redirectStatuses = redirect.redirectStatuses;
|
|
|
45
43
|
exports.ACTION = Action.ACTION;
|
|
46
44
|
exports.Action = Action.Action;
|
|
47
45
|
exports.URL_PARSER = Action.URL_PARSER;
|
|
48
|
-
exports.
|
|
49
|
-
exports.getAction = getAction.getAction;
|
|
46
|
+
exports.useAction = Action.useAction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innet/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Create server-side application with innet",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.es6.js",
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/d8corp/innet-server",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@cantinc/utils": "^1.0.
|
|
26
|
-
"@innet/html": "^1.0.
|
|
27
|
-
"@innet/jsx": "^0.
|
|
25
|
+
"@cantinc/utils": "^1.0.1",
|
|
26
|
+
"@innet/html": "^1.0.1",
|
|
27
|
+
"@innet/jsx": "^1.0.4",
|
|
28
28
|
"@innet/switch": "^1.0.0",
|
|
29
|
-
"@innet/utils": "^1.1.
|
|
30
|
-
"@types/cookie": "^0.
|
|
31
|
-
"cookie": "^0.
|
|
29
|
+
"@innet/utils": "^1.1.1",
|
|
30
|
+
"@types/cookie": "^0.5.1",
|
|
31
|
+
"cookie": "^0.5.0",
|
|
32
32
|
"http-proxy": "^1.18.1",
|
|
33
33
|
"innet": "^1.0.0",
|
|
34
34
|
"is-invalid-path": "^1.0.2",
|
|
35
35
|
"mime": "^3.0.0",
|
|
36
36
|
"multiparty": "^4.2.3",
|
|
37
|
-
"tslib": "^2.
|
|
38
|
-
"watch-state": "^3.4.
|
|
37
|
+
"tslib": "^2.4.0",
|
|
38
|
+
"watch-state": "^3.4.4"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/plugins/cms/cms.d.ts
CHANGED
package/plugins/cms/cms.es6.js
CHANGED
package/plugins/cms/cms.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
|
-
var Action = require('../../action/Action/Action.js');
|
|
7
6
|
var file = require('../file/file.js');
|
|
7
|
+
var Action = require('../../action/Action/Action.js');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
10
|
|
package/plugins/index.es6.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { cookie } from './cookie/cookie.es6.js';
|
|
2
2
|
export { header } from './header/header.es6.js';
|
|
3
|
-
export { ROUTER, getMatchReg,
|
|
3
|
+
export { ROUTER, getMatchReg, router, useRouter } from './router/router.es6.js';
|
|
4
4
|
export { success, successStatuses } from './success/success.es6.js';
|
|
5
5
|
export { error, errorStatuses } from './error/error.es6.js';
|
|
6
6
|
export { cms } from './cms/cms.es6.js';
|
package/plugins/index.js
CHANGED
|
@@ -18,9 +18,8 @@ exports.cookie = cookie.cookie;
|
|
|
18
18
|
exports.header = header.header;
|
|
19
19
|
exports.ROUTER = router.ROUTER;
|
|
20
20
|
exports.getMatchReg = router.getMatchReg;
|
|
21
|
-
exports.getRouter = router.getRouter;
|
|
22
21
|
exports.router = router.router;
|
|
23
|
-
exports.
|
|
22
|
+
exports.useRouter = router.useRouter;
|
|
24
23
|
exports.success = success.success;
|
|
25
24
|
exports.successStatuses = success.successStatuses;
|
|
26
25
|
exports.error = error.error;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export interface RedirectProps {
|
|
2
|
-
to: string;
|
|
3
|
-
status?: number | keyof typeof redirectStatuses;
|
|
4
|
-
}
|
|
5
1
|
export declare const redirectStatuses: {
|
|
6
2
|
multipleChoices: number;
|
|
7
3
|
movedPermanently: number;
|
|
@@ -12,6 +8,10 @@ export declare const redirectStatuses: {
|
|
|
12
8
|
temporaryRedirect: number;
|
|
13
9
|
permanentRedirect: number;
|
|
14
10
|
};
|
|
11
|
+
export interface RedirectProps {
|
|
12
|
+
to: string;
|
|
13
|
+
status?: number | keyof typeof redirectStatuses;
|
|
14
|
+
}
|
|
15
15
|
export declare function redirect({ props, children }: {
|
|
16
16
|
props: any;
|
|
17
17
|
children: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ROUTER, getMatchReg,
|
|
1
|
+
export { ROUTER, getMatchReg, router, useRouter } from './router.es6.js';
|
package/plugins/router/index.js
CHANGED
|
@@ -8,6 +8,5 @@ var router = require('./router.js');
|
|
|
8
8
|
|
|
9
9
|
exports.ROUTER = router.ROUTER;
|
|
10
10
|
exports.getMatchReg = router.getMatchReg;
|
|
11
|
-
exports.getRouter = router.getRouter;
|
|
12
11
|
exports.router = router.router;
|
|
13
|
-
exports.
|
|
12
|
+
exports.useRouter = router.useRouter;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Children, Component, Props } from '@innet/jsx';
|
|
2
|
-
import { Handler } from 'innet';
|
|
3
1
|
import { Action } from '../../action';
|
|
4
2
|
export declare type Methods = 'GET' | 'HEAD' | 'POST' | 'DELETE' | 'PUT' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
|
5
3
|
export interface RouterProps {
|
|
@@ -15,15 +13,7 @@ export interface Router {
|
|
|
15
13
|
params?: Record<string, string>;
|
|
16
14
|
}
|
|
17
15
|
export declare const ROUTER: string;
|
|
18
|
-
export
|
|
19
|
-
router: Router;
|
|
20
|
-
}
|
|
21
|
-
export interface RouterComponentConstructor {
|
|
22
|
-
new (props?: Props, children?: Children, handler?: Handler): RouterComponent;
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
}
|
|
25
|
-
export declare function getRouter(handler: Handler): Router;
|
|
26
|
-
export declare function withRouter<T extends RouterComponentConstructor>(target: T): T;
|
|
16
|
+
export declare function useRouter(): Router;
|
|
27
17
|
export declare function router({ props, children }: {
|
|
28
18
|
props: any;
|
|
29
19
|
children: any;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
|
+
import { useHandler } from '@innet/jsx';
|
|
2
3
|
import { ACTION } from '../../action/Action/Action.es6.js';
|
|
3
4
|
|
|
4
5
|
function getMatchReg(props) {
|
|
@@ -6,16 +7,8 @@ function getMatchReg(props) {
|
|
|
6
7
|
return `^${path ? `${path}${ish ? '(/[^?]*)?' : ''}` : '[^?]*'}(\\?.*)?$`;
|
|
7
8
|
}
|
|
8
9
|
const ROUTER = Symbol('Parent Router');
|
|
9
|
-
function
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
function withRouter(target) {
|
|
13
|
-
const originInit = target.prototype.init;
|
|
14
|
-
target.prototype.init = function init(...args) {
|
|
15
|
-
this.router = args[2][ROUTER];
|
|
16
|
-
return originInit.apply(this, args);
|
|
17
|
-
};
|
|
18
|
-
return target;
|
|
10
|
+
function useRouter() {
|
|
11
|
+
return useHandler()[ROUTER];
|
|
19
12
|
}
|
|
20
13
|
function router({ props, children }, handler) {
|
|
21
14
|
var _a;
|
|
@@ -54,4 +47,4 @@ function router({ props, children }, handler) {
|
|
|
54
47
|
return innet(children.length > 1 ? children : children[0], newHandler);
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
export { ROUTER, getMatchReg,
|
|
50
|
+
export { ROUTER, getMatchReg, router, useRouter };
|
package/plugins/router/router.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
|
+
var jsx = require('@innet/jsx');
|
|
6
7
|
var Action = require('../../action/Action/Action.js');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -14,20 +15,8 @@ function getMatchReg(props) {
|
|
|
14
15
|
return "^".concat(path ? "".concat(path).concat(ish ? '(/[^?]*)?' : '') : '[^?]*', "(\\?.*)?$");
|
|
15
16
|
}
|
|
16
17
|
var ROUTER = Symbol('Parent Router');
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
function withRouter(target) {
|
|
21
|
-
var originInit = target.prototype.init;
|
|
22
|
-
target.prototype.init = function init() {
|
|
23
|
-
var args = [];
|
|
24
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
25
|
-
args[_i] = arguments[_i];
|
|
26
|
-
}
|
|
27
|
-
this.router = args[2][ROUTER];
|
|
28
|
-
return originInit.apply(this, args);
|
|
29
|
-
};
|
|
30
|
-
return target;
|
|
18
|
+
function useRouter() {
|
|
19
|
+
return jsx.useHandler()[ROUTER];
|
|
31
20
|
}
|
|
32
21
|
function router(_a, handler) {
|
|
33
22
|
var _b;
|
|
@@ -69,6 +58,5 @@ function router(_a, handler) {
|
|
|
69
58
|
|
|
70
59
|
exports.ROUTER = ROUTER;
|
|
71
60
|
exports.getMatchReg = getMatchReg;
|
|
72
|
-
exports.getRouter = getRouter;
|
|
73
61
|
exports.router = router;
|
|
74
|
-
exports.
|
|
62
|
+
exports.useRouter = useRouter;
|
package/server/server.es6.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
+
import innet from 'innet';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import http from 'http';
|
|
4
5
|
import http2 from 'https';
|
|
5
|
-
import innet from 'innet';
|
|
6
6
|
import { onDestroy } from 'watch-state';
|
|
7
7
|
import { ACTION, Action } from '../action/Action/Action.es6.js';
|
|
8
8
|
import { CONTINUE } from '../constants.es6.js';
|
|
@@ -17,7 +17,7 @@ function server({ props = {}, children }, handler) {
|
|
|
17
17
|
if (!isInvalidPath(cert)) {
|
|
18
18
|
cert = fs.readFileSync(cert).toString();
|
|
19
19
|
}
|
|
20
|
-
const https = (key && cert);
|
|
20
|
+
const https = Boolean(key && cert);
|
|
21
21
|
const { port = env.PORT || (https ? 442 : 80), unknownError = '', onStart, onError, onRequest } = props;
|
|
22
22
|
const server = https ? http2.createServer({ key, cert }) : http.createServer();
|
|
23
23
|
onDestroy(() => {
|
package/server/server.js
CHANGED
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
+
var innet = require('innet');
|
|
6
7
|
var fs = require('fs');
|
|
7
8
|
var http = require('http');
|
|
8
9
|
var http2 = require('https');
|
|
9
|
-
var innet = require('innet');
|
|
10
10
|
var watchState = require('watch-state');
|
|
11
11
|
var Action = require('../action/Action/Action.js');
|
|
12
12
|
var constants = require('../constants.js');
|
|
13
13
|
|
|
14
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
15
|
|
|
16
|
+
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
16
17
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
17
18
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
18
19
|
var http2__default = /*#__PURE__*/_interopDefaultLegacy(http2);
|
|
19
|
-
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
20
20
|
|
|
21
21
|
var isInvalidPath = require('is-invalid-path');
|
|
22
22
|
function server(_a, handler) {
|
|
@@ -30,7 +30,7 @@ function server(_a, handler) {
|
|
|
30
30
|
if (!isInvalidPath(cert)) {
|
|
31
31
|
cert = fs__default["default"].readFileSync(cert).toString();
|
|
32
32
|
}
|
|
33
|
-
var https = (key && cert);
|
|
33
|
+
var https = Boolean(key && cert);
|
|
34
34
|
var _g = props.port, port = _g === void 0 ? env.PORT || (https ? 442 : 80) : _g, _h = props.unknownError, unknownError = _h === void 0 ? '' : _h, onStart = props.onStart, onError = props.onError, onRequest = props.onRequest;
|
|
35
35
|
var server = https ? http2__default["default"].createServer({ key: key, cert: cert }) : http__default["default"].createServer();
|
|
36
36
|
watchState.onDestroy(function () {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getAction';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getAction } from './getAction.es6.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './withAction';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { withAction } from './withAction.es6.js';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Children, Component, Props } from '@innet/jsx';
|
|
2
|
-
import { Handler } from 'innet';
|
|
3
|
-
import { Action, Body } from '../Action';
|
|
4
|
-
export interface ActionComponent<B extends Body> extends Component {
|
|
5
|
-
action: Action<B>;
|
|
6
|
-
}
|
|
7
|
-
export interface RequestComponentConstructor<B extends Body> {
|
|
8
|
-
new (props?: Props, children?: Children, handler?: Handler): ActionComponent<B>;
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}
|
|
11
|
-
export declare function withAction<B extends Body, T extends RequestComponentConstructor<B>>(target: T): T;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ACTION } from '../Action/Action.es6.js';
|
|
2
|
-
|
|
3
|
-
function withAction(target) {
|
|
4
|
-
const originInit = target.prototype.init;
|
|
5
|
-
target.prototype.init = function init(...args) {
|
|
6
|
-
this.action = args[2][ACTION];
|
|
7
|
-
return originInit.apply(this, args);
|
|
8
|
-
};
|
|
9
|
-
return target;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { withAction };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var Action = require('../Action/Action.js');
|
|
6
|
-
|
|
7
|
-
function withAction(target) {
|
|
8
|
-
var originInit = target.prototype.init;
|
|
9
|
-
target.prototype.init = function init() {
|
|
10
|
-
var args = [];
|
|
11
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
-
args[_i] = arguments[_i];
|
|
13
|
-
}
|
|
14
|
-
this.action = args[2][Action.ACTION];
|
|
15
|
-
return originInit.apply(this, args);
|
|
16
|
-
};
|
|
17
|
-
return target;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.withAction = withAction;
|