@innet/server 1.6.5 → 1.7.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.
Files changed (84) hide show
  1. package/handler/handler.d.ts +3 -2
  2. package/handler/handler.es6.js +3 -1
  3. package/handler/handler.js +3 -1
  4. package/hooks/index.d.ts +1 -0
  5. package/hooks/index.es6.js +2 -1
  6. package/hooks/index.js +4 -0
  7. package/hooks/useAction/index.es6.js +1 -1
  8. package/hooks/useAction/index.js +1 -0
  9. package/hooks/useAction/useAction.d.ts +3 -1
  10. package/hooks/useAction/useAction.es6.js +8 -4
  11. package/hooks/useAction/useAction.js +7 -2
  12. package/hooks/useCookies/useCookies.d.ts +1 -1
  13. package/hooks/useServer/index.d.ts +1 -0
  14. package/hooks/useServer/index.es6.js +1 -0
  15. package/hooks/useServer/index.js +10 -0
  16. package/hooks/useServer/useServer.d.ts +7 -0
  17. package/hooks/useServer/useServer.es6.js +12 -0
  18. package/hooks/useServer/useServer.js +17 -0
  19. package/index.d.ts +0 -2
  20. package/index.es6.js +5 -3
  21. package/index.js +11 -6
  22. package/package.json +1 -1
  23. package/plugins/access/access.es6.js +4 -3
  24. package/plugins/access/access.js +4 -3
  25. package/plugins/action/action.d.ts +10 -0
  26. package/plugins/action/action.es6.js +38 -0
  27. package/plugins/action/action.js +60 -0
  28. package/plugins/action/index.d.ts +1 -0
  29. package/plugins/action/index.es6.js +1 -0
  30. package/plugins/action/index.js +9 -0
  31. package/plugins/cms/cms.es6.js +5 -5
  32. package/plugins/cms/cms.js +5 -5
  33. package/plugins/cookie/cookie.es6.js +6 -2
  34. package/plugins/cookie/cookie.js +6 -2
  35. package/plugins/error/error.es6.js +7 -2
  36. package/plugins/error/error.js +7 -2
  37. package/plugins/file/file.es6.js +8 -4
  38. package/plugins/file/file.js +8 -4
  39. package/plugins/formatter/formatter.d.ts +1 -1
  40. package/plugins/formatter/formatter.es6.js +4 -3
  41. package/plugins/formatter/formatter.js +4 -3
  42. package/plugins/header/header.es6.js +7 -3
  43. package/plugins/header/header.js +7 -3
  44. package/plugins/index.d.ts +2 -0
  45. package/plugins/index.es6.js +2 -0
  46. package/plugins/index.js +4 -0
  47. package/plugins/parseBody/parseBody.d.ts +1 -1
  48. package/plugins/parseBody/parseBody.es6.js +3 -2
  49. package/plugins/parseBody/parseBody.js +3 -2
  50. package/plugins/proxy/proxy.es6.js +7 -2
  51. package/plugins/proxy/proxy.js +7 -2
  52. package/plugins/redirect/redirect.es6.js +7 -3
  53. package/plugins/redirect/redirect.js +7 -3
  54. package/plugins/router/router.d.ts +1 -1
  55. package/plugins/router/router.es6.js +4 -3
  56. package/plugins/router/router.js +4 -3
  57. package/plugins/server/server.d.ts +22 -0
  58. package/plugins/server/server.es6.js +43 -0
  59. package/plugins/server/server.js +55 -0
  60. package/plugins/success/success.es6.js +7 -3
  61. package/plugins/success/success.js +7 -3
  62. package/plugins/validation/validation.d.ts +1 -1
  63. package/plugins/validation/validation.es6.js +4 -3
  64. package/plugins/validation/validation.js +4 -3
  65. package/{action → utils/action}/Action/Action.d.ts +0 -1
  66. package/{action → utils/action}/Action/Action.es6.js +2 -4
  67. package/{action → utils/action}/Action/Action.js +1 -4
  68. package/utils/action/Action/index.es6.js +1 -0
  69. package/{action → utils/action}/Action/index.js +0 -1
  70. package/utils/action/index.es6.js +1 -0
  71. package/{action → utils/action}/index.js +0 -1
  72. package/utils/index.d.ts +1 -0
  73. package/utils/index.es6.js +1 -0
  74. package/utils/index.js +5 -0
  75. package/action/Action/index.es6.js +0 -1
  76. package/action/index.es6.js +0 -1
  77. package/server/server.d.ts +0 -20
  78. package/server/server.es6.js +0 -69
  79. package/server/server.js +0 -97
  80. /package/{server → plugins/server}/index.d.ts +0 -0
  81. /package/{server → plugins/server}/index.es6.js +0 -0
  82. /package/{server → plugins/server}/index.js +0 -0
  83. /package/{action → utils/action}/Action/index.d.ts +0 -0
  84. /package/{action → utils/action}/index.d.ts +0 -0
@@ -3,11 +3,11 @@ import { context, ContextProps, slot, SlotProps, slots, SlotsProps } from '@inne
3
3
  import { switchAsync, SwitchProps } from '@innet/switch';
4
4
  import { arrayAsync, async } from '@innet/utils';
5
5
  import { serverFn } from '../experimental/serverFn';
6
- import { access, AccessProps, cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, formatter, FormatterProps, header, HeaderProps, parseBody, ParseBodyProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, success, SuccessProps, validation, ValidationProps } from '../plugins';
7
- import { server, ServerProps } from '../server';
6
+ import { access, AccessProps, action, ActionProps, cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, formatter, FormatterProps, header, HeaderProps, parseBody, ParseBodyProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, server, ServerProps, success, SuccessProps, validation, ValidationProps } from '../plugins';
8
7
  export declare const arrayPlugins: (typeof arrayAsync)[];
9
8
  export declare const JSXPlugins: {
10
9
  server: typeof server;
10
+ action: typeof action;
11
11
  html: typeof html;
12
12
  switch: typeof switchAsync;
13
13
  router: typeof router;
@@ -35,6 +35,7 @@ declare global {
35
35
  namespace JSX {
36
36
  interface IntrinsicElements {
37
37
  server: ServerProps;
38
+ action: ActionProps;
38
39
  router: RouterProps;
39
40
  redirect: RedirectProps;
40
41
  cookie: CookieProps;
@@ -17,7 +17,8 @@ import { validation } from '../plugins/validation/validation.es6.js';
17
17
  import { formatter } from '../plugins/formatter/formatter.es6.js';
18
18
  import { access } from '../plugins/access/access.es6.js';
19
19
  import { parseBody } from '../plugins/parseBody/parseBody.es6.js';
20
- import { server } from '../server/server.es6.js';
20
+ import { server } from '../plugins/server/server.es6.js';
21
+ import { action } from '../plugins/action/action.es6.js';
21
22
 
22
23
  const arrayPlugins = [
23
24
  arrayAsync,
@@ -26,6 +27,7 @@ const arrayPlugins = [
26
27
  ];
27
28
  const JSXPlugins = {
28
29
  server,
30
+ action,
29
31
  html,
30
32
  switch: switchAsync,
31
33
  router,
@@ -21,7 +21,8 @@ var validation = require('../plugins/validation/validation.js');
21
21
  var formatter = require('../plugins/formatter/formatter.js');
22
22
  var access = require('../plugins/access/access.js');
23
23
  var parseBody = require('../plugins/parseBody/parseBody.js');
24
- var server = require('../server/server.js');
24
+ var server = require('../plugins/server/server.js');
25
+ var action = require('../plugins/action/action.js');
25
26
 
26
27
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
27
28
 
@@ -34,6 +35,7 @@ var arrayPlugins = [
34
35
  ];
35
36
  var JSXPlugins = {
36
37
  server: server.server,
38
+ action: action.action,
37
39
  html: html__default["default"],
38
40
  switch: _switch.switchAsync,
39
41
  router: router.router,
package/hooks/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export * from './useBody';
3
3
  export * from './useCookies';
4
4
  export * from './useFiles';
5
5
  export * from './useSearch';
6
+ export * from './useServer';
@@ -1,5 +1,6 @@
1
- export { useAction } from './useAction/useAction.es6.js';
1
+ export { actionContext, useAction } from './useAction/useAction.es6.js';
2
2
  export { useBody } from './useBody/useBody.es6.js';
3
3
  export { useCookies } from './useCookies/useCookies.es6.js';
4
4
  export { useFiles } from './useFiles/useFiles.es6.js';
5
5
  export { useSearch } from './useSearch/useSearch.es6.js';
6
+ export { serverContext, useServer } from './useServer/useServer.es6.js';
package/hooks/index.js CHANGED
@@ -7,11 +7,15 @@ var useBody = require('./useBody/useBody.js');
7
7
  var useCookies = require('./useCookies/useCookies.js');
8
8
  var useFiles = require('./useFiles/useFiles.js');
9
9
  var useSearch = require('./useSearch/useSearch.js');
10
+ var useServer = require('./useServer/useServer.js');
10
11
 
11
12
 
12
13
 
14
+ exports.actionContext = useAction.actionContext;
13
15
  exports.useAction = useAction.useAction;
14
16
  exports.useBody = useBody.useBody;
15
17
  exports.useCookies = useCookies.useCookies;
16
18
  exports.useFiles = useFiles.useFiles;
17
19
  exports.useSearch = useSearch.useSearch;
20
+ exports.serverContext = useServer.serverContext;
21
+ exports.useServer = useServer.useServer;
@@ -1 +1 @@
1
- export { useAction } from './useAction.es6.js';
1
+ export { actionContext, useAction } from './useAction.es6.js';
@@ -6,4 +6,5 @@ var useAction = require('./useAction.js');
6
6
 
7
7
 
8
8
 
9
+ exports.actionContext = useAction.actionContext;
9
10
  exports.useAction = useAction.useAction;
@@ -1,2 +1,4 @@
1
- import { Action, ActionOptions } from '../../action';
1
+ import { Context } from '@innet/jsx';
2
+ import { type Action, type ActionOptions } from '../../utils';
3
+ export declare const actionContext: Context<Action<ActionOptions>, undefined>;
2
4
  export declare function useAction<T extends Partial<ActionOptions>, O extends ActionOptions = ActionOptions & T>(): Action<O>;
@@ -1,8 +1,12 @@
1
- import { useHandler } from '@innet/jsx';
2
- import { ACTION } from '../../action/Action/Action.es6.js';
1
+ import { Context, useContext } from '@innet/jsx';
3
2
 
3
+ const actionContext = new Context();
4
4
  function useAction() {
5
- return useHandler()[ACTION];
5
+ const action = useContext(actionContext);
6
+ if (!action) {
7
+ throw Error('Use `useAction` in <action>');
8
+ }
9
+ return action;
6
10
  }
7
11
 
8
- export { useAction };
12
+ export { actionContext, useAction };
@@ -3,10 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsx = require('@innet/jsx');
6
- var Action = require('../../action/Action/Action.js');
7
6
 
7
+ var actionContext = new jsx.Context();
8
8
  function useAction() {
9
- return jsx.useHandler()[Action.ACTION];
9
+ var action = jsx.useContext(actionContext);
10
+ if (!action) {
11
+ throw Error('Use `useAction` in <action>');
12
+ }
13
+ return action;
10
14
  }
11
15
 
16
+ exports.actionContext = actionContext;
12
17
  exports.useAction = useAction;
@@ -1,2 +1,2 @@
1
- import { Cookies } from '../../action';
1
+ import { Cookies } from '../../utils';
2
2
  export declare function useCookies<T extends Cookies>(): T;
@@ -0,0 +1 @@
1
+ export * from './useServer';
@@ -0,0 +1 @@
1
+ export { serverContext, useServer } from './useServer.es6.js';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useServer = require('./useServer.js');
6
+
7
+
8
+
9
+ exports.serverContext = useServer.serverContext;
10
+ exports.useServer = useServer.useServer;
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Context } from '@innet/jsx';
4
+ import { type Server as HttpServer } from 'http';
5
+ import { type Server as HttpsServer } from 'https';
6
+ export declare const serverContext: Context<HttpServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | HttpsServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, HttpServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | HttpsServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
7
+ export declare function useServer(): HttpServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | HttpsServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
@@ -0,0 +1,12 @@
1
+ import { Context, useContext } from '@innet/jsx';
2
+
3
+ const serverContext = new Context();
4
+ function useServer() {
5
+ const server = useContext(serverContext);
6
+ if (!server) {
7
+ throw Error('Use `useServer` in <server>');
8
+ }
9
+ return server;
10
+ }
11
+
12
+ export { serverContext, useServer };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsx = require('@innet/jsx');
6
+
7
+ var serverContext = new jsx.Context();
8
+ function useServer() {
9
+ var server = jsx.useContext(serverContext);
10
+ if (!server) {
11
+ throw Error('Use `useServer` in <server>');
12
+ }
13
+ return server;
14
+ }
15
+
16
+ exports.serverContext = serverContext;
17
+ exports.useServer = useServer;
package/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export { handler as default } from './handler';
2
- export * from './server';
3
2
  export * from './plugins';
4
3
  export * from './handler';
5
- export * from './action';
6
4
  export * from './utils';
7
5
  export * from './hooks';
package/index.es6.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { JSXPlugins, arrayPlugins, handler as default, fnPlugins, handler, objectPlugins, promisePlugins } from './handler/handler.es6.js';
2
- export { server } from './server/server.es6.js';
3
2
  export { cookie } from './plugins/cookie/cookie.es6.js';
4
3
  export { header } from './plugins/header/header.es6.js';
5
4
  export { ROUTER, getMatchReg, router, useRouter } from './plugins/router/router.es6.js';
@@ -13,11 +12,14 @@ export { validation, validationContext } from './plugins/validation/validation.e
13
12
  export { formatter } from './plugins/formatter/formatter.es6.js';
14
13
  export { access, accessContext } from './plugins/access/access.es6.js';
15
14
  export { parseBody } from './plugins/parseBody/parseBody.es6.js';
16
- export { ACTION, Action, KEY_FIELD, KEY_KEYS, URL_PARSER } from './action/Action/Action.es6.js';
15
+ export { server } from './plugins/server/server.es6.js';
16
+ export { action } from './plugins/action/action.es6.js';
17
17
  export { parseSearch } from './utils/parseSearch/parseSearch.es6.js';
18
18
  export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
19
- export { useAction } from './hooks/useAction/useAction.es6.js';
19
+ export { Action, KEY_FIELD, KEY_KEYS, URL_PARSER } from './utils/action/Action/Action.es6.js';
20
+ export { actionContext, useAction } from './hooks/useAction/useAction.es6.js';
20
21
  export { useBody } from './hooks/useBody/useBody.es6.js';
21
22
  export { useCookies } from './hooks/useCookies/useCookies.es6.js';
22
23
  export { useFiles } from './hooks/useFiles/useFiles.es6.js';
23
24
  export { useSearch } from './hooks/useSearch/useSearch.es6.js';
25
+ export { serverContext, useServer } from './hooks/useServer/useServer.es6.js';
package/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var handler = require('./handler/handler.js');
6
- var server = require('./server/server.js');
7
6
  var cookie = require('./plugins/cookie/cookie.js');
8
7
  var header = require('./plugins/header/header.js');
9
8
  var router = require('./plugins/router/router.js');
@@ -17,14 +16,17 @@ var validation = require('./plugins/validation/validation.js');
17
16
  var formatter = require('./plugins/formatter/formatter.js');
18
17
  var access = require('./plugins/access/access.js');
19
18
  var parseBody = require('./plugins/parseBody/parseBody.js');
20
- var Action = require('./action/Action/Action.js');
19
+ var server = require('./plugins/server/server.js');
20
+ var action = require('./plugins/action/action.js');
21
21
  var parseSearch = require('./utils/parseSearch/parseSearch.js');
22
22
  var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
23
+ var Action = require('./utils/action/Action/Action.js');
23
24
  var useAction = require('./hooks/useAction/useAction.js');
24
25
  var useBody = require('./hooks/useBody/useBody.js');
25
26
  var useCookies = require('./hooks/useCookies/useCookies.js');
26
27
  var useFiles = require('./hooks/useFiles/useFiles.js');
27
28
  var useSearch = require('./hooks/useSearch/useSearch.js');
29
+ var useServer = require('./hooks/useServer/useServer.js');
28
30
 
29
31
 
30
32
 
@@ -35,7 +37,6 @@ exports.fnPlugins = handler.fnPlugins;
35
37
  exports.handler = handler.handler;
36
38
  exports.objectPlugins = handler.objectPlugins;
37
39
  exports.promisePlugins = handler.promisePlugins;
38
- exports.server = server.server;
39
40
  exports.cookie = cookie.cookie;
40
41
  exports.header = header.header;
41
42
  exports.ROUTER = router.ROUTER;
@@ -57,15 +58,19 @@ exports.formatter = formatter.formatter;
57
58
  exports.access = access.access;
58
59
  exports.accessContext = access.accessContext;
59
60
  exports.parseBody = parseBody.parseBody;
60
- exports.ACTION = Action.ACTION;
61
+ exports.server = server.server;
62
+ exports.action = action.action;
63
+ exports.parseSearch = parseSearch.parseSearch;
64
+ exports.stringifySearch = stringifySearch.stringifySearch;
61
65
  exports.Action = Action.Action;
62
66
  exports.KEY_FIELD = Action.KEY_FIELD;
63
67
  exports.KEY_KEYS = Action.KEY_KEYS;
64
68
  exports.URL_PARSER = Action.URL_PARSER;
65
- exports.parseSearch = parseSearch.parseSearch;
66
- exports.stringifySearch = stringifySearch.stringifySearch;
69
+ exports.actionContext = useAction.actionContext;
67
70
  exports.useAction = useAction.useAction;
68
71
  exports.useBody = useBody.useBody;
69
72
  exports.useCookies = useCookies.useCookies;
70
73
  exports.useFiles = useFiles.useFiles;
71
74
  exports.useSearch = useSearch.useSearch;
75
+ exports.serverContext = useServer.serverContext;
76
+ exports.useServer = useServer.useServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "1.6.5",
3
+ "version": "1.7.0",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -1,12 +1,13 @@
1
1
  import innet from 'innet';
2
2
  import { Context } from '@innet/jsx';
3
- import { ACTION } from '../../action/Action/Action.es6.js';
3
+ import { actionContext } from '../../hooks/useAction/useAction.es6.js';
4
+ import '../../hooks/useServer/useServer.es6.js';
4
5
 
5
6
  const accessContext = new Context({});
6
7
  function access({ props, children }, handler) {
7
- const action = handler[ACTION];
8
+ const action = actionContext.get(handler);
8
9
  if (!action) {
9
- throw Error('`access` should be inside `server`');
10
+ throw Error('Use <access> inside <action>');
10
11
  }
11
12
  const { handleRole } = accessContext.get(handler);
12
13
  const role = props === null || props === void 0 ? void 0 : props.role;
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var innet = require('innet');
6
6
  var jsx = require('@innet/jsx');
7
- var Action = require('../../action/Action/Action.js');
7
+ var useAction = require('../../hooks/useAction/useAction.js');
8
+ require('../../hooks/useServer/useServer.js');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
11
 
@@ -13,9 +14,9 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
13
14
  var accessContext = new jsx.Context({});
14
15
  function access(_a, handler) {
15
16
  var props = _a.props, children = _a.children;
16
- var action = handler[Action.ACTION];
17
+ var action = useAction.actionContext.get(handler);
17
18
  if (!action) {
18
- throw Error('`access` should be inside `server`');
19
+ throw Error('Use <access> inside <action>');
19
20
  }
20
21
  var handleRole = accessContext.get(handler).handleRole;
21
22
  var role = props === null || props === void 0 ? void 0 : props.role;
@@ -0,0 +1,10 @@
1
+ import { Handler } from 'innet';
2
+ import { Action, ActionParams } from '../../utils';
3
+ export interface ActionProps extends ActionParams {
4
+ unknownError?: string;
5
+ onError?: (e: Error, action: Action) => any;
6
+ }
7
+ export declare function action({ props, children }: {
8
+ props?: ActionProps;
9
+ children: any;
10
+ }, handler: Handler): void;
@@ -0,0 +1,38 @@
1
+ import { __awaiter } from 'tslib';
2
+ import innet from 'innet';
3
+ import { CONTINUE } from '../../constants.es6.js';
4
+ import { actionContext } from '../../hooks/useAction/useAction.es6.js';
5
+ import { serverContext } from '../../hooks/useServer/useServer.es6.js';
6
+ import 'qs';
7
+ import { Action } from '../../utils/action/Action/Action.es6.js';
8
+
9
+ function action({ props = {}, children }, handler) {
10
+ const server = serverContext.get(handler);
11
+ if (!server) {
12
+ throw Error('Use <action> inside <server>');
13
+ }
14
+ const { onError, unknownError = '' } = props;
15
+ server.on('request', (req, res) => __awaiter(this, void 0, void 0, function* () {
16
+ const childHandler = Object.create(handler);
17
+ childHandler[actionContext.key] = new Action(req, res, props);
18
+ if (children) {
19
+ try {
20
+ const result = yield innet(children, childHandler);
21
+ if (result === CONTINUE) {
22
+ return;
23
+ }
24
+ if (typeof result === 'string') {
25
+ res.write(result);
26
+ }
27
+ }
28
+ catch (e) {
29
+ res.statusCode = 520;
30
+ onError === null || onError === void 0 ? void 0 : onError(e, actionContext.get(childHandler));
31
+ res.write(unknownError);
32
+ }
33
+ }
34
+ res.end();
35
+ }));
36
+ }
37
+
38
+ export { action };
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib = require('tslib');
6
+ var innet = require('innet');
7
+ var constants = require('../../constants.js');
8
+ var useAction = require('../../hooks/useAction/useAction.js');
9
+ var useServer = require('../../hooks/useServer/useServer.js');
10
+ require('qs');
11
+ var Action = require('../../utils/action/Action/Action.js');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
16
+
17
+ function action(_a, handler) {
18
+ var _this = this;
19
+ var _b = _a.props, props = _b === void 0 ? {} : _b, children = _a.children;
20
+ var server = useServer.serverContext.get(handler);
21
+ if (!server) {
22
+ throw Error('Use <action> inside <server>');
23
+ }
24
+ var onError = props.onError, _c = props.unknownError, unknownError = _c === void 0 ? '' : _c;
25
+ server.on('request', function (req, res) { return tslib.__awaiter(_this, void 0, void 0, function () {
26
+ var childHandler, result, e_1;
27
+ return tslib.__generator(this, function (_a) {
28
+ switch (_a.label) {
29
+ case 0:
30
+ childHandler = Object.create(handler);
31
+ childHandler[useAction.actionContext.key] = new Action.Action(req, res, props);
32
+ if (!children) return [3 /*break*/, 4];
33
+ _a.label = 1;
34
+ case 1:
35
+ _a.trys.push([1, 3, , 4]);
36
+ return [4 /*yield*/, innet__default["default"](children, childHandler)];
37
+ case 2:
38
+ result = _a.sent();
39
+ if (result === constants.CONTINUE) {
40
+ return [2 /*return*/];
41
+ }
42
+ if (typeof result === 'string') {
43
+ res.write(result);
44
+ }
45
+ return [3 /*break*/, 4];
46
+ case 3:
47
+ e_1 = _a.sent();
48
+ res.statusCode = 520;
49
+ onError === null || onError === void 0 ? void 0 : onError(e_1, useAction.actionContext.get(childHandler));
50
+ res.write(unknownError);
51
+ return [3 /*break*/, 4];
52
+ case 4:
53
+ res.end();
54
+ return [2 /*return*/];
55
+ }
56
+ });
57
+ }); });
58
+ }
59
+
60
+ exports.action = action;
@@ -0,0 +1 @@
1
+ export * from './action';
@@ -0,0 +1 @@
1
+ export { action } from './action.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var action = require('./action.js');
6
+
7
+
8
+
9
+ exports.action = action.action;
@@ -1,12 +1,12 @@
1
1
  import path from 'path';
2
2
  import { file } from '../file/file.es6.js';
3
- import { ACTION } from '../../action/Action/Action.es6.js';
3
+ import { actionContext } from '../../hooks/useAction/useAction.es6.js';
4
+ import '../../hooks/useServer/useServer.es6.js';
4
5
 
5
6
  function cms({ props, children }, handler) {
6
- const action = handler[ACTION];
7
- const { req } = action;
8
- if (!req) {
9
- throw Error('`cms` should be used inside `server`');
7
+ const action = actionContext.get(handler);
8
+ if (!action) {
9
+ throw Error('Use <cms> inside <action>');
10
10
  }
11
11
  const { prefix, dir } = props;
12
12
  let url = action.path;
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('path');
6
6
  var file = require('../file/file.js');
7
- var Action = require('../../action/Action/Action.js');
7
+ var useAction = require('../../hooks/useAction/useAction.js');
8
+ require('../../hooks/useServer/useServer.js');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
11
 
@@ -12,10 +13,9 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
12
13
 
13
14
  function cms(_a, handler) {
14
15
  var props = _a.props, children = _a.children;
15
- var action = handler[Action.ACTION];
16
- var req = action.req;
17
- if (!req) {
18
- throw Error('`cms` should be used inside `server`');
16
+ var action = useAction.actionContext.get(handler);
17
+ if (!action) {
18
+ throw Error('Use <cms> inside <action>');
19
19
  }
20
20
  var prefix = props.prefix, dir = props.dir;
21
21
  var url = action.path;
@@ -1,10 +1,14 @@
1
1
  import { __rest } from 'tslib';
2
2
  import innet from 'innet';
3
- import { ACTION } from '../../action/Action/Action.es6.js';
3
+ import { actionContext } from '../../hooks/useAction/useAction.es6.js';
4
+ import '../../hooks/useServer/useServer.es6.js';
4
5
 
5
6
  function cookie(_a, handler) {
6
7
  var _b = _a.props, { key, value } = _b, opt = __rest(_b, ["key", "value"]), { children } = _a;
7
- const action = handler[ACTION];
8
+ const action = actionContext.get(handler);
9
+ if (!action) {
10
+ throw Error('Use <cookie> inside <action>');
11
+ }
8
12
  if (value === undefined) {
9
13
  action.setCookie(key, '', Object.assign({ path: '/', expires: new Date(0) }, opt));
10
14
  }
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
6
  var innet = require('innet');
7
- var Action = require('../../action/Action/Action.js');
7
+ var useAction = require('../../hooks/useAction/useAction.js');
8
+ require('../../hooks/useServer/useServer.js');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
11
 
@@ -12,7 +13,10 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
12
13
 
13
14
  function cookie(_a, handler) {
14
15
  var _b = _a.props, key = _b.key, value = _b.value, opt = tslib.__rest(_b, ["key", "value"]), children = _a.children;
15
- var action = handler[Action.ACTION];
16
+ var action = useAction.actionContext.get(handler);
17
+ if (!action) {
18
+ throw Error('Use <cookie> inside <action>');
19
+ }
16
20
  if (value === undefined) {
17
21
  action.setCookie(key, '', tslib.__assign({ path: '/', expires: new Date(0) }, opt));
18
22
  }
@@ -1,5 +1,6 @@
1
1
  import innet from 'innet';
2
- import { ACTION } from '../../action/Action/Action.es6.js';
2
+ import { actionContext } from '../../hooks/useAction/useAction.es6.js';
3
+ import '../../hooks/useServer/useServer.es6.js';
3
4
 
4
5
  const errorStatuses = {
5
6
  badRequest: 400,
@@ -55,7 +56,11 @@ const errorStatuses = {
55
56
  invalidSSLCertificate: 526,
56
57
  };
57
58
  function error({ props, children }, handler) {
58
- const { res } = handler[ACTION];
59
+ const action = actionContext.get(handler);
60
+ if (!action) {
61
+ throw Error('Use <error> inside <action>');
62
+ }
63
+ const { res } = action;
59
64
  const status = props === null || props === void 0 ? void 0 : props.status;
60
65
  res.statusCode = status ? errorStatuses[status] || status : 520;
61
66
  const data = innet(children, handler);
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var innet = require('innet');
6
- var Action = require('../../action/Action/Action.js');
6
+ var useAction = require('../../hooks/useAction/useAction.js');
7
+ require('../../hooks/useServer/useServer.js');
7
8
 
8
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10
 
@@ -64,7 +65,11 @@ var errorStatuses = {
64
65
  };
65
66
  function error(_a, handler) {
66
67
  var props = _a.props, children = _a.children;
67
- var res = handler[Action.ACTION].res;
68
+ var action = useAction.actionContext.get(handler);
69
+ if (!action) {
70
+ throw Error('Use <error> inside <action>');
71
+ }
72
+ var res = action.res;
68
73
  var status = props === null || props === void 0 ? void 0 : props.status;
69
74
  res.statusCode = status ? errorStatuses[status] || status : 520;
70
75
  var data = innet__default["default"](children, handler);