@nocobase/resourcer 2.0.0-alpha.6 → 2.0.0-alpha.60
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 +21 -0
- 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,6 +205,24 @@ 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 类型
|
|
@@ -215,6 +233,9 @@ function parseQuery(input) {
|
|
|
215
233
|
if (typeof query.filter === "string") {
|
|
216
234
|
query.filter = JSON.parse(query.filter);
|
|
217
235
|
}
|
|
236
|
+
if (typeof query.filterByTk === "string") {
|
|
237
|
+
query.filterByTk = smartParse(query.filterByTk);
|
|
238
|
+
}
|
|
218
239
|
return query;
|
|
219
240
|
}
|
|
220
241
|
__name(parseQuery, "parseQuery");
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/resourcer",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.60",
|
|
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-alpha.
|
|
9
|
+
"@nocobase/utils": "2.0.0-alpha.60",
|
|
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": "9113d61ce85b60b7ba3d0e5ca64182d92a15ece4"
|
|
22
22
|
}
|