@innet/server 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/action/Action/Action.d.ts +2 -2
- package/handler/handler.d.ts +3 -1
- package/handler/handler.es6.js +2 -0
- package/handler/handler.js +2 -0
- package/index.es6.js +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/plugins/access/access.d.ts +14 -0
- package/plugins/access/access.es6.js +23 -0
- package/plugins/access/access.js +33 -0
- package/plugins/access/index.d.ts +1 -0
- package/plugins/access/index.es6.js +1 -0
- package/plugins/access/index.js +10 -0
- package/plugins/formatter/formatter.es6.js +1 -1
- package/plugins/formatter/formatter.js +1 -1
- package/plugins/index.d.ts +1 -0
- package/plugins/index.es6.js +1 -0
- package/plugins/index.js +3 -0
- package/plugins/validation/validation.d.ts +1 -1
- package/plugins/validation/validation.es6.js +3 -4
- package/plugins/validation/validation.js +3 -4
package/README.md
CHANGED
|
@@ -795,14 +795,14 @@ async function Body () {
|
|
|
795
795
|
}
|
|
796
796
|
```
|
|
797
797
|
|
|
798
|
-
##
|
|
798
|
+
## useRouter
|
|
799
799
|
|
|
800
800
|
You can get router data in a component
|
|
801
801
|
|
|
802
802
|
```typescript jsx
|
|
803
803
|
import { useRouter } from '@innet/server'
|
|
804
804
|
|
|
805
|
-
|
|
805
|
+
function Router () {
|
|
806
806
|
const { prefix, params } = useRouter()
|
|
807
807
|
|
|
808
808
|
return <success>{{ prefix, params }}</success>
|
|
@@ -17,9 +17,9 @@ export declare type Files = Record<string, File | File[]>;
|
|
|
17
17
|
export declare type Request = IncomingMessage;
|
|
18
18
|
export declare type Response = ServerResponse;
|
|
19
19
|
export interface ActionOptions {
|
|
20
|
+
search: Search;
|
|
21
|
+
cookies: Cookies;
|
|
20
22
|
body?: Body;
|
|
21
|
-
search?: Search;
|
|
22
|
-
cookies?: Cookies;
|
|
23
23
|
files?: Files;
|
|
24
24
|
}
|
|
25
25
|
export declare type Resources = Exclude<keyof ActionOptions, undefined>;
|
package/handler/handler.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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 { cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, formatter, FormatterProps, header, HeaderProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, success, SuccessProps, validation, ValidationProps } from '../plugins';
|
|
6
|
+
import { access, AccessProps, cms, CmsProps, cookie, CookieProps, error, ErrorProps, file, FileProps, formatter, FormatterProps, header, HeaderProps, proxy, ProxyProps, redirect, RedirectProps, router, RouterProps, success, SuccessProps, validation, ValidationProps } from '../plugins';
|
|
7
7
|
import { server, ServerProps } from '../server';
|
|
8
8
|
export declare const arrayPlugins: (typeof arrayAsync)[];
|
|
9
9
|
export declare const JSXPlugins: {
|
|
@@ -24,6 +24,7 @@ export declare const JSXPlugins: {
|
|
|
24
24
|
context: typeof context;
|
|
25
25
|
slot: typeof slot;
|
|
26
26
|
slots: typeof slots;
|
|
27
|
+
access: typeof access;
|
|
27
28
|
};
|
|
28
29
|
export declare const fnPlugins: (typeof serverFn)[];
|
|
29
30
|
export declare const objectPlugins: ((handler: any) => import("innet").PluginHandler)[];
|
|
@@ -48,6 +49,7 @@ declare global {
|
|
|
48
49
|
context: ContextProps;
|
|
49
50
|
slot: SlotProps;
|
|
50
51
|
slots: SlotsProps;
|
|
52
|
+
access: AccessProps;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
}
|
package/handler/handler.es6.js
CHANGED
|
@@ -15,6 +15,7 @@ import { proxy } from '../plugins/proxy/proxy.es6.js';
|
|
|
15
15
|
import { redirect } from '../plugins/redirect/redirect.es6.js';
|
|
16
16
|
import { validation } from '../plugins/validation/validation.es6.js';
|
|
17
17
|
import { formatter } from '../plugins/formatter/formatter.es6.js';
|
|
18
|
+
import { access } from '../plugins/access/access.es6.js';
|
|
18
19
|
import { server } from '../server/server.es6.js';
|
|
19
20
|
|
|
20
21
|
const arrayPlugins = [
|
|
@@ -40,6 +41,7 @@ const JSXPlugins = {
|
|
|
40
41
|
context,
|
|
41
42
|
slot,
|
|
42
43
|
slots,
|
|
44
|
+
access,
|
|
43
45
|
};
|
|
44
46
|
const fnPlugins = [
|
|
45
47
|
serverFn,
|
package/handler/handler.js
CHANGED
|
@@ -19,6 +19,7 @@ var proxy = require('../plugins/proxy/proxy.js');
|
|
|
19
19
|
var redirect = require('../plugins/redirect/redirect.js');
|
|
20
20
|
var validation = require('../plugins/validation/validation.js');
|
|
21
21
|
var formatter = require('../plugins/formatter/formatter.js');
|
|
22
|
+
var access = require('../plugins/access/access.js');
|
|
22
23
|
var server = require('../server/server.js');
|
|
23
24
|
|
|
24
25
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -48,6 +49,7 @@ var JSXPlugins = {
|
|
|
48
49
|
context: jsx.context,
|
|
49
50
|
slot: jsx.slot,
|
|
50
51
|
slots: jsx.slots,
|
|
52
|
+
access: access.access,
|
|
51
53
|
};
|
|
52
54
|
var fnPlugins = [
|
|
53
55
|
serverFn.serverFn,
|
package/index.es6.js
CHANGED
|
@@ -11,6 +11,7 @@ export { proxy } from './plugins/proxy/proxy.es6.js';
|
|
|
11
11
|
export { redirect, redirectStatuses } from './plugins/redirect/redirect.es6.js';
|
|
12
12
|
export { validation, validationContext } from './plugins/validation/validation.es6.js';
|
|
13
13
|
export { formatter } from './plugins/formatter/formatter.es6.js';
|
|
14
|
+
export { access, accessContext } from './plugins/access/access.es6.js';
|
|
14
15
|
export { ACTION, Action, URL_PARSER, useAction } from './action/Action/Action.es6.js';
|
|
15
16
|
export { parseSearch } from './utils/parseSearch/parseSearch.es6.js';
|
|
16
17
|
export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
|
package/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var proxy = require('./plugins/proxy/proxy.js');
|
|
|
15
15
|
var redirect = require('./plugins/redirect/redirect.js');
|
|
16
16
|
var validation = require('./plugins/validation/validation.js');
|
|
17
17
|
var formatter = require('./plugins/formatter/formatter.js');
|
|
18
|
+
var access = require('./plugins/access/access.js');
|
|
18
19
|
var Action = require('./action/Action/Action.js');
|
|
19
20
|
var parseSearch = require('./utils/parseSearch/parseSearch.js');
|
|
20
21
|
var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
|
|
@@ -47,6 +48,8 @@ exports.redirectStatuses = redirect.redirectStatuses;
|
|
|
47
48
|
exports.validation = validation.validation;
|
|
48
49
|
exports.validationContext = validation.validationContext;
|
|
49
50
|
exports.formatter = formatter.formatter;
|
|
51
|
+
exports.access = access.access;
|
|
52
|
+
exports.accessContext = access.accessContext;
|
|
50
53
|
exports.ACTION = Action.ACTION;
|
|
51
54
|
exports.Action = Action.Action;
|
|
52
55
|
exports.URL_PARSER = Action.URL_PARSER;
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Handler } from 'innet';
|
|
2
|
+
import { Context } from '@innet/jsx';
|
|
3
|
+
export interface AccessProps {
|
|
4
|
+
role?: any;
|
|
5
|
+
}
|
|
6
|
+
export interface AccessJsxElement {
|
|
7
|
+
props: AccessProps;
|
|
8
|
+
children?: any;
|
|
9
|
+
}
|
|
10
|
+
export interface AccessContext {
|
|
11
|
+
handleRole?: (role: any, handler: Handler) => any;
|
|
12
|
+
}
|
|
13
|
+
export declare const accessContext: Context<AccessContext, AccessContext>;
|
|
14
|
+
export declare function access({ props, children }: AccessJsxElement, handler: any): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import innet from 'innet';
|
|
2
|
+
import { Context } from '@innet/jsx';
|
|
3
|
+
import { ACTION } from '../../action/Action/Action.es6.js';
|
|
4
|
+
|
|
5
|
+
const accessContext = new Context({});
|
|
6
|
+
function access({ props, children }, handler) {
|
|
7
|
+
const action = handler[ACTION];
|
|
8
|
+
if (!action) {
|
|
9
|
+
throw Error('`access` should be inside `server`');
|
|
10
|
+
}
|
|
11
|
+
const { handleRole } = accessContext.get(handler);
|
|
12
|
+
const role = props === null || props === void 0 ? void 0 : props.role;
|
|
13
|
+
if (!handleRole) {
|
|
14
|
+
return innet(children, handler);
|
|
15
|
+
}
|
|
16
|
+
const error = handleRole(role, handler);
|
|
17
|
+
if (error) {
|
|
18
|
+
return innet(error, handler);
|
|
19
|
+
}
|
|
20
|
+
return innet(children, handler);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { access, accessContext };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var innet = require('innet');
|
|
6
|
+
var jsx = require('@innet/jsx');
|
|
7
|
+
var Action = require('../../action/Action/Action.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
12
|
+
|
|
13
|
+
var accessContext = new jsx.Context({});
|
|
14
|
+
function access(_a, handler) {
|
|
15
|
+
var props = _a.props, children = _a.children;
|
|
16
|
+
var action = handler[Action.ACTION];
|
|
17
|
+
if (!action) {
|
|
18
|
+
throw Error('`access` should be inside `server`');
|
|
19
|
+
}
|
|
20
|
+
var handleRole = accessContext.get(handler).handleRole;
|
|
21
|
+
var role = props === null || props === void 0 ? void 0 : props.role;
|
|
22
|
+
if (!handleRole) {
|
|
23
|
+
return innet__default["default"](children, handler);
|
|
24
|
+
}
|
|
25
|
+
var error = handleRole(role, handler);
|
|
26
|
+
if (error) {
|
|
27
|
+
return innet__default["default"](error, handler);
|
|
28
|
+
}
|
|
29
|
+
return innet__default["default"](children, handler);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.access = access;
|
|
33
|
+
exports.accessContext = accessContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './access';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { access, accessContext } from './access.es6.js';
|
|
@@ -4,7 +4,7 @@ import { ACTION } from '../../action/Action/Action.es6.js';
|
|
|
4
4
|
function formatter({ props, children }, handler) {
|
|
5
5
|
const action = handler[ACTION];
|
|
6
6
|
if (!action) {
|
|
7
|
-
throw Error('`
|
|
7
|
+
throw Error('`formatter` should be inside `server`');
|
|
8
8
|
}
|
|
9
9
|
const { map, resource = 'body' } = props;
|
|
10
10
|
const run = () => {
|
|
@@ -14,7 +14,7 @@ function formatter(_a, handler) {
|
|
|
14
14
|
var props = _a.props, children = _a.children;
|
|
15
15
|
var action = handler[Action.ACTION];
|
|
16
16
|
if (!action) {
|
|
17
|
-
throw Error('`
|
|
17
|
+
throw Error('`formatter` should be inside `server`');
|
|
18
18
|
}
|
|
19
19
|
var map = props.map, _b = props.resource, resource = _b === void 0 ? 'body' : _b;
|
|
20
20
|
var run = function () {
|
package/plugins/index.d.ts
CHANGED
package/plugins/index.es6.js
CHANGED
|
@@ -9,3 +9,4 @@ export { proxy } from './proxy/proxy.es6.js';
|
|
|
9
9
|
export { redirect, redirectStatuses } from './redirect/redirect.es6.js';
|
|
10
10
|
export { validation, validationContext } from './validation/validation.es6.js';
|
|
11
11
|
export { formatter } from './formatter/formatter.es6.js';
|
|
12
|
+
export { access, accessContext } from './access/access.es6.js';
|
package/plugins/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var proxy = require('./proxy/proxy.js');
|
|
|
13
13
|
var redirect = require('./redirect/redirect.js');
|
|
14
14
|
var validation = require('./validation/validation.js');
|
|
15
15
|
var formatter = require('./formatter/formatter.js');
|
|
16
|
+
var access = require('./access/access.js');
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
@@ -34,3 +35,5 @@ exports.redirectStatuses = redirect.redirectStatuses;
|
|
|
34
35
|
exports.validation = validation.validation;
|
|
35
36
|
exports.validationContext = validation.validationContext;
|
|
36
37
|
exports.formatter = formatter.formatter;
|
|
38
|
+
exports.access = access.access;
|
|
39
|
+
exports.accessContext = access.accessContext;
|
|
@@ -10,7 +10,7 @@ export interface ValidationJsxElement<T> {
|
|
|
10
10
|
children?: any;
|
|
11
11
|
}
|
|
12
12
|
export interface ValidationContext {
|
|
13
|
-
handleError
|
|
13
|
+
handleError?: (e: ValidationResponse<any>) => any;
|
|
14
14
|
}
|
|
15
15
|
export declare const validationContext: Context<ValidationContext, ValidationContext>;
|
|
16
16
|
export declare function validation<T extends object, E extends object>({ props, children }: ValidationJsxElement<T>, handler: any): Promise<any>;
|
|
@@ -3,9 +3,7 @@ import { validation as validation$1 } from '@cantinc/utils';
|
|
|
3
3
|
import { Context } from '@innet/jsx';
|
|
4
4
|
import { ACTION } from '../../action/Action/Action.es6.js';
|
|
5
5
|
|
|
6
|
-
const validationContext = new Context({
|
|
7
|
-
handleError: () => { },
|
|
8
|
-
});
|
|
6
|
+
const validationContext = new Context({});
|
|
9
7
|
function validation({ props, children }, handler) {
|
|
10
8
|
const action = handler[ACTION];
|
|
11
9
|
if (!action) {
|
|
@@ -18,7 +16,8 @@ function validation({ props, children }, handler) {
|
|
|
18
16
|
throw Error(`cannot find ${resource} in action`);
|
|
19
17
|
return validation$1(map, data).then(e => {
|
|
20
18
|
if (e) {
|
|
21
|
-
|
|
19
|
+
const { handleError } = validationContext.get(handler);
|
|
20
|
+
return handleError ? innet(handleError(e), handler) : undefined;
|
|
22
21
|
}
|
|
23
22
|
return innet(children, handler);
|
|
24
23
|
});
|
|
@@ -11,9 +11,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
13
13
|
|
|
14
|
-
var validationContext = new jsx.Context({
|
|
15
|
-
handleError: function () { },
|
|
16
|
-
});
|
|
14
|
+
var validationContext = new jsx.Context({});
|
|
17
15
|
function validation(_a, handler) {
|
|
18
16
|
var props = _a.props, children = _a.children;
|
|
19
17
|
var action = handler[Action.ACTION];
|
|
@@ -27,7 +25,8 @@ function validation(_a, handler) {
|
|
|
27
25
|
throw Error("cannot find ".concat(resource, " in action"));
|
|
28
26
|
return utils.validation(map, data).then(function (e) {
|
|
29
27
|
if (e) {
|
|
30
|
-
|
|
28
|
+
var handleError = validationContext.get(handler).handleError;
|
|
29
|
+
return handleError ? innet__default["default"](handleError(e), handler) : undefined;
|
|
31
30
|
}
|
|
32
31
|
return innet__default["default"](children, handler);
|
|
33
32
|
});
|