@kiwano/core 2.2.0-beta.2 → 3.0.0-beta.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.
- package/LICENSE +21 -0
- package/dist/index.cjs +2250 -0
- package/dist/index.js +2118 -35
- package/dist/{Builder.d.ts → types/Builder.d.ts} +5 -5
- package/dist/{argument.d.ts → types/argument.d.ts} +3 -3
- package/dist/{common.d.ts → types/common.d.ts} +2 -2
- package/dist/{entity → types/entity}/createInputObjectType.d.ts +3 -3
- package/dist/{entity → types/entity}/entitySchema.d.ts +4 -4
- package/dist/{entity → types/entity}/updateInputObjectType.d.ts +3 -3
- package/dist/{enumType.d.ts → types/enumType.d.ts} +3 -3
- package/dist/{enumValue.d.ts → types/enumValue.d.ts} +3 -3
- package/dist/{field.d.ts → types/field.d.ts} +7 -7
- package/dist/{inputField.d.ts → types/inputField.d.ts} +3 -3
- package/dist/{inputObjectType.d.ts → types/inputObjectType.d.ts} +5 -5
- package/dist/{naming → types/naming}/common.d.ts +1 -2
- package/dist/{naming → types/naming}/compact.d.ts +1 -1
- package/dist/{naming → types/naming}/descriptive.d.ts +1 -1
- package/dist/{objectType.d.ts → types/objectType.d.ts} +4 -4
- package/dist/{plugin → types/plugin}/MultiPlugin.d.ts +14 -14
- package/dist/{plugin → types/plugin}/acl/acl.d.ts +5 -5
- package/dist/{plugin → types/plugin}/acl/middleware.d.ts +4 -4
- package/dist/{plugin → types/plugin}/common.d.ts +13 -13
- package/dist/{plugin → types/plugin}/filter/equals.d.ts +5 -5
- package/dist/{plugin → types/plugin}/filter/search.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/connection.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/firstAfter.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/items.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/offsetLimit.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/simple.d.ts +1 -1
- package/dist/{plugin → types/plugin}/sort/sort.d.ts +5 -5
- package/dist/{schema.d.ts → types/schema.d.ts} +9 -9
- package/dist/{unionType.d.ts → types/unionType.d.ts} +3 -3
- package/dist/{util.d.ts → types/util.d.ts} +4 -4
- package/package.json +43 -34
- package/dist/Builder.js +0 -113
- package/dist/argument.js +0 -100
- package/dist/common.js +0 -2
- package/dist/entity/createInputObjectType.js +0 -55
- package/dist/entity/entitySchema.js +0 -212
- package/dist/entity/index.js +0 -24
- package/dist/entity/updateInputObjectType.js +0 -55
- package/dist/enumType.js +0 -126
- package/dist/enumValue.js +0 -60
- package/dist/error/FrameworkError.js +0 -12
- package/dist/error/index.js +0 -18
- package/dist/error/resolver/DataError.js +0 -11
- package/dist/error/resolver/ForbiddenError.js +0 -11
- package/dist/error/resolver/InvalidInputError.js +0 -11
- package/dist/error/resolver/NotFoundError.js +0 -11
- package/dist/error/resolver/ResolverError.js +0 -11
- package/dist/error/resolver/index.js +0 -21
- package/dist/field.js +0 -193
- package/dist/inputField.js +0 -100
- package/dist/inputObjectType.js +0 -119
- package/dist/naming/common.js +0 -2
- package/dist/naming/compact.js +0 -54
- package/dist/naming/descriptive.js +0 -54
- package/dist/naming/index.js +0 -20
- package/dist/naming/util.js +0 -22
- package/dist/objectType.js +0 -140
- package/dist/plugin/MultiPlugin.js +0 -147
- package/dist/plugin/PluginError.js +0 -11
- package/dist/plugin/acl/acl.js +0 -205
- package/dist/plugin/acl/index.js +0 -18
- package/dist/plugin/acl/middleware.js +0 -48
- package/dist/plugin/common.js +0 -2
- package/dist/plugin/filter/equals.js +0 -124
- package/dist/plugin/filter/index.js +0 -18
- package/dist/plugin/filter/search.js +0 -24
- package/dist/plugin/index.js +0 -23
- package/dist/plugin/pagination/connection.js +0 -115
- package/dist/plugin/pagination/firstAfter.js +0 -19
- package/dist/plugin/pagination/index.js +0 -22
- package/dist/plugin/pagination/items.js +0 -78
- package/dist/plugin/pagination/offsetLimit.js +0 -19
- package/dist/plugin/pagination/relay.js +0 -26
- package/dist/plugin/pagination/simple.js +0 -20
- package/dist/plugin/sort/index.js +0 -22
- package/dist/plugin/sort/sort.js +0 -151
- package/dist/schema.js +0 -380
- package/dist/unionType.js +0 -75
- package/dist/util.js +0 -142
- /package/dist/{entity → types/entity}/index.d.ts +0 -0
- /package/dist/{error → types/error}/FrameworkError.d.ts +0 -0
- /package/dist/{error → types/error}/index.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/DataError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/ForbiddenError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/InvalidInputError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/NotFoundError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/ResolverError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/index.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{naming → types/naming}/index.d.ts +0 -0
- /package/dist/{naming → types/naming}/util.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/PluginError.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/acl/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/filter/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/pagination/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/pagination/relay.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/sort/index.d.ts +0 -0
package/dist/plugin/acl/acl.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AclPlugin = exports.defaultAclOptions = exports.AclAction = void 0;
|
|
7
|
-
exports.aclPlugin = aclPlugin;
|
|
8
|
-
const lodash_1 = require("lodash");
|
|
9
|
-
const middleware_1 = require("./middleware");
|
|
10
|
-
const FrameworkError_1 = __importDefault(require("../../error/FrameworkError"));
|
|
11
|
-
var AclAction;
|
|
12
|
-
(function (AclAction) {
|
|
13
|
-
AclAction[AclAction["DENY"] = 0] = "DENY";
|
|
14
|
-
AclAction[AclAction["ALLOW"] = 1] = "ALLOW";
|
|
15
|
-
})(AclAction || (exports.AclAction = AclAction = {}));
|
|
16
|
-
exports.defaultAclOptions = {
|
|
17
|
-
defaultAction: AclAction.DENY,
|
|
18
|
-
learn: true
|
|
19
|
-
};
|
|
20
|
-
class AclPlugin {
|
|
21
|
-
constructor(options) {
|
|
22
|
-
this._roles = new Map();
|
|
23
|
-
this._allowRules = new Map();
|
|
24
|
-
this._denyRules = new Map();
|
|
25
|
-
this._options = (0, lodash_1.defaults)(options || {}, middleware_1.defaultAclMiddlewareOptions, exports.defaultAclOptions);
|
|
26
|
-
}
|
|
27
|
-
defaultAction(action) {
|
|
28
|
-
this._options.defaultAction = action;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
learn(learn = true) {
|
|
32
|
-
this._options.learn = learn;
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
role(identifier, parent = null) {
|
|
36
|
-
this._roles.set(identifier, {
|
|
37
|
-
identifier, parent
|
|
38
|
-
});
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
allow(resource, roles) {
|
|
42
|
-
const parsedRoles = new Set((0, lodash_1.isArray)(roles) ? roles : [roles]);
|
|
43
|
-
if (this._options.learn) {
|
|
44
|
-
this._learnRoles(parsedRoles);
|
|
45
|
-
}
|
|
46
|
-
if (this._allowRules.has(resource)) {
|
|
47
|
-
const config = this._allowRules.get(resource);
|
|
48
|
-
parsedRoles.forEach(role => config.roles.add(role));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this._allowRules.set(resource, this._getRuleConfig(resource, parsedRoles));
|
|
52
|
-
}
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
deny(resource, roles) {
|
|
56
|
-
const parsedRoles = new Set((0, lodash_1.isArray)(roles) ? roles : [roles]);
|
|
57
|
-
if (this._options.learn) {
|
|
58
|
-
this._learnRoles(parsedRoles);
|
|
59
|
-
}
|
|
60
|
-
if (this._denyRules.has(resource)) {
|
|
61
|
-
const config = this._denyRules.get(resource);
|
|
62
|
-
parsedRoles.forEach(role => config.roles.add(role));
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
this._denyRules.set(resource, this._getRuleConfig(resource, parsedRoles));
|
|
66
|
-
}
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
isAllowed(role, resource) {
|
|
70
|
-
let determinedAction = this._options.defaultAction;
|
|
71
|
-
const allowRules = this._findRules(resource, this._allowRules);
|
|
72
|
-
const denyRules = this._findRules(resource, this._denyRules);
|
|
73
|
-
const rules = (0, lodash_1.sortBy)([
|
|
74
|
-
...allowRules.map(rule => ({ rule, action: AclAction.ALLOW })),
|
|
75
|
-
...denyRules.map(rule => ({ rule, action: AclAction.DENY })),
|
|
76
|
-
], rule => rule.rule.name.length);
|
|
77
|
-
for (let { rule, action } of rules) {
|
|
78
|
-
if (this.isRoleIncluded(role, rule.roles)) {
|
|
79
|
-
determinedAction = action;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return determinedAction === AclAction.ALLOW;
|
|
83
|
-
}
|
|
84
|
-
isRoleIncluded(role, compareRoles) {
|
|
85
|
-
const roleConfig = this._roles.get(role);
|
|
86
|
-
if (!roleConfig) {
|
|
87
|
-
throw new FrameworkError_1.default(`Role "${role}" not registered`);
|
|
88
|
-
}
|
|
89
|
-
if (compareRoles.has(role)) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
const roleList = this._getRoleList(roleConfig);
|
|
93
|
-
for (let candidate of compareRoles) {
|
|
94
|
-
if (roleList.indexOf(candidate) >= 0) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
validate(config, role = null) {
|
|
101
|
-
let parsedConfig;
|
|
102
|
-
if ((0, lodash_1.isArray)(config)) {
|
|
103
|
-
parsedConfig = { allowedRoles: config };
|
|
104
|
-
}
|
|
105
|
-
else if ((0, lodash_1.isString)(config) || (0, lodash_1.isNumber)(config)) {
|
|
106
|
-
parsedConfig = { allowedRoles: [config] };
|
|
107
|
-
}
|
|
108
|
-
else if (config) {
|
|
109
|
-
parsedConfig = config;
|
|
110
|
-
}
|
|
111
|
-
let allowed = this._options.defaultAction === AclAction.ALLOW;
|
|
112
|
-
if (role) {
|
|
113
|
-
if (parsedConfig.allowedRoles) {
|
|
114
|
-
allowed = this.isRoleIncluded(role, new Set(parsedConfig.allowedRoles));
|
|
115
|
-
}
|
|
116
|
-
else if (parsedConfig.resource) {
|
|
117
|
-
allowed = this.isAllowed(role, parsedConfig.resource);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return allowed;
|
|
121
|
-
}
|
|
122
|
-
middleware(config = null) {
|
|
123
|
-
return (0, middleware_1.expressAclMiddleware)(this, config, this._options);
|
|
124
|
-
}
|
|
125
|
-
rolePath(path) {
|
|
126
|
-
this._options.rolePath = path;
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
onForbidden(handler) {
|
|
130
|
-
this._options.onForbidden = handler;
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
beforeBuildSchema(builder, rootBuilder) {
|
|
134
|
-
// Add middleware
|
|
135
|
-
builder.use((0, middleware_1.graphQLAclMiddleware)(this, rootBuilder.name || rootBuilder.tag.toString(), this._options));
|
|
136
|
-
}
|
|
137
|
-
afterBuildSchema(builder, schema, rootBuilder) {
|
|
138
|
-
// Add rules
|
|
139
|
-
const schemaId = rootBuilder.name || rootBuilder.tag.toString();
|
|
140
|
-
for (let type of builder.getObjectTypes()) {
|
|
141
|
-
const typeInfo = type.info();
|
|
142
|
-
this.addRules(`${schemaId}:${type.name}.*`, typeInfo.allowedRoles, typeInfo.deniedRoles);
|
|
143
|
-
for (let field of type.info().fields) {
|
|
144
|
-
const fieldInfo = field.info();
|
|
145
|
-
this.addRules(`${schemaId}:${type.name}.${field.name}`, fieldInfo.allowedRoles, fieldInfo.deniedRoles);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
addRules(resource, allowed, denied) {
|
|
150
|
-
if (allowed.size > 0) {
|
|
151
|
-
this.allow(resource, Array.from(allowed));
|
|
152
|
-
}
|
|
153
|
-
if (denied.size > 0) {
|
|
154
|
-
this.deny(resource, Array.from(denied));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
_findRules(resource, collection) {
|
|
158
|
-
const allRules = Array.from(collection.values());
|
|
159
|
-
return allRules.filter(rule => {
|
|
160
|
-
if ((0, lodash_1.isString)(rule.resource)) {
|
|
161
|
-
return rule.resource === resource;
|
|
162
|
-
}
|
|
163
|
-
else if (rule.resource instanceof RegExp) {
|
|
164
|
-
return rule.resource.test(resource);
|
|
165
|
-
}
|
|
166
|
-
return false;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
_learnRoles(roles) {
|
|
170
|
-
for (let role of roles) {
|
|
171
|
-
if (!this._roles.has(role)) {
|
|
172
|
-
this.role(role);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
_getRoleList(roleConfig) {
|
|
177
|
-
if (!roleConfig) {
|
|
178
|
-
return [];
|
|
179
|
-
}
|
|
180
|
-
if (!roleConfig.parent) {
|
|
181
|
-
return [roleConfig.identifier];
|
|
182
|
-
}
|
|
183
|
-
return [
|
|
184
|
-
roleConfig.identifier,
|
|
185
|
-
...this._getRoleList(this._roles.get(roleConfig.parent))
|
|
186
|
-
];
|
|
187
|
-
}
|
|
188
|
-
_getRuleConfig(name, roles) {
|
|
189
|
-
let resource = name;
|
|
190
|
-
if (name.indexOf('*') >= 0) {
|
|
191
|
-
const pattern = (0, lodash_1.escapeRegExp)(name).replace('\\*', '(.*)');
|
|
192
|
-
resource = new RegExp(`^${pattern}$`);
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
name,
|
|
196
|
-
resource,
|
|
197
|
-
roles
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
exports.AclPlugin = AclPlugin;
|
|
202
|
-
function aclPlugin(options) {
|
|
203
|
-
return new AclPlugin(options);
|
|
204
|
-
}
|
|
205
|
-
exports.default = aclPlugin;
|
package/dist/plugin/acl/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./acl"), exports);
|
|
18
|
-
__exportStar(require("./middleware"), exports);
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultAclMiddlewareOptions = void 0;
|
|
4
|
-
exports.expressAclMiddleware = expressAclMiddleware;
|
|
5
|
-
exports.graphQLAclMiddleware = graphQLAclMiddleware;
|
|
6
|
-
exports.getPathResource = getPathResource;
|
|
7
|
-
const lodash_1 = require("lodash");
|
|
8
|
-
const resolver_1 = require("../../error/resolver");
|
|
9
|
-
exports.defaultAclMiddlewareOptions = {
|
|
10
|
-
rolePath: "role",
|
|
11
|
-
onForbidden: resource => { throw new resolver_1.ForbiddenError(`No access to ${resource}`); }
|
|
12
|
-
};
|
|
13
|
-
function expressAclMiddleware(acl, config = null, options = null) {
|
|
14
|
-
const fullOptions = getOptions(options);
|
|
15
|
-
return (req, res, next) => {
|
|
16
|
-
var _a;
|
|
17
|
-
const fullPath = req.baseUrl + req.path;
|
|
18
|
-
if (!config) {
|
|
19
|
-
config = { resource: fullPath };
|
|
20
|
-
}
|
|
21
|
-
const role = (_a = (0, lodash_1.get)(req, fullOptions.rolePath)) !== null && _a !== void 0 ? _a : null;
|
|
22
|
-
const allowed = acl.validate(config, role);
|
|
23
|
-
if (!allowed) {
|
|
24
|
-
fullOptions.onForbidden(fullPath);
|
|
25
|
-
}
|
|
26
|
-
next();
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function graphQLAclMiddleware(acl, schemaName, options = null) {
|
|
30
|
-
const fullOptions = getOptions(options);
|
|
31
|
-
return (resolve, root, args, context, info) => {
|
|
32
|
-
var _a;
|
|
33
|
-
const pathResource = getPathResource(info.path);
|
|
34
|
-
let parsedConfig = { resource: `${schemaName}:${pathResource}` };
|
|
35
|
-
const role = (_a = (0, lodash_1.get)(context, fullOptions.rolePath)) !== null && _a !== void 0 ? _a : null;
|
|
36
|
-
const allowed = acl.validate(parsedConfig, role);
|
|
37
|
-
if (!allowed) {
|
|
38
|
-
fullOptions.onForbidden(pathResource);
|
|
39
|
-
}
|
|
40
|
-
return resolve(root, args, context, info);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function getPathResource(path) {
|
|
44
|
-
return [path.typename, path.key].join('.');
|
|
45
|
-
}
|
|
46
|
-
function getOptions(options) {
|
|
47
|
-
return (0, lodash_1.defaults)({}, options || {}, exports.defaultAclMiddlewareOptions);
|
|
48
|
-
}
|
package/dist/plugin/common.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EqualsFilterPlugin = exports.defaultEqualsFilterPluginOptions = void 0;
|
|
7
|
-
exports.equalsFilterPlugin = equalsFilterPlugin;
|
|
8
|
-
const lodash_1 = require("lodash");
|
|
9
|
-
const inputObjectType_1 = __importDefault(require("../../inputObjectType"));
|
|
10
|
-
const objectType_1 = require("../../objectType");
|
|
11
|
-
const util_1 = require("../../util");
|
|
12
|
-
const PluginError_1 = __importDefault(require("../PluginError"));
|
|
13
|
-
exports.defaultEqualsFilterPluginOptions = {
|
|
14
|
-
multi: false,
|
|
15
|
-
manual: false,
|
|
16
|
-
argumentName: 'filter',
|
|
17
|
-
inputName: typeName => `${typeName}EqualsFilter`,
|
|
18
|
-
};
|
|
19
|
-
class EqualsFilterPlugin {
|
|
20
|
-
constructor(options) {
|
|
21
|
-
this._options = (0, lodash_1.defaults)(options || {}, exports.defaultEqualsFilterPluginOptions, {
|
|
22
|
-
exclude: [],
|
|
23
|
-
include: []
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
multi(multi = true) {
|
|
27
|
-
this._options.multi = multi;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
manual(manual = true) {
|
|
31
|
-
this._options.manual = manual;
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
field(name, type) {
|
|
35
|
-
if (!this._options.fields) {
|
|
36
|
-
this._options.fields = [];
|
|
37
|
-
}
|
|
38
|
-
this._options.fields.push({ name, type });
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
exclude(...fieldNames) {
|
|
42
|
-
fieldNames.forEach(name => this._options.exclude.push(name));
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
include(...fieldNames) {
|
|
46
|
-
fieldNames.forEach(name => this._options.include.push(name));
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
argumentName(name) {
|
|
50
|
-
this._options.argumentName = name;
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
inputName(nameFactory) {
|
|
54
|
-
this._options.inputName = nameFactory;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
beforeBuildField(builder, context, info) {
|
|
58
|
-
if (!info.list) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const typeName = info.type.toString();
|
|
62
|
-
const inputTypeName = this._options.inputName(typeName);
|
|
63
|
-
let targetObjectType;
|
|
64
|
-
if (!this._options.manual) {
|
|
65
|
-
targetObjectType = context.rootSchema.findType(typeName, true);
|
|
66
|
-
if (!targetObjectType) {
|
|
67
|
-
throw new PluginError_1.default(`Filter target object ${typeName} not found`);
|
|
68
|
-
}
|
|
69
|
-
if (!(targetObjectType instanceof objectType_1.ObjectTypeBuilder)) {
|
|
70
|
-
throw new PluginError_1.default(`Filter target ${typeName} is not an object type`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const inputType = this._createFilterInputType(context, inputTypeName, targetObjectType);
|
|
74
|
-
context.schema.inputObject(inputType);
|
|
75
|
-
builder.arg(this._options.argumentName, inputTypeName, _ => _.description(`Configuration for how the nodes should be filtered`));
|
|
76
|
-
}
|
|
77
|
-
_createFilterInputType(context, name, targetObjectType) {
|
|
78
|
-
var _a;
|
|
79
|
-
const inputObjectType = (0, inputObjectType_1.default)(name)
|
|
80
|
-
.description(`Configuration for how the nodes should be filtered`);
|
|
81
|
-
let fields = new Set();
|
|
82
|
-
if (targetObjectType) {
|
|
83
|
-
for (let field of targetObjectType.info().fields) {
|
|
84
|
-
const fieldInfo = field.info();
|
|
85
|
-
if (fieldInfo.list || !(0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema)) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (((_a = this._options.include) === null || _a === void 0 ? void 0 : _a.length) && !this._options.include.includes(field.name)) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
fields.add({
|
|
92
|
-
name: field.name,
|
|
93
|
-
type: fieldInfo.type
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (this._options.fields) {
|
|
98
|
-
this._options.fields.forEach(field => fields.add(field));
|
|
99
|
-
}
|
|
100
|
-
const extraFields = this._getExtraFieldConfigs(context, name, targetObjectType);
|
|
101
|
-
if (extraFields) {
|
|
102
|
-
extraFields.forEach(extraField => fields.add(extraField));
|
|
103
|
-
}
|
|
104
|
-
for (let field of fields) {
|
|
105
|
-
if (this._options.exclude && this._options.exclude.indexOf(field.name) >= 0) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
inputObjectType.field(field.name, field.type, _ => {
|
|
109
|
-
if (this._options.multi) {
|
|
110
|
-
_.list();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return inputObjectType;
|
|
115
|
-
}
|
|
116
|
-
_getExtraFieldConfigs(context, name, targetObjectType) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.EqualsFilterPlugin = EqualsFilterPlugin;
|
|
121
|
-
function equalsFilterPlugin(options) {
|
|
122
|
-
return new EqualsFilterPlugin(options);
|
|
123
|
-
}
|
|
124
|
-
exports.default = equalsFilterPlugin;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./equals"), exports);
|
|
18
|
-
__exportStar(require("./search"), exports);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchFilterPlugin = exports.defaultSearchFilterPluginOptions = void 0;
|
|
4
|
-
exports.searchFilterPlugin = searchFilterPlugin;
|
|
5
|
-
const lodash_1 = require("lodash");
|
|
6
|
-
exports.defaultSearchFilterPluginOptions = {
|
|
7
|
-
argumentName: 'search'
|
|
8
|
-
};
|
|
9
|
-
class SearchFilterPlugin {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this._options = (0, lodash_1.defaults)(options || {}, exports.defaultSearchFilterPluginOptions);
|
|
12
|
-
}
|
|
13
|
-
beforeBuildField(builder, context, info) {
|
|
14
|
-
if (!info.list) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
builder.arg(this._options.argumentName, 'String', _ => _.description('Search query'));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.SearchFilterPlugin = SearchFilterPlugin;
|
|
21
|
-
function searchFilterPlugin() {
|
|
22
|
-
return new SearchFilterPlugin();
|
|
23
|
-
}
|
|
24
|
-
exports.default = searchFilterPlugin;
|
package/dist/plugin/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./acl"), exports);
|
|
18
|
-
__exportStar(require("./filter"), exports);
|
|
19
|
-
__exportStar(require("./pagination"), exports);
|
|
20
|
-
__exportStar(require("./sort"), exports);
|
|
21
|
-
__exportStar(require("./common"), exports);
|
|
22
|
-
__exportStar(require("./MultiPlugin"), exports);
|
|
23
|
-
__exportStar(require("./PluginError"), exports);
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ConnectionPaginationPlugin = void 0;
|
|
40
|
-
exports.connectionPaginationPlugin = connectionPaginationPlugin;
|
|
41
|
-
const objectType_1 = __importStar(require("../../objectType"));
|
|
42
|
-
const PluginError_1 = __importDefault(require("../PluginError"));
|
|
43
|
-
const PageInfoObjectTypeName = "PageInfo";
|
|
44
|
-
class ConnectionPaginationPlugin {
|
|
45
|
-
constructor() {
|
|
46
|
-
this._totalCount = false;
|
|
47
|
-
}
|
|
48
|
-
totalCount(totalCount = true) {
|
|
49
|
-
this._totalCount = totalCount;
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
beforeBuildField(builder, context, info) {
|
|
53
|
-
if (!info.list) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
// Create edges type
|
|
57
|
-
if (!context.schema.hasType(PageInfoObjectTypeName)) {
|
|
58
|
-
context.schema.object(this._createPageInfoObjectType());
|
|
59
|
-
}
|
|
60
|
-
const typeName = info.type.toString();
|
|
61
|
-
const targetType = context.rootSchema.findType(typeName, true);
|
|
62
|
-
if (!targetType) {
|
|
63
|
-
throw new PluginError_1.default(`Edges target type "${typeName}" not found`);
|
|
64
|
-
}
|
|
65
|
-
if (!(targetType instanceof objectType_1.ObjectTypeBuilder)) {
|
|
66
|
-
throw new PluginError_1.default(`Edges target "${typeName}" is not an object type`);
|
|
67
|
-
}
|
|
68
|
-
const targetObjectInfo = targetType.info();
|
|
69
|
-
const pageInfoType = context.schema.findType(PageInfoObjectTypeName);
|
|
70
|
-
pageInfoType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
71
|
-
pageInfoType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
72
|
-
const edgeObjectTypeName = `${typeName}Edge`;
|
|
73
|
-
const edgeObjectType = this._createEdgeObjectType(edgeObjectTypeName, typeName);
|
|
74
|
-
edgeObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
75
|
-
edgeObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
76
|
-
context.schema.object(edgeObjectType);
|
|
77
|
-
const connectionObjectTypeName = `${typeName}Connection`;
|
|
78
|
-
const connectionObjectType = this._createConnectionObjectType(connectionObjectTypeName, edgeObjectTypeName);
|
|
79
|
-
connectionObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
80
|
-
connectionObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
81
|
-
context.schema.object(connectionObjectType);
|
|
82
|
-
builder
|
|
83
|
-
.type(connectionObjectTypeName)
|
|
84
|
-
.list(false);
|
|
85
|
-
}
|
|
86
|
-
_createPageInfoObjectType() {
|
|
87
|
-
return (0, objectType_1.default)(PageInfoObjectTypeName)
|
|
88
|
-
.description('Provides information about the paging state')
|
|
89
|
-
.field('hasNextPage', 'Boolean', _ => _.nonNull().description('Indicates whether there is a next page'))
|
|
90
|
-
.field('hasPreviousPage', 'Boolean', _ => _.nonNull().description('Indicates whether there is a previous page'))
|
|
91
|
-
.field('startCursor', 'String', _ => _.description('Cursor for the first node'))
|
|
92
|
-
.field('endCursor', 'String', _ => _.description('Cursor for the last node'));
|
|
93
|
-
}
|
|
94
|
-
_createConnectionObjectType(name, edgeTypeName) {
|
|
95
|
-
const type = (0, objectType_1.default)(name)
|
|
96
|
-
.description(`Connection with ${edgeTypeName}`)
|
|
97
|
-
.field('pageInfo', PageInfoObjectTypeName, _ => _.nonNull().description('Provides information about the paging state'))
|
|
98
|
-
.field('edges', edgeTypeName, _ => _.list().description('List of the queried edges'));
|
|
99
|
-
if (this._totalCount) {
|
|
100
|
-
type.field('totalCount', 'Int', _ => _.nonNull().description('Total number of nodes'));
|
|
101
|
-
}
|
|
102
|
-
return type;
|
|
103
|
-
}
|
|
104
|
-
_createEdgeObjectType(name, typeName) {
|
|
105
|
-
return (0, objectType_1.default)(name)
|
|
106
|
-
.description(`${typeName} edge`)
|
|
107
|
-
.field('node', typeName, _ => _.description('Current node'))
|
|
108
|
-
.field('cursor', 'String', _ => _.nonNull().description('Cursor for the current node'));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.ConnectionPaginationPlugin = ConnectionPaginationPlugin;
|
|
112
|
-
function connectionPaginationPlugin() {
|
|
113
|
-
return new ConnectionPaginationPlugin();
|
|
114
|
-
}
|
|
115
|
-
exports.default = connectionPaginationPlugin;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FirstAfterPaginationPlugin = void 0;
|
|
4
|
-
exports.firstAfterPaginationPlugin = firstAfterPaginationPlugin;
|
|
5
|
-
class FirstAfterPaginationPlugin {
|
|
6
|
-
beforeBuildField(builder, context, info) {
|
|
7
|
-
if (!info.list) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
builder
|
|
11
|
-
.arg('first', 'Int', _ => _.description('Number of nodes to return'))
|
|
12
|
-
.arg('after', 'String', _ => _.description('Cursor for item after which results are to be selected'));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.FirstAfterPaginationPlugin = FirstAfterPaginationPlugin;
|
|
16
|
-
function firstAfterPaginationPlugin() {
|
|
17
|
-
return new FirstAfterPaginationPlugin();
|
|
18
|
-
}
|
|
19
|
-
exports.default = firstAfterPaginationPlugin;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./connection"), exports);
|
|
18
|
-
__exportStar(require("./firstAfter"), exports);
|
|
19
|
-
__exportStar(require("./items"), exports);
|
|
20
|
-
__exportStar(require("./offsetLimit"), exports);
|
|
21
|
-
__exportStar(require("./relay"), exports);
|
|
22
|
-
__exportStar(require("./simple"), exports);
|