@nocobase/resourcer 0.8.0-alpha.8 → 0.8.1-alpha.3
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/action.d.ts +7 -1
- package/lib/action.js +20 -5
- package/lib/utils.js +7 -0
- package/package.json +3 -3
- package/lib/assign.d.ts +0 -10
- package/lib/assign.js +0 -145
package/lib/action.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MergeStrategies } from '
|
|
1
|
+
import { MergeStrategies } from '@nocobase/utils';
|
|
2
2
|
import Middleware, { MiddlewareType } from './middleware';
|
|
3
3
|
import Resource from './resource';
|
|
4
4
|
import { HandlerType } from './resourcer';
|
|
@@ -174,6 +174,12 @@ export declare class Action {
|
|
|
174
174
|
resourceOf: any;
|
|
175
175
|
readonly middlewares: Array<Middleware>;
|
|
176
176
|
constructor(options: ActionOptions);
|
|
177
|
+
toJSON(): {
|
|
178
|
+
actionName: string;
|
|
179
|
+
resourceName: string;
|
|
180
|
+
resourceOf: any;
|
|
181
|
+
params: ActionParams;
|
|
182
|
+
};
|
|
177
183
|
clone(): Action;
|
|
178
184
|
setContext(context: any): void;
|
|
179
185
|
mergeParams(params: ActionParams, strategies?: MergeStrategies): void;
|
package/lib/action.js
CHANGED
|
@@ -35,8 +35,6 @@ function _lodash() {
|
|
|
35
35
|
return data;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
var _assign = require("./assign");
|
|
39
|
-
|
|
40
38
|
var _middleware = _interopRequireDefault(require("./middleware"));
|
|
41
39
|
|
|
42
40
|
const _excluded = ["middleware", "middlewares", "handler"];
|
|
@@ -90,6 +88,15 @@ class Action {
|
|
|
90
88
|
this.mergeParams(params);
|
|
91
89
|
}
|
|
92
90
|
|
|
91
|
+
toJSON() {
|
|
92
|
+
return {
|
|
93
|
+
actionName: this.actionName,
|
|
94
|
+
resourceName: this.resourceName,
|
|
95
|
+
resourceOf: this.resourceOf,
|
|
96
|
+
params: this.params
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
93
100
|
clone() {
|
|
94
101
|
const options = _lodash().default.cloneDeep(this.options);
|
|
95
102
|
|
|
@@ -107,7 +114,15 @@ class Action {
|
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
mergeParams(params, strategies = {}) {
|
|
110
|
-
|
|
117
|
+
if (!this.params) {
|
|
118
|
+
this.params = {};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!params) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
(0, _utils().assign)(this.params, params, _objectSpread({
|
|
111
126
|
filter: 'andMerge',
|
|
112
127
|
fields: 'intersect',
|
|
113
128
|
appends: 'union',
|
|
@@ -155,8 +170,8 @@ class Action {
|
|
|
155
170
|
}
|
|
156
171
|
|
|
157
172
|
getHandlers() {
|
|
158
|
-
const
|
|
159
|
-
return
|
|
173
|
+
const handlers = [...this.resource.resourcer.getMiddlewares(), ...this.getMiddlewareHandlers(), this.getHandler()].filter(Boolean);
|
|
174
|
+
return handlers;
|
|
160
175
|
}
|
|
161
176
|
|
|
162
177
|
execute(context, next) {
|
package/lib/utils.js
CHANGED
|
@@ -165,6 +165,13 @@ function parseRequest(request, options = {}) {
|
|
|
165
165
|
patch: accessors.update,
|
|
166
166
|
delete: accessors.remove
|
|
167
167
|
}
|
|
168
|
+
},
|
|
169
|
+
set: {
|
|
170
|
+
'/:associatedName/:associatedIndex/:resourceName': {
|
|
171
|
+
get: accessors.list,
|
|
172
|
+
post: accessors.add,
|
|
173
|
+
delete: accessors.remove
|
|
174
|
+
}
|
|
168
175
|
}
|
|
169
176
|
};
|
|
170
177
|
const params = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/resourcer",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-alpha.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@nocobase/utils": "0.8.
|
|
15
|
+
"@nocobase/utils": "0.8.1-alpha.3",
|
|
16
16
|
"deepmerge": "^4.2.2",
|
|
17
17
|
"koa-compose": "^4.1.0",
|
|
18
18
|
"lodash": "^4.17.21",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
25
25
|
"directory": "packages/resourcer"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "e03df3df5962b99d9fbf5b6e33fbe2b23f14f3d3"
|
|
28
28
|
}
|
package/lib/assign.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare type MergeStrategyType = 'merge' | 'deepMerge' | 'overwrite' | 'andMerge' | 'orMerge' | 'intersect' | 'union';
|
|
2
|
-
declare type MergeStrategyFunc = (x: any, y: any) => any;
|
|
3
|
-
export declare type MergeStrategy = MergeStrategyType | MergeStrategyFunc;
|
|
4
|
-
export interface MergeStrategies {
|
|
5
|
-
[key: string]: MergeStrategy;
|
|
6
|
-
}
|
|
7
|
-
export default function isPlainObject(value: any): boolean;
|
|
8
|
-
export declare const mergeStrategies: Map<MergeStrategyType, MergeStrategyFunc>;
|
|
9
|
-
export declare function assign(target: any, source: any, strategies?: MergeStrategies): any;
|
|
10
|
-
export {};
|
package/lib/assign.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.assign = assign;
|
|
7
|
-
exports.default = isPlainObject;
|
|
8
|
-
exports.mergeStrategies = void 0;
|
|
9
|
-
|
|
10
|
-
function _deepmerge() {
|
|
11
|
-
const data = _interopRequireDefault(require("deepmerge"));
|
|
12
|
-
|
|
13
|
-
_deepmerge = function _deepmerge() {
|
|
14
|
-
return data;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function _lodash() {
|
|
21
|
-
const data = _interopRequireDefault(require("lodash"));
|
|
22
|
-
|
|
23
|
-
_lodash = function _lodash() {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
function isPlainObject(value) {
|
|
33
|
-
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const prototype = Object.getPrototypeOf(value);
|
|
38
|
-
return prototype === null || prototype === Object.prototype;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getEnumerableOwnPropertySymbols(target) {
|
|
42
|
-
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(symbol => target.propertyIsEnumerable(symbol)) : [];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getKeys(target) {
|
|
46
|
-
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const mergeStrategies = new Map();
|
|
50
|
-
exports.mergeStrategies = mergeStrategies;
|
|
51
|
-
mergeStrategies.set('overwrite', (_, y) => {
|
|
52
|
-
if (typeof y === 'string') {
|
|
53
|
-
y = y.split(',');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return y;
|
|
57
|
-
});
|
|
58
|
-
mergeStrategies.set('andMerge', (x, y) => {
|
|
59
|
-
if (!x && !y) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!x) {
|
|
64
|
-
return y;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!y) {
|
|
68
|
-
return x;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
$and: [x, y]
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
mergeStrategies.set('orMerge', (x, y) => {
|
|
76
|
-
if (!x && !y) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!x) {
|
|
81
|
-
return y;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (!y) {
|
|
85
|
-
return x;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
$or: [x, y]
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
mergeStrategies.set('deepMerge', (x, y) => {
|
|
93
|
-
return isPlainObject(x) && isPlainObject(y) ? (0, _deepmerge().default)(x, y, {
|
|
94
|
-
arrayMerge: (x, y) => y
|
|
95
|
-
}) : y;
|
|
96
|
-
});
|
|
97
|
-
mergeStrategies.set('merge', (x, y) => {
|
|
98
|
-
return isPlainObject(x) && isPlainObject(y) ? Object.assign(x, y) : y;
|
|
99
|
-
});
|
|
100
|
-
mergeStrategies.set('union', (x, y) => {
|
|
101
|
-
if (typeof x === 'string') {
|
|
102
|
-
x = x.split(',');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (typeof y === 'string') {
|
|
106
|
-
y = y.split(',');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return _lodash().default.uniq((x || []).concat(y || [])).filter(Boolean);
|
|
110
|
-
});
|
|
111
|
-
mergeStrategies.set('intersect', (x, y) => {
|
|
112
|
-
if (typeof x === 'string') {
|
|
113
|
-
x = x.split(',');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (typeof y === 'string') {
|
|
117
|
-
y = y.split(',');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!Array.isArray(x) || x.length === 0) {
|
|
121
|
-
return y || [];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (!Array.isArray(y) || y.length === 0) {
|
|
125
|
-
return x || [];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return x.filter(v => y.includes(v));
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
function assign(target, source, strategies = {}) {
|
|
132
|
-
getKeys(source).forEach(sourceKey => {
|
|
133
|
-
const strategy = strategies[sourceKey];
|
|
134
|
-
let func = mergeStrategies.get('deepMerge');
|
|
135
|
-
|
|
136
|
-
if (typeof strategy === 'function') {
|
|
137
|
-
func = strategy;
|
|
138
|
-
} else if (typeof strategy === 'string' && mergeStrategies.has(strategy)) {
|
|
139
|
-
func = mergeStrategies.get(strategy);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
target[sourceKey] = func(target[sourceKey], source[sourceKey]);
|
|
143
|
-
});
|
|
144
|
-
return target;
|
|
145
|
-
}
|