@innet/server 1.3.0 → 1.4.1

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.
Files changed (62) hide show
  1. package/README.md +39 -33
  2. package/action/Action/Action.d.ts +11 -9
  3. package/action/Action/Action.es6.js +9 -22
  4. package/action/Action/Action.js +9 -32
  5. package/action/Action/index.es6.js +1 -1
  6. package/action/Action/index.js +1 -0
  7. package/action/index.d.ts +0 -2
  8. package/action/index.es6.js +1 -3
  9. package/action/index.js +1 -4
  10. package/experimental/serverFn/serverFn.es6.js +1 -1
  11. package/experimental/serverFn/serverFn.js +1 -1
  12. package/handler/handler.d.ts +3 -4
  13. package/handler/handler.es6.js +6 -6
  14. package/handler/handler.js +4 -4
  15. package/handler/index.d.ts +0 -1
  16. package/handler/index.es6.js +1 -1
  17. package/handler/index.js +1 -1
  18. package/index.d.ts +2 -1
  19. package/index.es6.js +5 -5
  20. package/index.js +8 -7
  21. package/package.json +11 -9
  22. package/plugins/cms/cms.d.ts +1 -2
  23. package/plugins/cms/cms.es6.js +1 -1
  24. package/plugins/cms/cms.js +1 -1
  25. package/plugins/cookie/cookie.d.ts +1 -1
  26. package/plugins/index.es6.js +1 -1
  27. package/plugins/index.js +1 -2
  28. package/plugins/redirect/redirect.d.ts +4 -4
  29. package/plugins/router/index.es6.js +1 -1
  30. package/plugins/router/index.js +1 -2
  31. package/plugins/router/router.d.ts +1 -11
  32. package/plugins/router/router.es6.js +4 -11
  33. package/plugins/router/router.js +4 -16
  34. package/server/server.es6.js +2 -2
  35. package/server/server.js +3 -3
  36. package/utils/index.d.ts +2 -0
  37. package/utils/index.es6.js +2 -0
  38. package/utils/index.js +11 -0
  39. package/utils/parseSearch/index.d.ts +1 -0
  40. package/utils/parseSearch/index.es6.js +1 -0
  41. package/utils/parseSearch/index.js +9 -0
  42. package/utils/parseSearch/parseSearch.d.ts +2 -0
  43. package/utils/parseSearch/parseSearch.es6.js +7 -0
  44. package/utils/parseSearch/parseSearch.js +16 -0
  45. package/utils/stringifySearch/index.d.ts +1 -0
  46. package/utils/stringifySearch/index.es6.js +1 -0
  47. package/utils/stringifySearch/index.js +9 -0
  48. package/utils/stringifySearch/stringifySearch.d.ts +2 -0
  49. package/utils/stringifySearch/stringifySearch.es6.js +7 -0
  50. package/utils/stringifySearch/stringifySearch.js +16 -0
  51. package/action/getAction/getAction.d.ts +0 -3
  52. package/action/getAction/getAction.es6.js +0 -7
  53. package/action/getAction/getAction.js +0 -11
  54. package/action/getAction/index.d.ts +0 -1
  55. package/action/getAction/index.es6.js +0 -1
  56. package/action/getAction/index.js +0 -9
  57. package/action/withAction/index.d.ts +0 -1
  58. package/action/withAction/index.es6.js +0 -1
  59. package/action/withAction/index.js +0 -9
  60. package/action/withAction/withAction.d.ts +0 -11
  61. package/action/withAction/withAction.es6.js +0 -12
  62. 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
- const Html = ({ title }, children) => (
500
- <header name='content-type' value='text/html'>
501
- <html>
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
- </html>
509
- </header>
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
- ## getAction
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 { getAction } from '@innet/server'
692
+ import { useAction } from '@innet/server'
687
693
 
688
- const Test = (props, child, handler) => {
689
- const action = getAction(handler)
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 { getAction } from '@innet/server'
705
+ import { useAction } from '@innet/server'
701
706
 
702
- const Cookies = (props, child, handler) => {
703
- const { cookies } = getAction(handler)
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 { getAction } from '@innet/server'
718
+ import { useAction } from '@innet/server'
719
+
720
+ function Login () {
721
+ const action = useAction()
714
722
 
715
- const Login = (props, child, handler) => {
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 { getAction } from '@innet/server'
731
+ import { useAction } from '@innet/server'
726
732
 
727
- const Path = (props, child, handler) => {
728
- const { path } = getAction(handler)
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 { getAction } from '@innet/server'
744
+ import { useAction } from '@innet/server'
739
745
 
740
- const Search = (props, child, handler) => {
741
- const { search } = getAction(handler)
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 { getAction } from '@innet/server'
757
+ import { useAction } from '@innet/server'
752
758
 
753
- const Body = async (props, child, handler) => {
754
- const action = getAction(handler)
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 { getAction } from '@innet/server'
772
+ import { useAction } from '@innet/server'
767
773
 
768
- const Body = async (props, child, handler) => {
769
- const action = getAction(handler)
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 { getRouter } from '@innet/server'
788
+ import { useRouter } from '@innet/server'
783
789
 
784
- const Router = async (props, child, handler) => {
785
- const { prefix, params } = getRouter(handler)
790
+ async function Router () {
791
+ const { prefix, params } = useRouter()
786
792
 
787
793
  return <success>{{ prefix, params }}</success>
788
794
  }
@@ -1,11 +1,18 @@
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 = Record<string, any>;
7
+ export declare type Search = ParsedQs;
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,7 @@ 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
+ 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;
@@ -39,3 +40,4 @@ export declare class Action<O extends ActionOptions = ActionOptions> {
39
40
  };
40
41
  get path(): string;
41
42
  }
43
+ export declare function useAction<O extends ActionOptions>(): Action<O>;
@@ -1,7 +1,10 @@
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';
6
+ import { parseSearch } from '../../utils/parseSearch/parseSearch.es6.js';
7
+ import 'qs';
5
8
 
6
9
  const ACTION = Symbol('Action');
7
10
  const URL_PARSER = /^(?<path>[^?]+)(\?(?<search>.*))?/;
@@ -52,26 +55,7 @@ class Action {
52
55
  });
53
56
  }
54
57
  get search() {
55
- const result = Object.create(null);
56
- const search = this.parsedUrl.search || '';
57
- for (const option of search.split('&')) {
58
- const [key, ...value] = option.split('=');
59
- if (key) {
60
- const normValue = value.join('=');
61
- if (key in result) {
62
- if (Array.isArray(result[key])) {
63
- result[key].push(normValue);
64
- }
65
- else {
66
- result[key] = [result[key], normValue];
67
- }
68
- }
69
- else {
70
- result[key] = normValue;
71
- }
72
- }
73
- }
74
- return result;
58
+ return parseSearch(this.parsedUrl.search);
75
59
  }
76
60
  get parsedUrl() {
77
61
  const match = this.req.url.match(URL_PARSER);
@@ -92,6 +76,9 @@ __decorate([
92
76
  ], Action.prototype, "search", null);
93
77
  __decorate([
94
78
  once
95
- ], Action.prototype, "parsedUrl", null);
79
+ ], Action.prototype, "parsedUrl", null);
80
+ function useAction() {
81
+ return useHandler()[ACTION];
82
+ }
96
83
 
97
- export { ACTION, Action, URL_PARSER };
84
+ export { ACTION, Action, URL_PARSER, useAction };
@@ -4,8 +4,11 @@ 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');
10
+ var parseSearch = require('../../utils/parseSearch/parseSearch.js');
11
+ require('qs');
9
12
 
10
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
14
 
@@ -67,37 +70,7 @@ var Action = /** @class */ (function () {
67
70
  };
68
71
  Object.defineProperty(Action.prototype, "search", {
69
72
  get: function () {
70
- var e_1, _a;
71
- var result = Object.create(null);
72
- var search = this.parsedUrl.search || '';
73
- try {
74
- for (var _b = tslib.__values(search.split('&')), _c = _b.next(); !_c.done; _c = _b.next()) {
75
- var option = _c.value;
76
- var _d = tslib.__read(option.split('=')), key = _d[0], value = _d.slice(1);
77
- if (key) {
78
- var normValue = value.join('=');
79
- if (key in result) {
80
- if (Array.isArray(result[key])) {
81
- result[key].push(normValue);
82
- }
83
- else {
84
- result[key] = [result[key], normValue];
85
- }
86
- }
87
- else {
88
- result[key] = normValue;
89
- }
90
- }
91
- }
92
- }
93
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
94
- finally {
95
- try {
96
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
97
- }
98
- finally { if (e_1) throw e_1.error; }
99
- }
100
- return result;
73
+ return parseSearch.parseSearch(this.parsedUrl.search);
101
74
  },
102
75
  enumerable: false,
103
76
  configurable: true
@@ -130,8 +103,12 @@ var Action = /** @class */ (function () {
130
103
  utils.once
131
104
  ], Action.prototype, "parsedUrl", null);
132
105
  return Action;
133
- }());
106
+ }());
107
+ function useAction() {
108
+ return jsx.useHandler()[ACTION];
109
+ }
134
110
 
135
111
  exports.ACTION = ACTION;
136
112
  exports.Action = Action;
137
113
  exports.URL_PARSER = URL_PARSER;
114
+ 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';
@@ -9,3 +9,4 @@ var Action = require('./Action.js');
9
9
  exports.ACTION = Action.ACTION;
10
10
  exports.Action = Action.Action;
11
11
  exports.URL_PARSER = Action.URL_PARSER;
12
+ exports.useAction = Action.useAction;
package/action/index.d.ts CHANGED
@@ -1,3 +1 @@
1
1
  export * from './Action';
2
- export * from './withAction';
3
- export * from './getAction';
@@ -1,3 +1 @@
1
- export { ACTION, Action, URL_PARSER } from './Action/Action.es6.js';
2
- export { withAction } from './withAction/withAction.es6.js';
3
- export { getAction } from './getAction/getAction.es6.js';
1
+ export { ACTION, Action, URL_PARSER, useAction } from './Action/Action.es6.js';
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.withAction = withAction.withAction;
15
- exports.getAction = getAction.getAction;
12
+ exports.useAction = Action.useAction;
@@ -4,7 +4,7 @@ import { Watch } from 'watch-state';
4
4
  function serverFn() {
5
5
  return (fn, next, handler) => {
6
6
  let result;
7
- new Watch(update => result = innet(fn(update), handler));
7
+ new Watch(update => (result = innet(fn(update), handler)));
8
8
  return result;
9
9
  };
10
10
  }
@@ -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
  }
@@ -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 _default: import("innet").Handler;
26
- export default _default;
25
+ export declare const handler: import("innet").Handler;
27
26
  declare global {
28
27
  namespace JSX {
29
28
  interface IntrinsicElements {
@@ -1,8 +1,9 @@
1
+ import { createHandler } from 'innet';
1
2
  import html from '@innet/html';
2
- import { jsxPlugins, jsxTemplate } from '@innet/jsx';
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 { createHandler } from 'innet';
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
- jsxTemplate,
42
+ jsxComponent,
43
43
  ];
44
44
  const promisePlugins = [
45
45
  async,
46
46
  ];
47
- var handler = createHandler([
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, handler as default, fnPlugins, objectPlugins, promisePlugins };
54
+ export { JSXPlugins, arrayPlugins, fnPlugins, handler, objectPlugins, promisePlugins };
@@ -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 innet = require('innet');
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.jsxTemplate,
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;
@@ -1,2 +1 @@
1
- export { default } from './handler';
2
1
  export * from './handler';
@@ -1 +1 @@
1
- export { JSXPlugins, arrayPlugins, default, fnPlugins, objectPlugins, promisePlugins } from './handler.es6.js';
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
@@ -1,5 +1,6 @@
1
- export { default } from './handler';
1
+ export { handler as default } from './handler';
2
2
  export * from './server';
3
3
  export * from './plugins';
4
4
  export * from './handler';
5
5
  export * from './action';
6
+ export * from './utils';
package/index.es6.js CHANGED
@@ -1,14 +1,14 @@
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, getRouter, router, withRouter } from './plugins/router/router.es6.js';
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';
13
+ export { parseSearch } from './utils/parseSearch/parseSearch.es6.js';
14
+ export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
package/index.js CHANGED
@@ -14,15 +14,16 @@ 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');
17
+ var parseSearch = require('./utils/parseSearch/parseSearch.js');
18
+ var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
19
19
 
20
20
 
21
21
 
22
22
  exports.JSXPlugins = handler.JSXPlugins;
23
23
  exports.arrayPlugins = handler.arrayPlugins;
24
- exports["default"] = handler["default"];
24
+ exports["default"] = handler.handler;
25
25
  exports.fnPlugins = handler.fnPlugins;
26
+ exports.handler = handler.handler;
26
27
  exports.objectPlugins = handler.objectPlugins;
27
28
  exports.promisePlugins = handler.promisePlugins;
28
29
  exports.server = server.server;
@@ -30,9 +31,8 @@ exports.cookie = cookie.cookie;
30
31
  exports.header = header.header;
31
32
  exports.ROUTER = router.ROUTER;
32
33
  exports.getMatchReg = router.getMatchReg;
33
- exports.getRouter = router.getRouter;
34
34
  exports.router = router.router;
35
- exports.withRouter = router.withRouter;
35
+ exports.useRouter = router.useRouter;
36
36
  exports.success = success.success;
37
37
  exports.successStatuses = success.successStatuses;
38
38
  exports.error = error.error;
@@ -45,5 +45,6 @@ exports.redirectStatuses = redirect.redirectStatuses;
45
45
  exports.ACTION = Action.ACTION;
46
46
  exports.Action = Action.Action;
47
47
  exports.URL_PARSER = Action.URL_PARSER;
48
- exports.withAction = withAction.withAction;
49
- exports.getAction = getAction.getAction;
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.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -22,19 +22,21 @@
22
22
  },
23
23
  "homepage": "https://github.com/d8corp/innet-server",
24
24
  "dependencies": {
25
- "@cantinc/utils": "^1.0.0",
26
- "@innet/html": "^1.0.0",
27
- "@innet/jsx": "^0.1.1",
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.0",
30
- "@types/cookie": "^0.4.1",
31
- "cookie": "^0.4.2",
29
+ "@innet/utils": "^1.1.1",
30
+ "@types/cookie": "^0.5.1",
31
+ "@types/qs": "^6.9.7",
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",
37
- "tslib": "^2.3.1",
38
- "watch-state": "^3.4.3"
38
+ "qs": "^6.11.0",
39
+ "tslib": "^2.4.0",
40
+ "watch-state": "^3.4.4"
39
41
  }
40
42
  }
@@ -1,5 +1,4 @@
1
- import { Props } from '@innet/jsx';
2
- export interface CmsProps extends Props {
1
+ export interface CmsProps {
3
2
  dir?: string;
4
3
  prefix?: string;
5
4
  }
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
- import { ACTION } from '../../action/Action/Action.es6.js';
3
2
  import { file } from '../file/file.es6.js';
3
+ import { ACTION } from '../../action/Action/Action.es6.js';
4
4
 
5
5
  function cms({ props }, handler) {
6
6
  const action = handler[ACTION];
@@ -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
 
@@ -1,5 +1,5 @@
1
- import { CookieSerializeOptions } from 'cookie';
2
1
  import { Handler } from 'innet';
2
+ import { CookieSerializeOptions } from 'cookie';
3
3
  export interface CookieProps extends CookieSerializeOptions {
4
4
  key: string;
5
5
  value?: string;
@@ -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, getRouter, router, withRouter } from './router/router.es6.js';
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.withRouter = router.withRouter;
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, getRouter, router, withRouter } from './router.es6.js';
1
+ export { ROUTER, getMatchReg, router, useRouter } from './router.es6.js';
@@ -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.withRouter = router.withRouter;
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 interface RouterComponent extends Component {
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 getRouter(handler) {
10
- return handler[ROUTER];
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, getRouter, router, withRouter };
50
+ export { ROUTER, getMatchReg, router, useRouter };
@@ -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 getRouter(handler) {
18
- return handler[ROUTER];
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.withRouter = withRouter;
62
+ exports.useRouter = useRouter;
@@ -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 () {
@@ -0,0 +1,2 @@
1
+ export * from './parseSearch';
2
+ export * from './stringifySearch';
@@ -0,0 +1,2 @@
1
+ export { parseSearch } from './parseSearch/parseSearch.es6.js';
2
+ export { stringifySearch } from './stringifySearch/stringifySearch.es6.js';
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,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var parseSearch = require('./parseSearch.js');
6
+
7
+
8
+
9
+ exports.parseSearch = parseSearch.parseSearch;
@@ -0,0 +1,2 @@
1
+ import { IParseOptions, ParsedQs } from 'qs';
2
+ export declare function parseSearch<V extends ParsedQs>(search?: string, options?: IParseOptions): V;
@@ -0,0 +1,7 @@
1
+ import qs from 'qs';
2
+
3
+ function parseSearch(search, options) {
4
+ return qs.parse(search, Object.assign({ ignoreQueryPrefix: true }, options));
5
+ }
6
+
7
+ export { parseSearch };
@@ -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,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var stringifySearch = require('./stringifySearch.js');
6
+
7
+
8
+
9
+ exports.stringifySearch = stringifySearch.stringifySearch;
@@ -0,0 +1,2 @@
1
+ import { IStringifyOptions, ParsedQs } from 'qs';
2
+ export declare function stringifySearch(search: ParsedQs, options?: IStringifyOptions): string;
@@ -0,0 +1,7 @@
1
+ import qs from 'qs';
2
+
3
+ function stringifySearch(search, options) {
4
+ return qs.stringify(search, Object.assign({ encode: false }, options));
5
+ }
6
+
7
+ export { stringifySearch };
@@ -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;
@@ -1,3 +0,0 @@
1
- import { Handler } from 'innet';
2
- import { Action, ActionOptions } from '../Action';
3
- export declare function getAction<O extends ActionOptions>(handler: Handler): Action<O>;
@@ -1,7 +0,0 @@
1
- import { ACTION } from '../Action/Action.es6.js';
2
-
3
- function getAction(handler) {
4
- return handler[ACTION];
5
- }
6
-
7
- export { getAction };
@@ -1,11 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from './getAction';
@@ -1 +0,0 @@
1
- export { getAction } from './getAction.es6.js';
@@ -1,9 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from './withAction';
@@ -1 +0,0 @@
1
- export { withAction } from './withAction.es6.js';
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var withAction = require('./withAction.js');
6
-
7
-
8
-
9
- exports.withAction = withAction.withAction;
@@ -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;