@nocobase/resourcer 2.0.0-alpha.9 → 2.0.0-beta.2
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/resourcer.js +3 -0
- package/lib/utils.js +24 -1
- package/package.json +3 -3
package/lib/resourcer.js
CHANGED
|
@@ -176,6 +176,9 @@ const _ResourceManager = class _ResourceManager {
|
|
|
176
176
|
return this.middlewares.nodes;
|
|
177
177
|
}
|
|
178
178
|
use(middlewares, options = {}) {
|
|
179
|
+
if (!options.tag && !options.group && !options.before && !options.after) {
|
|
180
|
+
options.tag = "default";
|
|
181
|
+
}
|
|
179
182
|
this.middlewares.add(middlewares, options);
|
|
180
183
|
}
|
|
181
184
|
middleware({ prefix, accessors, skipIfDataSourceExists = false } = {}) {
|
package/lib/utils.js
CHANGED
|
@@ -205,16 +205,39 @@ function parseRequest(request, options = {}) {
|
|
|
205
205
|
return params;
|
|
206
206
|
}
|
|
207
207
|
__name(parseRequest, "parseRequest");
|
|
208
|
+
function smartParse(str) {
|
|
209
|
+
if (typeof str !== "string") return str;
|
|
210
|
+
const s = str.trim();
|
|
211
|
+
if (!s) return str;
|
|
212
|
+
const first = s[0];
|
|
213
|
+
if (first !== "{" && first !== "[") {
|
|
214
|
+
return str;
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
const parsed = JSON.parse(s);
|
|
218
|
+
if (Array.isArray(parsed)) return parsed;
|
|
219
|
+
if (parsed !== null && typeof parsed === "object") return parsed;
|
|
220
|
+
return str;
|
|
221
|
+
} catch {
|
|
222
|
+
return str;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
__name(smartParse, "smartParse");
|
|
208
226
|
function parseQuery(input) {
|
|
209
227
|
const query = import_qs.default.parse(input, {
|
|
210
228
|
// 原始 query string 中如果一个键连等号“=”都没有可以被认为是 null 类型
|
|
211
|
-
strictNullHandling: true
|
|
229
|
+
strictNullHandling: true,
|
|
230
|
+
// 允许更大的数组长度,避免像 appends[] 这种参数在超过默认 20 个时被转换成对象
|
|
231
|
+
arrayLimit: 100
|
|
212
232
|
// 逗号分隔转换为数组
|
|
213
233
|
// comma: true,
|
|
214
234
|
});
|
|
215
235
|
if (typeof query.filter === "string") {
|
|
216
236
|
query.filter = JSON.parse(query.filter);
|
|
217
237
|
}
|
|
238
|
+
if (typeof query.filterByTk === "string") {
|
|
239
|
+
query.filterByTk = smartParse(query.filterByTk);
|
|
240
|
+
}
|
|
218
241
|
return query;
|
|
219
242
|
}
|
|
220
243
|
__name(parseQuery, "parseQuery");
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/resourcer",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
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-
|
|
9
|
+
"@nocobase/utils": "2.0.0-beta.2",
|
|
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": "b77a33ee933ae6e09d2d5dce017ca15d8552d57b"
|
|
22
22
|
}
|