@nocobase/resourcer 0.14.0-alpha.2 → 0.14.0-alpha.4

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/resource.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Action, { ActionName, ActionType } from './action';
2
2
  import Middleware, { MiddlewareType } from './middleware';
3
- import { Resourcer } from './resourcer';
3
+ import { HandlerType, Resourcer } from './resourcer';
4
4
  export type ResourceType = 'single' | 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany';
5
5
  export interface ResourceOptions {
6
6
  /**
@@ -47,6 +47,7 @@ export declare class Resource {
47
47
  constructor(options: ResourceOptions, resourcer: Resourcer);
48
48
  getName(): string;
49
49
  getExcept(): ActionName[];
50
+ addAction(name: ActionName, handler: HandlerType): void;
50
51
  getAction(action: ActionName): Action;
51
52
  }
52
53
  export default Resource;
package/lib/resource.js CHANGED
@@ -66,6 +66,19 @@ const _Resource = class _Resource {
66
66
  getExcept() {
67
67
  return this.except;
68
68
  }
69
+ addAction(name, handler) {
70
+ if (this.except.includes(name)) {
71
+ throw new Error(`${name} action is not allowed`);
72
+ }
73
+ if (this.actions.has(name)) {
74
+ throw new Error(`${name} action already exists`);
75
+ }
76
+ const action = new import_action.default(handler);
77
+ action.setName(name);
78
+ action.setResource(this);
79
+ action.middlewares.unshift(...this.middlewares);
80
+ this.actions.set(name, action);
81
+ }
69
82
  getAction(action) {
70
83
  if (this.except.includes(action)) {
71
84
  throw new Error(`${action} action is not allowed`);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nocobase/resourcer",
3
- "version": "0.14.0-alpha.2",
3
+ "version": "0.14.0-alpha.4",
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.14.0-alpha.2",
9
+ "@nocobase/utils": "0.14.0-alpha.4",
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": "ea841d4a1e8c37aa77b4fbae6a6a4937e2aa3c0a"
21
+ "gitHead": "e2aab7863bbdfd76afc7164272b275e868ac59c0"
22
22
  }