@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.
- package/handler/handler.d.ts +3 -2
- package/handler/handler.es6.js +3 -1
- package/handler/handler.js +3 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.es6.js +2 -1
- package/hooks/index.js +4 -0
- package/hooks/useAction/index.es6.js +1 -1
- package/hooks/useAction/index.js +1 -0
- package/hooks/useAction/useAction.d.ts +3 -1
- package/hooks/useAction/useAction.es6.js +8 -4
- package/hooks/useAction/useAction.js +7 -2
- package/hooks/useCookies/useCookies.d.ts +1 -1
- package/hooks/useServer/index.d.ts +1 -0
- package/hooks/useServer/index.es6.js +1 -0
- package/hooks/useServer/index.js +10 -0
- package/hooks/useServer/useServer.d.ts +7 -0
- package/hooks/useServer/useServer.es6.js +12 -0
- package/hooks/useServer/useServer.js +17 -0
- package/index.d.ts +0 -2
- package/index.es6.js +5 -3
- package/index.js +11 -6
- package/package.json +1 -1
- package/plugins/access/access.es6.js +4 -3
- package/plugins/access/access.js +4 -3
- package/plugins/action/action.d.ts +10 -0
- package/plugins/action/action.es6.js +38 -0
- package/plugins/action/action.js +60 -0
- package/plugins/action/index.d.ts +1 -0
- package/plugins/action/index.es6.js +1 -0
- package/plugins/action/index.js +9 -0
- package/plugins/cms/cms.es6.js +5 -5
- package/plugins/cms/cms.js +5 -5
- package/plugins/cookie/cookie.es6.js +6 -2
- package/plugins/cookie/cookie.js +6 -2
- package/plugins/error/error.es6.js +7 -2
- package/plugins/error/error.js +7 -2
- package/plugins/file/file.es6.js +8 -4
- package/plugins/file/file.js +8 -4
- package/plugins/formatter/formatter.d.ts +1 -1
- package/plugins/formatter/formatter.es6.js +4 -3
- package/plugins/formatter/formatter.js +4 -3
- package/plugins/header/header.es6.js +7 -3
- package/plugins/header/header.js +7 -3
- package/plugins/index.d.ts +2 -0
- package/plugins/index.es6.js +2 -0
- package/plugins/index.js +4 -0
- package/plugins/parseBody/parseBody.d.ts +1 -1
- package/plugins/parseBody/parseBody.es6.js +3 -2
- package/plugins/parseBody/parseBody.js +3 -2
- package/plugins/proxy/proxy.es6.js +7 -2
- package/plugins/proxy/proxy.js +7 -2
- package/plugins/redirect/redirect.es6.js +7 -3
- package/plugins/redirect/redirect.js +7 -3
- package/plugins/router/router.d.ts +1 -1
- package/plugins/router/router.es6.js +4 -3
- package/plugins/router/router.js +4 -3
- package/plugins/server/server.d.ts +22 -0
- package/plugins/server/server.es6.js +43 -0
- package/plugins/server/server.js +55 -0
- package/plugins/success/success.es6.js +7 -3
- package/plugins/success/success.js +7 -3
- package/plugins/validation/validation.d.ts +1 -1
- package/plugins/validation/validation.es6.js +4 -3
- package/plugins/validation/validation.js +4 -3
- package/{action → utils/action}/Action/Action.d.ts +0 -1
- package/{action → utils/action}/Action/Action.es6.js +2 -4
- package/{action → utils/action}/Action/Action.js +1 -4
- package/utils/action/Action/index.es6.js +1 -0
- package/{action → utils/action}/Action/index.js +0 -1
- package/utils/action/index.es6.js +1 -0
- package/{action → utils/action}/index.js +0 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +5 -0
- package/action/Action/index.es6.js +0 -1
- package/action/index.es6.js +0 -1
- package/server/server.d.ts +0 -20
- package/server/server.es6.js +0 -69
- package/server/server.js +0 -97
- /package/{server → plugins/server}/index.d.ts +0 -0
- /package/{server → plugins/server}/index.es6.js +0 -0
- /package/{server → plugins/server}/index.js +0 -0
- /package/{action → utils/action}/Action/index.d.ts +0 -0
- /package/{action → utils/action}/index.d.ts +0 -0
package/handler/handler.d.ts
CHANGED
|
@@ -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;
|
package/handler/handler.es6.js
CHANGED
|
@@ -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,
|
package/handler/handler.js
CHANGED
|
@@ -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
package/hooks/index.es6.js
CHANGED
|
@@ -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';
|
package/hooks/useAction/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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 '../../
|
|
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,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
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 {
|
|
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 {
|
|
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
|
|
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.
|
|
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.
|
|
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,12 +1,13 @@
|
|
|
1
1
|
import innet from 'innet';
|
|
2
2
|
import { Context } from '@innet/jsx';
|
|
3
|
-
import {
|
|
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
|
|
8
|
+
const action = actionContext.get(handler);
|
|
8
9
|
if (!action) {
|
|
9
|
-
throw Error('
|
|
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;
|
package/plugins/access/access.js
CHANGED
|
@@ -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
|
|
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
|
|
17
|
+
var action = useAction.actionContext.get(handler);
|
|
17
18
|
if (!action) {
|
|
18
|
-
throw Error('
|
|
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';
|
package/plugins/cms/cms.es6.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { file } from '../file/file.es6.js';
|
|
3
|
-
import {
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
package/plugins/cms/cms.js
CHANGED
|
@@ -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
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
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 {
|
|
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
|
|
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
|
}
|
package/plugins/cookie/cookie.js
CHANGED
|
@@ -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
|
|
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
|
|
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 {
|
|
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
|
|
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);
|
package/plugins/error/error.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var innet = require('innet');
|
|
6
|
-
var
|
|
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
|
|
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);
|