@innet/server 1.1.2 → 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 +56 -70
- 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/index.d.ts +1 -0
- package/experimental/serverFn/index.es6.js +1 -0
- package/experimental/serverFn/index.js +9 -0
- package/experimental/serverFn/serverFn.d.ts +2 -0
- package/experimental/serverFn/serverFn.es6.js +12 -0
- package/experimental/serverFn/serverFn.js +20 -0
- package/handler/handler.d.ts +6 -4
- package/handler/handler.es6.js +13 -6
- package/handler/handler.js +13 -4
- package/handler/index.d.ts +0 -1
- package/handler/index.es6.js +1 -1
- package/handler/index.js +3 -1
- package/index.d.ts +1 -1
- package/index.es6.js +3 -5
- package/index.js +6 -7
- package/package.json +9 -8
- 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.d.ts +1 -0
- package/server/server.es6.js +8 -2
- package/server/server.js +9 -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
|
@@ -124,6 +124,18 @@ export default (
|
|
|
124
124
|
)
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
### onDestroy
|
|
128
|
+
You can react on destroy the server with `onDestroy` prop.
|
|
129
|
+
|
|
130
|
+
```typescript jsx
|
|
131
|
+
export default (
|
|
132
|
+
<server
|
|
133
|
+
onDestroy={() => console.log('destroy')}>
|
|
134
|
+
Hello World!
|
|
135
|
+
</server>
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
127
139
|
## HTML
|
|
128
140
|
You can use `html` element to return html content.
|
|
129
141
|
|
|
@@ -455,9 +467,9 @@ export default (
|
|
|
455
467
|
)
|
|
456
468
|
```
|
|
457
469
|
|
|
458
|
-
##
|
|
470
|
+
## Components
|
|
459
471
|
|
|
460
|
-
Any
|
|
472
|
+
Any component is just a function which returns content that should be run.
|
|
461
473
|
|
|
462
474
|
`server.tsx`
|
|
463
475
|
```typescript jsx
|
|
@@ -484,18 +496,24 @@ export default <Server cmsPrefix='/cms' />
|
|
|
484
496
|
You can use it with any other functionality, for example with `html`.
|
|
485
497
|
|
|
486
498
|
```typescript jsx
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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>
|
|
490
507
|
<head>
|
|
491
508
|
<title>{title}</title>
|
|
492
509
|
</head>
|
|
493
510
|
<body>
|
|
494
511
|
{children}
|
|
495
512
|
</body>
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
)
|
|
513
|
+
</html>
|
|
514
|
+
</header>
|
|
515
|
+
)
|
|
516
|
+
}
|
|
499
517
|
|
|
500
518
|
export default (
|
|
501
519
|
<server>
|
|
@@ -508,39 +526,7 @@ export default (
|
|
|
508
526
|
|
|
509
527
|
The first argument is props, the second is children and the last one is a handler.
|
|
510
528
|
|
|
511
|
-
You can use
|
|
512
|
-
|
|
513
|
-
## Components
|
|
514
|
-
Component has the same functionality as template but this is a class.
|
|
515
|
-
|
|
516
|
-
```typescript jsx
|
|
517
|
-
class Html {
|
|
518
|
-
init ({ title }, children) {
|
|
519
|
-
return (
|
|
520
|
-
<header name='content-type' value='text/html'>
|
|
521
|
-
<html>
|
|
522
|
-
<head>
|
|
523
|
-
<title>{title}</title>
|
|
524
|
-
</head>
|
|
525
|
-
<body>
|
|
526
|
-
{children}
|
|
527
|
-
</body>
|
|
528
|
-
</html>
|
|
529
|
-
</header>
|
|
530
|
-
)
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
export default (
|
|
535
|
-
<server>
|
|
536
|
-
<Html title='main'>
|
|
537
|
-
Hello World!
|
|
538
|
-
</Html>
|
|
539
|
-
</server>
|
|
540
|
-
)
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
constructor of the class gets the same arguments as init method and the same as a template.
|
|
529
|
+
You can use components inside another component.
|
|
544
530
|
|
|
545
531
|
## success
|
|
546
532
|
If you work on REST API, you can use `success` or `error` as an answer
|
|
@@ -696,18 +682,17 @@ export default (
|
|
|
696
682
|
)
|
|
697
683
|
```
|
|
698
684
|
|
|
699
|
-
##
|
|
685
|
+
## useAction
|
|
700
686
|
Action is an object which contains `request` and `response`.
|
|
701
687
|
Also, it contains a couple of fields and methods.
|
|
702
688
|
|
|
703
|
-
Action available in
|
|
689
|
+
Action available in components.
|
|
704
690
|
|
|
705
691
|
```typescript jsx
|
|
706
|
-
import {
|
|
692
|
+
import { useAction } from '@innet/server'
|
|
707
693
|
|
|
708
|
-
|
|
709
|
-
const
|
|
710
|
-
const { req, res } = action
|
|
694
|
+
function Test () {
|
|
695
|
+
const { req, res } = useAction()
|
|
711
696
|
|
|
712
697
|
console.log(req, res)
|
|
713
698
|
}
|
|
@@ -717,10 +702,10 @@ const Test = (props, child, handler) => {
|
|
|
717
702
|
You can get cookies as an object from an action.
|
|
718
703
|
|
|
719
704
|
```typescript jsx
|
|
720
|
-
import {
|
|
705
|
+
import { useAction } from '@innet/server'
|
|
721
706
|
|
|
722
|
-
|
|
723
|
-
const { cookies } =
|
|
707
|
+
function Cookies () {
|
|
708
|
+
const { cookies } = useAction()
|
|
724
709
|
|
|
725
710
|
return <success>{cookies}</success>
|
|
726
711
|
}
|
|
@@ -730,11 +715,12 @@ const Cookies = (props, child, handler) => {
|
|
|
730
715
|
You can set cookie with action.
|
|
731
716
|
|
|
732
717
|
```typescript jsx
|
|
733
|
-
import {
|
|
718
|
+
import { useAction } from '@innet/server'
|
|
719
|
+
|
|
720
|
+
function Login () {
|
|
721
|
+
const action = useAction()
|
|
734
722
|
|
|
735
|
-
|
|
736
|
-
getAction(handler)
|
|
737
|
-
.setCookie('user', 'token')
|
|
723
|
+
action.setCookie('user', 'token')
|
|
738
724
|
}
|
|
739
725
|
```
|
|
740
726
|
|
|
@@ -742,10 +728,10 @@ const Login = (props, child, handler) => {
|
|
|
742
728
|
You can get current path with action.
|
|
743
729
|
|
|
744
730
|
```typescript jsx
|
|
745
|
-
import {
|
|
731
|
+
import { useAction } from '@innet/server'
|
|
746
732
|
|
|
747
|
-
|
|
748
|
-
const { path } =
|
|
733
|
+
function Path () {
|
|
734
|
+
const { path } = useAction()
|
|
749
735
|
|
|
750
736
|
return path
|
|
751
737
|
}
|
|
@@ -755,10 +741,10 @@ const Path = (props, child, handler) => {
|
|
|
755
741
|
You can get current search as an object.
|
|
756
742
|
|
|
757
743
|
```typescript jsx
|
|
758
|
-
import {
|
|
744
|
+
import { useAction } from '@innet/server'
|
|
759
745
|
|
|
760
|
-
|
|
761
|
-
const { search } =
|
|
746
|
+
function Search () {
|
|
747
|
+
const { search } = useAction()
|
|
762
748
|
|
|
763
749
|
return <success>{search}</success>
|
|
764
750
|
}
|
|
@@ -768,10 +754,10 @@ const Search = (props, child, handler) => {
|
|
|
768
754
|
You can parse body, and get values.
|
|
769
755
|
|
|
770
756
|
```typescript jsx
|
|
771
|
-
import {
|
|
757
|
+
import { useAction } from '@innet/server'
|
|
772
758
|
|
|
773
|
-
|
|
774
|
-
const action =
|
|
759
|
+
async function Body () {
|
|
760
|
+
const action = useAction()
|
|
775
761
|
|
|
776
762
|
await action.parseBody()
|
|
777
763
|
|
|
@@ -783,10 +769,10 @@ const Body = async (props, child, handler) => {
|
|
|
783
769
|
You can get files from a user.
|
|
784
770
|
|
|
785
771
|
```typescript jsx
|
|
786
|
-
import {
|
|
772
|
+
import { useAction } from '@innet/server'
|
|
787
773
|
|
|
788
|
-
|
|
789
|
-
const action =
|
|
774
|
+
async function Body () {
|
|
775
|
+
const action = useAction()
|
|
790
776
|
|
|
791
777
|
await action.parseBody()
|
|
792
778
|
|
|
@@ -796,13 +782,13 @@ const Body = async (props, child, handler) => {
|
|
|
796
782
|
|
|
797
783
|
## getRouter
|
|
798
784
|
|
|
799
|
-
You can get router data in a
|
|
785
|
+
You can get router data in a component
|
|
800
786
|
|
|
801
787
|
```typescript jsx
|
|
802
|
-
import {
|
|
788
|
+
import { useRouter } from '@innet/server'
|
|
803
789
|
|
|
804
|
-
|
|
805
|
-
const { prefix, params } =
|
|
790
|
+
async function Router () {
|
|
791
|
+
const { prefix, params } = useRouter()
|
|
806
792
|
|
|
807
793
|
return <success>{{ prefix, params }}</success>
|
|
808
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './serverFn';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { serverFn } from './serverFn.es6.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var innet = require('innet');
|
|
6
|
+
var watchState = require('watch-state');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
11
|
+
|
|
12
|
+
function serverFn() {
|
|
13
|
+
return function (fn, next, handler) {
|
|
14
|
+
var result;
|
|
15
|
+
new watchState.Watch(function (update) { return (result = innet__default["default"](fn(update), handler)); });
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.serverFn = serverFn;
|
package/handler/handler.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import html from '@innet/html';
|
|
2
2
|
import { switchAsync, SwitchProps } from '@innet/switch';
|
|
3
|
-
import { arrayAsync } from '@innet/utils';
|
|
4
|
-
import {
|
|
3
|
+
import { arrayAsync, async } from '@innet/utils';
|
|
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';
|
|
5
6
|
import { server, ServerProps } from '../server';
|
|
6
7
|
export declare const arrayPlugins: (typeof arrayAsync)[];
|
|
7
8
|
export declare const JSXPlugins: {
|
|
@@ -18,9 +19,10 @@ export declare const JSXPlugins: {
|
|
|
18
19
|
proxy: typeof proxy;
|
|
19
20
|
redirect: typeof redirect;
|
|
20
21
|
};
|
|
22
|
+
export declare const fnPlugins: (typeof serverFn)[];
|
|
21
23
|
export declare const objectPlugins: ((handler: any) => import("innet").PluginHandler)[];
|
|
22
|
-
declare const
|
|
23
|
-
export
|
|
24
|
+
export declare const promisePlugins: (typeof async)[];
|
|
25
|
+
export declare const handler: import("innet").Handler;
|
|
24
26
|
declare global {
|
|
25
27
|
namespace JSX {
|
|
26
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, jsxComponent
|
|
3
|
+
import { jsxPlugins, jsxComponent } from '@innet/jsx';
|
|
3
4
|
import { switchAsync } from '@innet/switch';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { promise, array, object, fn, arrayAsync, arrayClear, arraySingleLess, async } from '@innet/utils';
|
|
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';
|
|
@@ -33,15 +34,21 @@ const JSXPlugins = {
|
|
|
33
34
|
proxy,
|
|
34
35
|
redirect,
|
|
35
36
|
};
|
|
37
|
+
const fnPlugins = [
|
|
38
|
+
serverFn,
|
|
39
|
+
];
|
|
36
40
|
const objectPlugins = [
|
|
37
41
|
jsxPlugins(JSXPlugins),
|
|
38
42
|
jsxComponent,
|
|
39
|
-
jsxTemplate,
|
|
40
43
|
];
|
|
41
|
-
|
|
44
|
+
const promisePlugins = [
|
|
42
45
|
async,
|
|
46
|
+
];
|
|
47
|
+
const handler = createHandler([
|
|
48
|
+
promise(promisePlugins),
|
|
43
49
|
array(arrayPlugins),
|
|
44
50
|
object(objectPlugins),
|
|
51
|
+
fn(fnPlugins),
|
|
45
52
|
]);
|
|
46
53
|
|
|
47
|
-
export { JSXPlugins, arrayPlugins, handler
|
|
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');
|
|
@@ -41,18 +42,26 @@ var JSXPlugins = {
|
|
|
41
42
|
proxy: proxy.proxy,
|
|
42
43
|
redirect: redirect.redirect,
|
|
43
44
|
};
|
|
45
|
+
var fnPlugins = [
|
|
46
|
+
serverFn.serverFn,
|
|
47
|
+
];
|
|
44
48
|
var objectPlugins = [
|
|
45
49
|
jsx.jsxPlugins(JSXPlugins),
|
|
46
50
|
jsx.jsxComponent,
|
|
47
|
-
jsx.jsxTemplate,
|
|
48
51
|
];
|
|
49
|
-
var
|
|
52
|
+
var promisePlugins = [
|
|
50
53
|
utils.async,
|
|
54
|
+
];
|
|
55
|
+
var handler = innet.createHandler([
|
|
56
|
+
utils.promise(promisePlugins),
|
|
51
57
|
utils.array(arrayPlugins),
|
|
52
58
|
utils.object(objectPlugins),
|
|
59
|
+
utils.fn(fnPlugins),
|
|
53
60
|
]);
|
|
54
61
|
|
|
55
62
|
exports.JSXPlugins = JSXPlugins;
|
|
56
63
|
exports.arrayPlugins = arrayPlugins;
|
|
57
|
-
exports
|
|
64
|
+
exports.fnPlugins = fnPlugins;
|
|
65
|
+
exports.handler = handler;
|
|
58
66
|
exports.objectPlugins = objectPlugins;
|
|
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,5 +8,7 @@ var handler = require('./handler.js');
|
|
|
8
8
|
|
|
9
9
|
exports.JSXPlugins = handler.JSXPlugins;
|
|
10
10
|
exports.arrayPlugins = handler.arrayPlugins;
|
|
11
|
-
exports
|
|
11
|
+
exports.fnPlugins = handler.fnPlugins;
|
|
12
|
+
exports.handler = handler.handler;
|
|
12
13
|
exports.objectPlugins = handler.objectPlugins;
|
|
14
|
+
exports.promisePlugins = handler.promisePlugins;
|
package/index.d.ts
CHANGED
package/index.es6.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
export { JSXPlugins, arrayPlugins, default, objectPlugins } 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,23 +14,23 @@ 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;
|
|
23
|
+
exports.fnPlugins = handler.fnPlugins;
|
|
24
|
+
exports.handler = handler.handler;
|
|
25
25
|
exports.objectPlugins = handler.objectPlugins;
|
|
26
|
+
exports.promisePlugins = handler.promisePlugins;
|
|
26
27
|
exports.server = server.server;
|
|
27
28
|
exports.cookie = cookie.cookie;
|
|
28
29
|
exports.header = header.header;
|
|
29
30
|
exports.ROUTER = router.ROUTER;
|
|
30
31
|
exports.getMatchReg = router.getMatchReg;
|
|
31
|
-
exports.getRouter = router.getRouter;
|
|
32
32
|
exports.router = router.router;
|
|
33
|
-
exports.
|
|
33
|
+
exports.useRouter = router.useRouter;
|
|
34
34
|
exports.success = success.success;
|
|
35
35
|
exports.successStatuses = success.successStatuses;
|
|
36
36
|
exports.error = error.error;
|
|
@@ -43,5 +43,4 @@ exports.redirectStatuses = redirect.redirectStatuses;
|
|
|
43
43
|
exports.ACTION = Action.ACTION;
|
|
44
44
|
exports.Action = Action.Action;
|
|
45
45
|
exports.URL_PARSER = Action.URL_PARSER;
|
|
46
|
-
exports.
|
|
47
|
-
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,18 +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": "^
|
|
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.
|
|
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.
|
|
37
|
+
"tslib": "^2.4.0",
|
|
38
|
+
"watch-state": "^3.4.4"
|
|
38
39
|
}
|
|
39
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.d.ts
CHANGED
package/server/server.es6.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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
|
|
6
|
+
import { onDestroy } from 'watch-state';
|
|
6
7
|
import { ACTION, Action } from '../action/Action/Action.es6.js';
|
|
7
8
|
import { CONTINUE } from '../constants.es6.js';
|
|
8
9
|
|
|
@@ -16,9 +17,14 @@ function server({ props = {}, children }, handler) {
|
|
|
16
17
|
if (!isInvalidPath(cert)) {
|
|
17
18
|
cert = fs.readFileSync(cert).toString();
|
|
18
19
|
}
|
|
19
|
-
const https = (key && cert);
|
|
20
|
+
const https = Boolean(key && cert);
|
|
20
21
|
const { port = env.PORT || (https ? 442 : 80), unknownError = '', onStart, onError, onRequest } = props;
|
|
21
22
|
const server = https ? http2.createServer({ key, cert }) : http.createServer();
|
|
23
|
+
onDestroy(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = props.onDestroy) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
26
|
+
server.close();
|
|
27
|
+
});
|
|
22
28
|
server.on('request', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
23
29
|
const childHandler = Object.create(handler);
|
|
24
30
|
childHandler[ACTION] = new Action(req, res);
|
package/server/server.js
CHANGED
|
@@ -3,19 +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
|
|
10
|
+
var watchState = require('watch-state');
|
|
10
11
|
var Action = require('../action/Action/Action.js');
|
|
11
12
|
var constants = require('../constants.js');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
15
|
|
|
16
|
+
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
15
17
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
16
18
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
17
19
|
var http2__default = /*#__PURE__*/_interopDefaultLegacy(http2);
|
|
18
|
-
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
19
20
|
|
|
20
21
|
var isInvalidPath = require('is-invalid-path');
|
|
21
22
|
function server(_a, handler) {
|
|
@@ -29,9 +30,14 @@ function server(_a, handler) {
|
|
|
29
30
|
if (!isInvalidPath(cert)) {
|
|
30
31
|
cert = fs__default["default"].readFileSync(cert).toString();
|
|
31
32
|
}
|
|
32
|
-
var https = (key && cert);
|
|
33
|
+
var https = Boolean(key && cert);
|
|
33
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;
|
|
34
35
|
var server = https ? http2__default["default"].createServer({ key: key, cert: cert }) : http__default["default"].createServer();
|
|
36
|
+
watchState.onDestroy(function () {
|
|
37
|
+
var _a;
|
|
38
|
+
(_a = props.onDestroy) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
39
|
+
server.close();
|
|
40
|
+
});
|
|
35
41
|
server.on('request', function (req, res) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
36
42
|
var childHandler, result, e_1;
|
|
37
43
|
return tslib.__generator(this, function (_a) {
|
|
@@ -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;
|