@lanaqi/rsr 0.0.1-rc.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 (46) hide show
  1. package/README.md +49 -0
  2. package/dist/access/aaa.d.ts +177 -0
  3. package/dist/access/addon.d.ts +92 -0
  4. package/dist/access/blocker.d.ts +94 -0
  5. package/dist/access/common.d.ts +63 -0
  6. package/dist/access/context.d.ts +162 -0
  7. package/dist/access/guarder.d.ts +173 -0
  8. package/dist/access/handler.d.ts +183 -0
  9. package/dist/access/index.d.ts +56 -0
  10. package/dist/access/manager.d.ts +109 -0
  11. package/dist/access/matcher.d.ts +70 -0
  12. package/dist/access/navigator.d.ts +33 -0
  13. package/dist/access/recorder.d.ts +291 -0
  14. package/dist/access/resource.d.ts +215 -0
  15. package/dist/access/storer.d.ts +197 -0
  16. package/dist/access/voter.d.ts +156 -0
  17. package/dist/addons/index.d.ts +4 -0
  18. package/dist/addons/micro.d.ts +53 -0
  19. package/dist/bridge.d.ts +8 -0
  20. package/dist/builder/blocker.d.ts +24 -0
  21. package/dist/builder/builder.d.ts +9 -0
  22. package/dist/builder/context.d.ts +112 -0
  23. package/dist/builder/guarder.d.ts +54 -0
  24. package/dist/builder/handler.d.ts +21 -0
  25. package/dist/builder/index.d.ts +48 -0
  26. package/dist/builder/manager.d.ts +55 -0
  27. package/dist/builder/matcher.d.ts +37 -0
  28. package/dist/builder/navigator.d.ts +22 -0
  29. package/dist/builder/recorder.d.ts +11 -0
  30. package/dist/builder/resource.d.ts +101 -0
  31. package/dist/builder/storer.d.ts +83 -0
  32. package/dist/builder/voter.d.ts +41 -0
  33. package/dist/index.d.ts +24 -0
  34. package/dist/index.js +1778 -0
  35. package/dist/security/blocker.d.ts +14 -0
  36. package/dist/security/index.d.ts +8 -0
  37. package/dist/security/provider.d.ts +31 -0
  38. package/dist/support/aaa.d.ts +29 -0
  39. package/dist/support/blocker.d.ts +28 -0
  40. package/dist/support/index.d.ts +20 -0
  41. package/dist/support/permission.d.ts +5 -0
  42. package/dist/support/signature.d.ts +21 -0
  43. package/dist/support/user.d.ts +14 -0
  44. package/dist/warpper/index.d.ts +4 -0
  45. package/dist/warpper/permission.d.ts +24 -0
  46. package/package.json +74 -0
@@ -0,0 +1,173 @@
1
+ import type { AccessAddons } from './addon';
2
+ import { AccessBehave, AccessDecision, type AccessPath } from './common';
3
+ import type { AccessContext } from './context';
4
+ import type { AccessManager } from './manager';
5
+ /**
6
+ * 访问守护器
7
+ */
8
+ export interface AccessGuarder {
9
+ /**
10
+ * 守护决策
11
+ * @param blockPath 阻断路径
12
+ */
13
+ guardDecision(blockPath: AccessPath): AccessDecision;
14
+ /**
15
+ * 守护处理
16
+ * @param currentDecision 当前决策
17
+ * @param beforeDecision 之前决策
18
+ */
19
+ guardHandle(currentDecision: AccessDecision, beforeDecision?: AccessDecision): AccessBehave;
20
+ /**
21
+ * 守护阻断
22
+ * @param currentPath 当前路径
23
+ * @return 是否阻断
24
+ */
25
+ guardBlock(currentPath: AccessPath): boolean;
26
+ /**
27
+ * 守护之前
28
+ * @param currentPath 当前路径
29
+ */
30
+ guardBefore(currentPath: AccessPath): void;
31
+ /**
32
+ * 守护之后
33
+ * @param currentPath 当前路径
34
+ * @param currentDecision 当前决策
35
+ */
36
+ guardAfter(currentPath: AccessPath, currentDecision: AccessDecision): void;
37
+ /**
38
+ * 许可之前
39
+ * @param stayPath 停留路径
40
+ * @param blockPath 阻断路径
41
+ */
42
+ permitBefore(stayPath: AccessPath, blockPath: AccessPath): void;
43
+ /**
44
+ * 许可之前
45
+ * @param stayPath 停留路径
46
+ * @param blockPath 阻断路径
47
+ */
48
+ permitAfter(stayPath: AccessPath, blockPath: AccessPath): void;
49
+ }
50
+ /**
51
+ * 简单守护器
52
+ */
53
+ export declare class SimpleGuarder implements AccessGuarder {
54
+ /**
55
+ * 上下文
56
+ * @private
57
+ */
58
+ private readonly context;
59
+ /**
60
+ * 管理器
61
+ * @private
62
+ */
63
+ private readonly manager;
64
+ /**
65
+ * 插件集合
66
+ * @private
67
+ */
68
+ private readonly addons;
69
+ /**
70
+ * 构造函数
71
+ * @param context 上下文
72
+ * @param manager 管理器
73
+ */
74
+ constructor(context: AccessContext, manager: AccessManager, addons: AccessAddons);
75
+ /**
76
+ * 守护决策
77
+ * @param blockPath 阻断路径
78
+ */
79
+ guardDecision(blockPath: AccessPath): AccessDecision;
80
+ /**
81
+ * 守护处理
82
+ * @param currentDecision 当前决策
83
+ * @param beforeDecision 之前决策
84
+ */
85
+ guardHandle(currentDecision: AccessDecision, beforeDecision?: AccessDecision): AccessBehave;
86
+ /**
87
+ * 守护阻断
88
+ * @param currentPath 当前路径
89
+ * @return 是否阻断
90
+ */
91
+ guardBlock(currentPath: AccessPath): boolean;
92
+ /**
93
+ * 守护之前
94
+ * @param currentPath 当前路径
95
+ */
96
+ guardBefore(currentPath: AccessPath): void;
97
+ /**
98
+ * 守护之后
99
+ * @param currentPath 当前路径
100
+ * @param currentDecision 当前决策
101
+ */
102
+ guardAfter(currentPath: AccessPath, currentDecision: AccessDecision): void;
103
+ /**
104
+ * 许可之前
105
+ * @param stayPath 停留路径
106
+ * @param blockPath 阻断路径
107
+ */
108
+ permitBefore(stayPath: AccessPath, blockPath: AccessPath): void;
109
+ /**
110
+ * 许可之后
111
+ * @param stayPath 停留路径
112
+ * @param blockPath 阻断路径
113
+ */
114
+ permitAfter(stayPath: AccessPath, blockPath: AccessPath): void;
115
+ /**
116
+ * 遍历插件集合
117
+ * @param fn 执行插件函数
118
+ */
119
+ private forAddons;
120
+ /**
121
+ * 取得资源
122
+ * @param path 路径
123
+ * @private
124
+ */
125
+ private obtainResource;
126
+ /**
127
+ * 取得认证
128
+ * @private
129
+ */
130
+ private obtainAuthentication;
131
+ /**
132
+ * 检查认证
133
+ * @param authentication 认证
134
+ * @private
135
+ */
136
+ private checkAuthentication;
137
+ /**
138
+ * 取得授权
139
+ * @param authentication 认证 | undefined
140
+ * @private
141
+ */
142
+ private obtainAuthorization;
143
+ /**
144
+ * 检查授权
145
+ * @param resource 资源
146
+ * @param authorization 授权
147
+ * @private
148
+ */
149
+ private checkPermission;
150
+ /**
151
+ * 检查签名
152
+ * @param path 路径
153
+ * @param authentication 认证
154
+ * @param authorization 授权
155
+ * @private
156
+ */
157
+ private checkSignature;
158
+ /**
159
+ * 清理签名
160
+ * @param stayPath 停留路径
161
+ * @param stayResource 停留资源
162
+ * @private
163
+ */
164
+ private clearSignature;
165
+ }
166
+ /**
167
+ * 访问提供者
168
+ */
169
+ export type AccessProvider = {
170
+ context: AccessContext;
171
+ manager: AccessManager;
172
+ guarder: AccessGuarder;
173
+ };
@@ -0,0 +1,183 @@
1
+ import { AccessBehave, AccessDecision, type AccessPath } from './common';
2
+ import type { AccessContext } from './context';
3
+ /**
4
+ * 访问处理器
5
+ */
6
+ export interface AccessHandler {
7
+ /**
8
+ * 没有资源
9
+ * @param context 上下文
10
+ */
11
+ notResource(context: AccessContext): AccessBehave;
12
+ /**
13
+ * 没有认证
14
+ * @param context 上下文
15
+ */
16
+ notAuthentication(context: AccessContext): AccessBehave;
17
+ /**
18
+ * 无效认证
19
+ * @param context 上下文
20
+ */
21
+ invalidAuthentication(context: AccessContext): AccessBehave;
22
+ /**
23
+ * 没有授权
24
+ * @param context 上下文
25
+ */
26
+ notAuthorization(context: AccessContext): AccessBehave;
27
+ /**
28
+ * 没有签名
29
+ * @param context 上下文
30
+ */
31
+ notSignature(context: AccessContext): AccessBehave;
32
+ /**
33
+ * 访问拒绝
34
+ * @param context 上下文
35
+ */
36
+ accessDenied(context: AccessContext): AccessBehave;
37
+ /**
38
+ * 允许访问
39
+ * @param context 上下文
40
+ */
41
+ allowAccess(context: AccessContext): AccessBehave;
42
+ /**
43
+ * 错误决策
44
+ * @param context 上下文
45
+ * @param decision 决策
46
+ */
47
+ errorDecision(context: AccessContext, decision: AccessDecision): void;
48
+ }
49
+ /**
50
+ * 行为路径
51
+ */
52
+ export type BehavePath = string | Partial<AccessPath>;
53
+ /**
54
+ * 行为配置
55
+ */
56
+ export type BehaveConfig = {
57
+ /**
58
+ * 没有资源路径值
59
+ */
60
+ readonly notResourcePath?: BehavePath;
61
+ /**
62
+ * 没有资源函数
63
+ * @param context 上下文
64
+ */
65
+ readonly notResourceFunc?: (context: AccessContext) => AccessBehave;
66
+ /**
67
+ * 没有认证路径值
68
+ */
69
+ readonly notAuthenticationPath?: BehavePath;
70
+ /**
71
+ * 没有认证函数
72
+ * @param context 上下文
73
+ */
74
+ readonly notAuthenticationFunc?: (context: AccessContext) => AccessBehave;
75
+ /**
76
+ * 无效认证路径值
77
+ */
78
+ readonly invalidAuthenticationPath?: BehavePath;
79
+ /**
80
+ * 无效认证函数
81
+ * @param context 上下文
82
+ */
83
+ readonly invalidAuthenticationFunc?: (context: AccessContext) => AccessBehave;
84
+ /**
85
+ * 没有授权路径值
86
+ */
87
+ readonly notAuthorizationPath?: BehavePath;
88
+ /**
89
+ * 没有授权函数
90
+ * @param context 上下文
91
+ */
92
+ readonly notAuthorizationFunc?: (context: AccessContext) => AccessBehave;
93
+ /**
94
+ * 没有签名路径值
95
+ */
96
+ readonly notSignaturePath?: BehavePath;
97
+ /**
98
+ * 没有签名函数
99
+ * @param context 上下文
100
+ */
101
+ readonly notSignatureFunc?: (context: AccessContext) => AccessBehave;
102
+ /**
103
+ * 拒绝访问路径值
104
+ */
105
+ readonly accessDeniedPath?: BehavePath;
106
+ /**
107
+ * 拒绝访问函数
108
+ * @param context 上下文
109
+ */
110
+ readonly accessDeniedFunc?: (context: AccessContext) => AccessBehave;
111
+ /**
112
+ * 允许访问函数
113
+ * @param context 上下文
114
+ */
115
+ readonly allowAccessFunc?: (context: AccessContext) => void;
116
+ /**
117
+ * 错误决策函数
118
+ * @param context 上下文
119
+ * @param decision 决策
120
+ */
121
+ readonly errorDecisionFunc?: (context: AccessContext, decision: AccessDecision) => void;
122
+ };
123
+ /**
124
+ * 行为处理器
125
+ */
126
+ export declare class BehaveHandler implements AccessHandler {
127
+ /**
128
+ * 行为配置
129
+ * @private
130
+ */
131
+ private _config;
132
+ /**
133
+ * 构造函数
134
+ * @param config 行为配置
135
+ */
136
+ constructor(config: BehaveConfig);
137
+ /**
138
+ * 覆盖配置
139
+ * @param config 行为配置
140
+ */
141
+ config(config: BehaveConfig): void;
142
+ /**
143
+ * 没有资源
144
+ * @param context 上下文
145
+ */
146
+ notResource(context: AccessContext): AccessBehave;
147
+ /**
148
+ * 没有认证
149
+ * @param context 上下文
150
+ */
151
+ notAuthentication(context: AccessContext): AccessBehave;
152
+ /**
153
+ * 无效认证
154
+ * @param context 上下文
155
+ */
156
+ invalidAuthentication(context: AccessContext): AccessBehave;
157
+ /**
158
+ * 没有授权
159
+ * @param context 上下文
160
+ */
161
+ notAuthorization(context: AccessContext): AccessBehave;
162
+ /**
163
+ * 没有签名
164
+ * @param context 上下文
165
+ */
166
+ notSignature(context: AccessContext): AccessBehave;
167
+ /**
168
+ * 拒绝访问
169
+ * @param context 上下文
170
+ */
171
+ accessDenied(context: AccessContext): AccessBehave;
172
+ /**
173
+ * 允许访问
174
+ * @param context 上下文
175
+ */
176
+ allowAccess(context: AccessContext): AccessBehave;
177
+ /**
178
+ * 错误决策
179
+ * @param context 上下文
180
+ * @param decision 决策
181
+ */
182
+ errorDecision(context: AccessContext, decision: AccessDecision): void;
183
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 公共
3
+ */
4
+ export * from './common';
5
+ /**
6
+ * 认证与授权
7
+ */
8
+ export * from './aaa';
9
+ /**
10
+ * 资源
11
+ */
12
+ export * from './resource';
13
+ /**
14
+ * 记录器
15
+ */
16
+ export * from './recorder';
17
+ /**
18
+ * 投票器
19
+ */
20
+ export * from './voter';
21
+ /**
22
+ * 存储器
23
+ */
24
+ export * from './storer';
25
+ /**
26
+ * 匹配器
27
+ */
28
+ export * from './matcher';
29
+ /**
30
+ * 导航器
31
+ */
32
+ export * from './navigator';
33
+ /**
34
+ * 上下文
35
+ */
36
+ export * from './context';
37
+ /**
38
+ * 插件
39
+ */
40
+ export * from './addon';
41
+ /**
42
+ * 处理器
43
+ */
44
+ export * from './handler';
45
+ /**
46
+ * 阻断器
47
+ */
48
+ export * from './blocker';
49
+ /**
50
+ * 管理器
51
+ */
52
+ export * from './manager';
53
+ /**
54
+ * 守护器
55
+ */
56
+ export * from './guarder';
@@ -0,0 +1,109 @@
1
+ import type { AccessBlocker } from './blocker';
2
+ import type { AccessHandler } from './handler';
3
+ /**
4
+ * 访问管理器
5
+ */
6
+ export interface AccessManager {
7
+ /**
8
+ * 是否已禁用
9
+ */
10
+ isDisabled(): boolean;
11
+ /**
12
+ * 设置已禁用
13
+ */
14
+ setDisabled(disabled: boolean): void;
15
+ /**
16
+ * 获取处理器
17
+ */
18
+ getHandler(): AccessHandler;
19
+ /**
20
+ * 设置处理器
21
+ * @param handler 处理器
22
+ */
23
+ setHandler(handler: AccessHandler): void;
24
+ /**
25
+ * 获取阻断器
26
+ */
27
+ getBlocker(): AccessBlocker;
28
+ /**
29
+ * 设置阻断器
30
+ * @param blocker 阻断器
31
+ */
32
+ setBlocker(blocker: AccessBlocker): void;
33
+ /**
34
+ * 获取父级
35
+ */
36
+ getParent(): AccessManager | undefined;
37
+ /**
38
+ * 设置父级
39
+ * @param parent 父级
40
+ */
41
+ setParent(parent: AccessManager): void;
42
+ }
43
+ /**
44
+ * 简单管理器
45
+ */
46
+ export declare class SimpleManager implements AccessManager {
47
+ /**
48
+ * 已禁用
49
+ * @private
50
+ */
51
+ private disabled;
52
+ /**
53
+ * 处理器
54
+ * @private
55
+ */
56
+ private handler;
57
+ /**
58
+ * 阻断器
59
+ * @private
60
+ */
61
+ private blocker;
62
+ /**
63
+ * 父级
64
+ * @private
65
+ */
66
+ private parent?;
67
+ /**
68
+ * 构造函数
69
+ * @param disabled 已禁用
70
+ * @param handler 处理器
71
+ * @param blocker 阻断器
72
+ */
73
+ constructor(disabled: boolean, handler: AccessHandler, blocker: AccessBlocker);
74
+ /**
75
+ * 获取是否已禁用
76
+ */
77
+ isDisabled(): boolean;
78
+ /**
79
+ * 设置是否已禁用
80
+ */
81
+ setDisabled(disabled: boolean): void;
82
+ /**
83
+ * 获取处理器
84
+ */
85
+ getHandler(): AccessHandler;
86
+ /**
87
+ * 设置处理器
88
+ * @param handler 处理器
89
+ */
90
+ setHandler(handler: AccessHandler): void;
91
+ /**
92
+ * 获取阻断器
93
+ */
94
+ getBlocker(): AccessBlocker;
95
+ /**
96
+ * 设置阻断器
97
+ * @param blocker 阻断器
98
+ */
99
+ setBlocker(blocker: AccessBlocker): void;
100
+ /**
101
+ * 获取父级
102
+ */
103
+ getParent(): AccessManager | undefined;
104
+ /**
105
+ * 设置父级
106
+ * @param parent 父级
107
+ */
108
+ setParent(parent?: AccessManager): void;
109
+ }
@@ -0,0 +1,70 @@
1
+ import type { AccessPath } from './common';
2
+ import type { AccessResource, AccessResources } from './resource';
3
+ /**
4
+ * 访问匹配器
5
+ */
6
+ export interface AccessMatcher {
7
+ /**
8
+ * 进行匹配
9
+ * @param resource 资源
10
+ * @param path 路径
11
+ */
12
+ match(resource: AccessResource, path: AccessPath): boolean;
13
+ /**
14
+ * 取得资源
15
+ * @param path 路径
16
+ */
17
+ obtain(path: AccessPath): AccessResource | null;
18
+ /**
19
+ * 获取基础路径
20
+ */
21
+ getBasename(): string | undefined;
22
+ /**
23
+ * 设置基础路径
24
+ */
25
+ setBasename(basename: string | undefined): void;
26
+ }
27
+ /**
28
+ * 简单匹配器
29
+ */
30
+ export declare class SimpleMatcher implements AccessMatcher {
31
+ /**
32
+ * 缓存资源
33
+ * @private
34
+ */
35
+ private readonly cache;
36
+ /**
37
+ * 资源集合
38
+ * @private
39
+ */
40
+ private readonly resources;
41
+ /**
42
+ * 基础路径
43
+ * @private
44
+ */
45
+ private basename?;
46
+ /**
47
+ * 构造函数
48
+ * @param resources 资源集合
49
+ */
50
+ constructor(resources: AccessResources);
51
+ /**
52
+ * 进行匹配
53
+ * @param resource 资源
54
+ * @param path 路径
55
+ */
56
+ match(resource: AccessResource, path: AccessPath): boolean;
57
+ /**
58
+ * 取得资源
59
+ * @param path 路径
60
+ */
61
+ obtain(path: AccessPath): AccessResource | null;
62
+ /**
63
+ * 获取基础路径
64
+ */
65
+ getBasename(): string | undefined;
66
+ /**
67
+ * 设置基础路径
68
+ */
69
+ setBasename(basename: string | undefined): void;
70
+ }
@@ -0,0 +1,33 @@
1
+ import type { NavigateFunction, NavigateOptions, To } from '../bridge';
2
+ /**
3
+ * 访问导航器
4
+ */
5
+ export interface AccessNavigator {
6
+ /**
7
+ * 进行导航
8
+ * @param to 路径
9
+ * @param options 可选配置
10
+ */
11
+ navigate(to: To, options?: NavigateOptions): void;
12
+ }
13
+ /**
14
+ * 简单导航器
15
+ */
16
+ export declare class SimpleNavigator implements AccessNavigator {
17
+ /**
18
+ * 导航函数
19
+ * @private
20
+ */
21
+ private readonly _navigate;
22
+ /**
23
+ * 构造函数
24
+ * @param navigate 导航函数
25
+ */
26
+ constructor(navigate: NavigateFunction);
27
+ /**
28
+ * 进行导航
29
+ * @param to 路径
30
+ * @param options 可选配置
31
+ */
32
+ navigate(to: To, options?: NavigateOptions): void;
33
+ }