@nocobase/resourcer 2.0.0-beta.1 → 2.0.0-beta.3
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/lib/action.js +1 -0
- package/lib/resourcer.d.ts +3 -0
- package/lib/resourcer.js +17 -0
- package/lib/utils.js +3 -1
- package/package.json +3 -3
package/lib/action.js
CHANGED
|
@@ -180,6 +180,7 @@ const _Action = class _Action {
|
|
|
180
180
|
const handlers = [
|
|
181
181
|
...this.resource.resourcer.getMiddlewares(),
|
|
182
182
|
...this.getMiddlewareHandlers(),
|
|
183
|
+
...this.resource.resourcer.getRegisteredPreActionHandlers(this.resource.getName(), this.name),
|
|
183
184
|
this.getHandler()
|
|
184
185
|
].filter(Boolean);
|
|
185
186
|
return handlers.map((fn) => (0, import_utils.wrapMiddlewareWithLogging)(fn));
|
package/lib/resourcer.d.ts
CHANGED
|
@@ -142,6 +142,7 @@ export declare class ResourceManager {
|
|
|
142
142
|
*/
|
|
143
143
|
protected handlers: Map<ActionName, any>;
|
|
144
144
|
protected actionHandlers: Map<ActionName, any>;
|
|
145
|
+
protected preActionHandlers: Map<ActionName, Toposort<HandlerType>>;
|
|
145
146
|
protected middlewareHandlers: Map<string, any>;
|
|
146
147
|
protected middlewares: Toposort<any>;
|
|
147
148
|
constructor(options?: ResourceManagerOptions);
|
|
@@ -195,6 +196,8 @@ export declare class ResourceManager {
|
|
|
195
196
|
* @internal
|
|
196
197
|
*/
|
|
197
198
|
getRegisteredHandlers(): Map<ActionName, any>;
|
|
199
|
+
registerPreActionHandler(name: ActionName, handler: HandlerType, options?: ToposortOptions): void;
|
|
200
|
+
getRegisteredPreActionHandlers(name: string, action: ActionName): HandlerType[];
|
|
198
201
|
/**
|
|
199
202
|
* @internal
|
|
200
203
|
*/
|
package/lib/resourcer.js
CHANGED
|
@@ -59,6 +59,7 @@ const _ResourceManager = class _ResourceManager {
|
|
|
59
59
|
*/
|
|
60
60
|
handlers = /* @__PURE__ */ new Map();
|
|
61
61
|
actionHandlers = /* @__PURE__ */ new Map();
|
|
62
|
+
preActionHandlers = /* @__PURE__ */ new Map();
|
|
62
63
|
middlewareHandlers = /* @__PURE__ */ new Map();
|
|
63
64
|
middlewares;
|
|
64
65
|
constructor(options = {}) {
|
|
@@ -151,6 +152,22 @@ const _ResourceManager = class _ResourceManager {
|
|
|
151
152
|
getRegisteredHandlers() {
|
|
152
153
|
return this.actionHandlers;
|
|
153
154
|
}
|
|
155
|
+
registerPreActionHandler(name, handler, options = {}) {
|
|
156
|
+
const middlewares = this.preActionHandlers.get(name) || new import_utils.Toposort();
|
|
157
|
+
middlewares.add(handler, options);
|
|
158
|
+
this.preActionHandlers.set(name, middlewares);
|
|
159
|
+
}
|
|
160
|
+
getRegisteredPreActionHandlers(name, action) {
|
|
161
|
+
let specificAction = action;
|
|
162
|
+
if (!action.includes(":")) {
|
|
163
|
+
specificAction = `${name}:${action}`;
|
|
164
|
+
}
|
|
165
|
+
let middlewares = this.preActionHandlers.get(specificAction);
|
|
166
|
+
if (!middlewares) {
|
|
167
|
+
middlewares = this.preActionHandlers.get(action);
|
|
168
|
+
}
|
|
169
|
+
return (middlewares == null ? void 0 : middlewares.nodes) || [];
|
|
170
|
+
}
|
|
154
171
|
/**
|
|
155
172
|
* @internal
|
|
156
173
|
*/
|
package/lib/utils.js
CHANGED
|
@@ -226,7 +226,9 @@ __name(smartParse, "smartParse");
|
|
|
226
226
|
function parseQuery(input) {
|
|
227
227
|
const query = import_qs.default.parse(input, {
|
|
228
228
|
// 原始 query string 中如果一个键连等号“=”都没有可以被认为是 null 类型
|
|
229
|
-
strictNullHandling: true
|
|
229
|
+
strictNullHandling: true,
|
|
230
|
+
// 允许更大的数组长度,避免像 appends[] 这种参数在超过默认 20 个时被转换成对象
|
|
231
|
+
arrayLimit: 100
|
|
230
232
|
// 逗号分隔转换为数组
|
|
231
233
|
// comma: true,
|
|
232
234
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/resourcer",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/utils": "2.0.0-beta.
|
|
9
|
+
"@nocobase/utils": "2.0.0-beta.3",
|
|
10
10
|
"deepmerge": "^4.2.2",
|
|
11
11
|
"koa-compose": "^4.1.0",
|
|
12
12
|
"lodash": "^4.17.21",
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
19
19
|
"directory": "packages/resourcer"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "6c178de2050651bcfcc0b2708de0246977eac510"
|
|
22
22
|
}
|