@nocobase/resourcer 2.2.42 → 2.2.44
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 +4 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +11 -1
- package/package.json +3 -3
package/lib/resourcer.js
CHANGED
|
@@ -201,6 +201,7 @@ const _ResourceManager = class _ResourceManager {
|
|
|
201
201
|
middleware({ prefix, accessors, skipIfDataSourceExists = false } = {}) {
|
|
202
202
|
const self = this;
|
|
203
203
|
return /* @__PURE__ */ __name(async function resourcerMiddleware(ctx, next) {
|
|
204
|
+
var _a;
|
|
204
205
|
if (skipIfDataSourceExists) {
|
|
205
206
|
const dataSource = ctx.get("x-data-source");
|
|
206
207
|
if (dataSource) {
|
|
@@ -262,6 +263,9 @@ const _ResourceManager = class _ResourceManager {
|
|
|
262
263
|
}
|
|
263
264
|
return (0, import_koa_compose.default)(ctx.action.getHandlers())(ctx, next);
|
|
264
265
|
} catch (error) {
|
|
266
|
+
if (error instanceof import_utils2.InvalidFilterError) {
|
|
267
|
+
ctx.throw(400, ((_a = ctx.t) == null ? void 0 : _a.call(ctx, error.message, { ns: "error-handler" })) ?? error.message, { code: "INVALID_FILTER" });
|
|
268
|
+
}
|
|
265
269
|
console.log(error);
|
|
266
270
|
return next();
|
|
267
271
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface ParsedParams {
|
|
|
34
34
|
}
|
|
35
35
|
export declare function getNameByParams(params: ParsedParams): string;
|
|
36
36
|
export declare function parseRequest(request: ParseRequest, options?: ParseOptions): ParsedParams | false;
|
|
37
|
+
export declare class InvalidFilterError extends SyntaxError {
|
|
38
|
+
}
|
|
37
39
|
export declare function parseQuery(input: string): any;
|
|
38
40
|
export declare function parseFields(fields: any): any;
|
|
39
41
|
export declare function mergeFields(defaults: any, inputs: any): any;
|
package/lib/utils.js
CHANGED
|
@@ -37,6 +37,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
38
|
var utils_exports = {};
|
|
39
39
|
__export(utils_exports, {
|
|
40
|
+
InvalidFilterError: () => InvalidFilterError,
|
|
40
41
|
getNameByParams: () => getNameByParams,
|
|
41
42
|
mergeFields: () => mergeFields,
|
|
42
43
|
parseFields: () => parseFields,
|
|
@@ -234,6 +235,10 @@ function normalizeIndexedObjectToArray(value) {
|
|
|
234
235
|
return keys.sort((a, b) => Number(a) - Number(b)).map((key) => value[key]);
|
|
235
236
|
}
|
|
236
237
|
__name(normalizeIndexedObjectToArray, "normalizeIndexedObjectToArray");
|
|
238
|
+
const _InvalidFilterError = class _InvalidFilterError extends SyntaxError {
|
|
239
|
+
};
|
|
240
|
+
__name(_InvalidFilterError, "InvalidFilterError");
|
|
241
|
+
let InvalidFilterError = _InvalidFilterError;
|
|
237
242
|
function parseQuery(input) {
|
|
238
243
|
const query = import_qs.default.parse(input, {
|
|
239
244
|
// 原始 query string 中如果一个键连等号“=”都没有可以被认为是 null 类型
|
|
@@ -244,7 +249,11 @@ function parseQuery(input) {
|
|
|
244
249
|
// comma: true,
|
|
245
250
|
});
|
|
246
251
|
if (typeof query.filter === "string") {
|
|
247
|
-
|
|
252
|
+
try {
|
|
253
|
+
query.filter = JSON.parse(query.filter);
|
|
254
|
+
} catch {
|
|
255
|
+
throw new InvalidFilterError("The filter query parameter must be valid JSON.");
|
|
256
|
+
}
|
|
248
257
|
}
|
|
249
258
|
if (typeof query.filterByTk === "string") {
|
|
250
259
|
query.filterByTk = smartParse(query.filterByTk);
|
|
@@ -324,6 +333,7 @@ function mergeFields(defaults, inputs) {
|
|
|
324
333
|
__name(mergeFields, "mergeFields");
|
|
325
334
|
// Annotate the CommonJS export names for ESM import in node:
|
|
326
335
|
0 && (module.exports = {
|
|
336
|
+
InvalidFilterError,
|
|
327
337
|
getNameByParams,
|
|
328
338
|
mergeFields,
|
|
329
339
|
parseFields,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/resourcer",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/utils": "2.2.
|
|
9
|
+
"@nocobase/utils": "2.2.44",
|
|
10
10
|
"deepmerge": "^4.2.2",
|
|
11
11
|
"koa": "^3.2.0",
|
|
12
12
|
"koa-compose": "^4.1.0",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
23
23
|
"directory": "packages/resourcer"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "7129d0eb6df74b6fd5c77c45b4d8557c1356c9d4"
|
|
26
26
|
}
|