@innet/server 1.1.1 → 1.1.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/README.md CHANGED
@@ -696,19 +696,19 @@ export default (
696
696
  )
697
697
  ```
698
698
 
699
- ## ACTION
699
+ ## getAction
700
700
  Action is an object which contains `request` and `response`.
701
701
  Also, it contains a couple of fields and methods.
702
702
 
703
703
  Action available in templates and components.
704
704
 
705
705
  ```typescript jsx
706
- import { ACTION } from '@innet/server'
706
+ import { getAction } from '@innet/server'
707
707
 
708
708
  const Test = (props, child, handler) => {
709
- const action = handler[ACTION]
709
+ const action = getAction(handler)
710
710
  const { req, res } = action
711
-
711
+
712
712
  console.log(req, res)
713
713
  }
714
714
  ```
@@ -717,10 +717,10 @@ const Test = (props, child, handler) => {
717
717
  You can get cookies as an object from an action.
718
718
 
719
719
  ```typescript jsx
720
- import { ACTION } from '@innet/server'
720
+ import { getAction } from '@innet/server'
721
721
 
722
722
  const Cookies = (props, child, handler) => {
723
- const { cookies } = handler[ACTION]
723
+ const { cookies } = getAction(handler)
724
724
 
725
725
  return <success>{cookies}</success>
726
726
  }
@@ -730,12 +730,11 @@ const Cookies = (props, child, handler) => {
730
730
  You can set cookie with action.
731
731
 
732
732
  ```typescript jsx
733
- import { ACTION } from '@innet/server'
733
+ import { getAction } from '@innet/server'
734
734
 
735
735
  const Login = (props, child, handler) => {
736
- const action = handler[ACTION]
737
-
738
- action.setCookie('user', 'token')
736
+ getAction(handler)
737
+ .setCookie('user', 'token')
739
738
  }
740
739
  ```
741
740
 
@@ -743,10 +742,10 @@ const Login = (props, child, handler) => {
743
742
  You can get current path with action.
744
743
 
745
744
  ```typescript jsx
746
- import { ACTION } from '@innet/server'
745
+ import { getAction } from '@innet/server'
747
746
 
748
747
  const Path = (props, child, handler) => {
749
- const { path } = handler[ACTION]
748
+ const { path } = getAction(handler)
750
749
 
751
750
  return path
752
751
  }
@@ -756,10 +755,10 @@ const Path = (props, child, handler) => {
756
755
  You can get current search as an object.
757
756
 
758
757
  ```typescript jsx
759
- import { ACTION } from '@innet/server'
758
+ import { getAction } from '@innet/server'
760
759
 
761
760
  const Search = (props, child, handler) => {
762
- const { search } = handler[ACTION]
761
+ const { search } = getAction(handler)
763
762
 
764
763
  return <success>{search}</success>
765
764
  }
@@ -769,10 +768,10 @@ const Search = (props, child, handler) => {
769
768
  You can parse body, and get values.
770
769
 
771
770
  ```typescript jsx
772
- import { ACTION } from '@innet/server'
771
+ import { getAction } from '@innet/server'
773
772
 
774
773
  const Body = async (props, child, handler) => {
775
- const action = handler[ACTION]
774
+ const action = getAction(handler)
776
775
 
777
776
  await action.parseBody()
778
777
 
@@ -784,10 +783,10 @@ const Body = async (props, child, handler) => {
784
783
  You can get files from a user.
785
784
 
786
785
  ```typescript jsx
787
- import { ACTION } from '@innet/server'
786
+ import { getAction } from '@innet/server'
788
787
 
789
788
  const Body = async (props, child, handler) => {
790
- const action = handler[ACTION]
789
+ const action = getAction(handler)
791
790
 
792
791
  await action.parseBody()
793
792
 
@@ -795,15 +794,15 @@ const Body = async (props, child, handler) => {
795
794
  }
796
795
  ```
797
796
 
798
- ## ROUTER
797
+ ## getRouter
799
798
 
800
799
  You can get router data in a template or component
801
800
 
802
801
  ```typescript jsx
803
- import { ROUTER } from '@innet/server'
802
+ import { getRouter } from '@innet/server'
804
803
 
805
804
  const Router = async (props, child, handler) => {
806
- const { prefix, params } = handler[ROUTER]
805
+ const { prefix, params } = getRouter(handler)
807
806
 
808
807
  return <success>{{ prefix, params }}</success>
809
808
  }
@@ -0,0 +1,3 @@
1
+ import { Handler } from 'innet';
2
+ import { Action, ActionOptions } from '../Action';
3
+ export declare function getAction<O extends ActionOptions>(handler: Handler): Action<O>;
@@ -0,0 +1,7 @@
1
+ import { ACTION } from '../Action/Action.es6.js';
2
+
3
+ function getAction(handler) {
4
+ return handler[ACTION];
5
+ }
6
+
7
+ export { getAction };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Action = require('../Action/Action.js');
6
+
7
+ function getAction(handler) {
8
+ return handler[Action.ACTION];
9
+ }
10
+
11
+ exports.getAction = getAction;
@@ -0,0 +1 @@
1
+ export * from './getAction';
@@ -0,0 +1 @@
1
+ export { getAction } from './getAction.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var getAction = require('./getAction.js');
6
+
7
+
8
+
9
+ exports.getAction = getAction.getAction;
package/action/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './Action';
2
2
  export * from './withAction';
3
+ export * from './getAction';
@@ -1,2 +1,3 @@
1
1
  export { ACTION, Action, URL_PARSER } from './Action/Action.es6.js';
2
2
  export { withAction } from './withAction/withAction.es6.js';
3
+ export { getAction } from './getAction/getAction.es6.js';
package/action/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var Action = require('./Action/Action.js');
6
6
  var withAction = require('./withAction/withAction.js');
7
+ var getAction = require('./getAction/getAction.js');
7
8
 
8
9
 
9
10
 
@@ -11,3 +12,4 @@ exports.ACTION = Action.ACTION;
11
12
  exports.Action = Action.Action;
12
13
  exports.URL_PARSER = Action.URL_PARSER;
13
14
  exports.withAction = withAction.withAction;
15
+ exports.getAction = getAction.getAction;
package/index.es6.js CHANGED
@@ -2,7 +2,7 @@ export { JSXPlugins, arrayPlugins, default, objectPlugins } from './handler/hand
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, router, withRouter } from './plugins/router/router.es6.js';
5
+ export { ROUTER, getMatchReg, getRouter, router, withRouter } 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';
@@ -11,3 +11,4 @@ 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 } from './action/Action/Action.es6.js';
13
13
  export { withAction } from './action/withAction/withAction.es6.js';
14
+ export { getAction } from './action/getAction/getAction.es6.js';
package/index.js CHANGED
@@ -15,6 +15,7 @@ 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
17
  var withAction = require('./action/withAction/withAction.js');
18
+ var getAction = require('./action/getAction/getAction.js');
18
19
 
19
20
 
20
21
 
@@ -27,6 +28,7 @@ exports.cookie = cookie.cookie;
27
28
  exports.header = header.header;
28
29
  exports.ROUTER = router.ROUTER;
29
30
  exports.getMatchReg = router.getMatchReg;
31
+ exports.getRouter = router.getRouter;
30
32
  exports.router = router.router;
31
33
  exports.withRouter = router.withRouter;
32
34
  exports.success = success.success;
@@ -42,3 +44,4 @@ exports.ACTION = Action.ACTION;
42
44
  exports.Action = Action.Action;
43
45
  exports.URL_PARSER = Action.URL_PARSER;
44
46
  exports.withAction = withAction.withAction;
47
+ exports.getAction = getAction.getAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -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, router, withRouter } from './router/router.es6.js';
3
+ export { ROUTER, getMatchReg, getRouter, router, withRouter } 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,6 +18,7 @@ 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;
21
22
  exports.router = router.router;
22
23
  exports.withRouter = router.withRouter;
23
24
  exports.success = success.success;
@@ -1 +1 @@
1
- export { ROUTER, getMatchReg, router, withRouter } from './router.es6.js';
1
+ export { ROUTER, getMatchReg, getRouter, router, withRouter } from './router.es6.js';
@@ -8,5 +8,6 @@ var router = require('./router.js');
8
8
 
9
9
  exports.ROUTER = router.ROUTER;
10
10
  exports.getMatchReg = router.getMatchReg;
11
+ exports.getRouter = router.getRouter;
11
12
  exports.router = router.router;
12
13
  exports.withRouter = router.withRouter;
@@ -22,6 +22,7 @@ export interface RouterComponentConstructor {
22
22
  new (props?: Props, children?: Children, handler?: Handler): RouterComponent;
23
23
  [key: string]: any;
24
24
  }
25
+ export declare function getRouter(handler: Handler): Router;
25
26
  export declare function withRouter<T extends RouterComponentConstructor>(target: T): T;
26
27
  export declare function router({ props, children }: {
27
28
  props: any;
@@ -6,6 +6,9 @@ function getMatchReg(props) {
6
6
  return `^${path ? `${path}${ish ? '(/[^?]*)?' : ''}` : '[^?]*'}(\\?.*)?$`;
7
7
  }
8
8
  const ROUTER = Symbol('Parent Router');
9
+ function getRouter(handler) {
10
+ return handler[ROUTER];
11
+ }
9
12
  function withRouter(target) {
10
13
  const originInit = target.prototype.init;
11
14
  target.prototype.init = function init(...args) {
@@ -51,4 +54,4 @@ function router({ props, children }, handler) {
51
54
  return innet(children.length > 1 ? children : children[0], newHandler);
52
55
  }
53
56
 
54
- export { ROUTER, getMatchReg, router, withRouter };
57
+ export { ROUTER, getMatchReg, getRouter, router, withRouter };
@@ -14,6 +14,9 @@ function getMatchReg(props) {
14
14
  return "^".concat(path ? "".concat(path).concat(ish ? '(/[^?]*)?' : '') : '[^?]*', "(\\?.*)?$");
15
15
  }
16
16
  var ROUTER = Symbol('Parent Router');
17
+ function getRouter(handler) {
18
+ return handler[ROUTER];
19
+ }
17
20
  function withRouter(target) {
18
21
  var originInit = target.prototype.init;
19
22
  target.prototype.init = function init() {
@@ -66,5 +69,6 @@ function router(_a, handler) {
66
69
 
67
70
  exports.ROUTER = ROUTER;
68
71
  exports.getMatchReg = getMatchReg;
72
+ exports.getRouter = getRouter;
69
73
  exports.router = router;
70
74
  exports.withRouter = withRouter;