@nocobase/resourcer 0.19.0-alpha.9 → 0.20.0-alpha.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.
@@ -8,6 +8,7 @@ export interface ResourcerContext {
8
8
  [key: string]: any;
9
9
  }
10
10
  export interface KoaMiddlewareOptions {
11
+ skipIfDataSourceExists?: boolean;
11
12
  /**
12
13
  * 前缀
13
14
  */
@@ -167,7 +168,7 @@ export declare class Resourcer {
167
168
  getAction(name: string, action: ActionName): Action;
168
169
  getMiddlewares(): any[];
169
170
  use(middlewares: HandlerType | HandlerType[], options?: ToposortOptions): void;
170
- restApiMiddleware({ prefix, accessors }?: KoaMiddlewareOptions): (ctx: ResourcerContext, next: () => Promise<any>) => Promise<any>;
171
+ restApiMiddleware({ prefix, accessors, skipIfDataSourceExists }?: KoaMiddlewareOptions): (ctx: ResourcerContext, next: () => Promise<any>) => Promise<any>;
171
172
  middleware(options?: KoaMiddlewareOptions): (ctx: ResourcerContext, next: () => Promise<any>) => Promise<any>;
172
173
  /**
173
174
  * 实验性 API
package/lib/resourcer.js CHANGED
@@ -137,8 +137,14 @@ const _Resourcer = class _Resourcer {
137
137
  use(middlewares, options = {}) {
138
138
  this.middlewares.add(middlewares, options);
139
139
  }
140
- restApiMiddleware({ prefix, accessors } = {}) {
140
+ restApiMiddleware({ prefix, accessors, skipIfDataSourceExists = false } = {}) {
141
141
  return async (ctx, next) => {
142
+ if (skipIfDataSourceExists) {
143
+ const dataSource = ctx.get("x-data-source");
144
+ if (dataSource) {
145
+ return next();
146
+ }
147
+ }
142
148
  ctx.resourcer = this;
143
149
  let params = (0, import_utils2.parseRequest)(
144
150
  {
@@ -193,6 +199,7 @@ const _Resourcer = class _Resourcer {
193
199
  }
194
200
  return (0, import_koa_compose.default)(ctx.action.getHandlers())(ctx, next);
195
201
  } catch (error) {
202
+ console.log(error);
196
203
  return next();
197
204
  }
198
205
  };
package/lib/utils.d.ts CHANGED
@@ -2,6 +2,7 @@ import { ResourceType } from './resource';
2
2
  export interface ParseRequest {
3
3
  path: string;
4
4
  method: string;
5
+ namespace?: string;
5
6
  type?: ResourceType;
6
7
  }
7
8
  export interface ParseOptions {
package/lib/utils.js CHANGED
@@ -59,7 +59,8 @@ function parseRequest(request, options = {}) {
59
59
  };
60
60
  const keys = [];
61
61
  const regexp = (0, import_path_to_regexp.pathToRegexp)("/resourcer/{:associatedName.}?:resourceName{\\::actionName}", keys);
62
- const matches = regexp.exec(request.path);
62
+ const reqPath = decodeURI(request.path);
63
+ const matches = regexp.exec(reqPath);
63
64
  if (matches) {
64
65
  const params2 = {};
65
66
  keys.forEach((obj, index) => {
@@ -160,7 +161,7 @@ function parseRequest(request, options = {}) {
160
161
  for (const path in defaults[type]) {
161
162
  const keys2 = [];
162
163
  const regexp2 = (0, import_path_to_regexp.pathToRegexp)(`${prefix}${path}`, keys2, {});
163
- const matches2 = regexp2.exec(request.path);
164
+ const matches2 = regexp2.exec(reqPath);
164
165
  if (!matches2) {
165
166
  continue;
166
167
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nocobase/resourcer",
3
- "version": "0.19.0-alpha.9",
3
+ "version": "0.20.0-alpha.2",
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": "0.19.0-alpha.9",
9
+ "@nocobase/utils": "0.20.0-alpha.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": "975f9c58a1995df6a8d7a4d191a0dc4a9769ebc5"
21
+ "gitHead": "6fb885dfc3554e4b0f29e9a7a1eecbbe85d0eebb"
22
22
  }