@kiwano/core 0.0.1 → 0.0.6
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/Builder.js +2 -2
- package/argument.d.ts +4 -0
- package/argument.js +28 -11
- package/enumType.js +7 -10
- package/enumValue.js +5 -7
- package/field.d.ts +4 -0
- package/field.js +33 -13
- package/inputField.d.ts +4 -0
- package/inputField.js +28 -11
- package/inputObjectType.js +7 -10
- package/objectType.js +7 -10
- package/package.json +8 -5
- package/plugin/MultiPlugin.d.ts +16 -16
- package/plugin/MultiPlugin.js +32 -32
- package/plugin/acl/{Acl.d.ts → acl.d.ts} +16 -8
- package/plugin/acl/{Acl.js → acl.js} +49 -25
- package/plugin/acl/index.d.ts +1 -4
- package/plugin/acl/index.js +1 -7
- package/plugin/acl/middleware.d.ts +3 -3
- package/plugin/acl/middleware.js +10 -13
- package/plugin/common.d.ts +16 -16
- package/plugin/filter/equals.d.ts +2 -2
- package/plugin/filter/equals.js +3 -4
- package/plugin/filter/search.d.ts +2 -2
- package/plugin/filter/search.js +3 -7
- package/plugin/pagination/connection.d.ts +2 -2
- package/plugin/pagination/connection.js +1 -2
- package/plugin/pagination/firstAfter.d.ts +2 -2
- package/plugin/pagination/firstAfter.js +1 -2
- package/plugin/pagination/items.d.ts +2 -2
- package/plugin/pagination/items.js +1 -2
- package/plugin/pagination/offsetLimit.d.ts +2 -2
- package/plugin/pagination/offsetLimit.js +1 -2
- package/plugin/sort/sort.d.ts +2 -2
- package/plugin/sort/sort.js +3 -4
- package/schema.js +22 -25
- package/unionType.js +6 -9
- package/util.d.ts +7 -0
- package/util.js +22 -11
- package/plugin/acl/plugin.d.ts +0 -15
- package/plugin/acl/plugin.js +0 -50
package/schema.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.schema = exports.SchemaBuilder = exports.AbstractSchemaBuilder = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const compact_1 = __importDefault(require("lodash/compact"));
|
|
10
|
-
const isString_1 = __importDefault(require("lodash/isString"));
|
|
11
|
-
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
12
|
-
const isObjectLike_1 = __importDefault(require("lodash/isObjectLike"));
|
|
13
|
-
const merge_1 = require("@graphql-tools/merge");
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const schema_1 = require("@graphql-tools/schema");
|
|
14
6
|
const graphql_middleware_1 = require("graphql-middleware");
|
|
15
7
|
const graphql_1 = require("graphql");
|
|
16
8
|
const objectType_1 = require("./objectType");
|
|
@@ -57,7 +49,7 @@ class AbstractSchemaBuilder {
|
|
|
57
49
|
return this;
|
|
58
50
|
}
|
|
59
51
|
getObjectTypes() {
|
|
60
|
-
return
|
|
52
|
+
return lodash_1.compact([this._queryObject, this._mutationObject, ...Array.from(this._objectTypes.values())]);
|
|
61
53
|
}
|
|
62
54
|
inputObject(objectOrName, configurator = null) {
|
|
63
55
|
const resolvedArgs = util_1.resolveBuilderArgs(objectOrName, configurator, inputObjectType_1.InputObjectTypeBuilder);
|
|
@@ -75,13 +67,13 @@ class AbstractSchemaBuilder {
|
|
|
75
67
|
let valuesObject = null;
|
|
76
68
|
if (enumOrName instanceof enumType_1.EnumTypeBuilder) {
|
|
77
69
|
builder = enumOrName;
|
|
78
|
-
if (
|
|
70
|
+
if (lodash_1.isFunction(configuratorOrValuesObject)) {
|
|
79
71
|
configurator = configuratorOrValuesObject;
|
|
80
72
|
}
|
|
81
73
|
}
|
|
82
|
-
else if (
|
|
74
|
+
else if (lodash_1.isString(enumOrName)) {
|
|
83
75
|
name = enumOrName;
|
|
84
|
-
if (
|
|
76
|
+
if (lodash_1.isFunction(configuratorOrValuesObject)) {
|
|
85
77
|
configurator = configuratorOrValuesObject;
|
|
86
78
|
}
|
|
87
79
|
else {
|
|
@@ -103,16 +95,16 @@ class AbstractSchemaBuilder {
|
|
|
103
95
|
let resolvedTypes = null;
|
|
104
96
|
if (objectOrName instanceof unionType_1.UnionTypeBuilder) {
|
|
105
97
|
builder = objectOrName;
|
|
106
|
-
if (
|
|
98
|
+
if (lodash_1.isFunction(configuratorOrTypes)) {
|
|
107
99
|
configurator = configuratorOrTypes;
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
|
-
else if (
|
|
102
|
+
else if (lodash_1.isString(objectOrName)) {
|
|
111
103
|
name = objectOrName;
|
|
112
|
-
if (
|
|
104
|
+
if (lodash_1.isFunction(configuratorOrTypes)) {
|
|
113
105
|
configurator = configuratorOrTypes;
|
|
114
106
|
}
|
|
115
|
-
else if (
|
|
107
|
+
else if (lodash_1.isArray(configuratorOrTypes)) {
|
|
116
108
|
resolvedTypes = configuratorOrTypes;
|
|
117
109
|
}
|
|
118
110
|
}
|
|
@@ -181,10 +173,10 @@ class AbstractSchemaBuilder {
|
|
|
181
173
|
}
|
|
182
174
|
use(...middlewareOrPlugins) {
|
|
183
175
|
for (let item of middlewareOrPlugins) {
|
|
184
|
-
if (
|
|
176
|
+
if (lodash_1.isObjectLike(item)) {
|
|
185
177
|
this._plugins.push(item);
|
|
186
178
|
}
|
|
187
|
-
else if (
|
|
179
|
+
else if (lodash_1.isFunction(item)) {
|
|
188
180
|
this._middleware.push(item);
|
|
189
181
|
}
|
|
190
182
|
}
|
|
@@ -232,7 +224,6 @@ class AbstractSchemaBuilder {
|
|
|
232
224
|
return Builder_1.resolveName(this._name);
|
|
233
225
|
}
|
|
234
226
|
async finalize(rootSchema) {
|
|
235
|
-
var _a;
|
|
236
227
|
const resolvedRootSchema = rootSchema || this;
|
|
237
228
|
// Assign naming strategy to sub schemas as default
|
|
238
229
|
if (this._namingStrategy) {
|
|
@@ -271,8 +262,14 @@ class AbstractSchemaBuilder {
|
|
|
271
262
|
for (let objectType of this.getObjectTypes()) {
|
|
272
263
|
objectType.allow(...Array.from(this._allowedRoles)).deny(...Array.from(this._deniedRoles));
|
|
273
264
|
}
|
|
274
|
-
this._queryObject.
|
|
275
|
-
|
|
265
|
+
for (let queryField of this._queryObject.info().fields) {
|
|
266
|
+
queryField.allow(...Array.from(this._allowedQueryRoles)).deny(...Array.from(this._deniedQueryRoles));
|
|
267
|
+
}
|
|
268
|
+
if (this._mutationObject) {
|
|
269
|
+
for (let mutationField of this._mutationObject.info().fields) {
|
|
270
|
+
mutationField.allow(...Array.from(this._allowedMutationRoles)).deny(...Array.from(this._deniedMutationRoles));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
276
273
|
// Finalize types
|
|
277
274
|
const finalizeContext = new Builder_1.FinalizeContext(this, resolvedRootSchema);
|
|
278
275
|
for (let objectType of this.getObjectTypes()) {
|
|
@@ -322,14 +319,14 @@ class AbstractSchemaBuilder {
|
|
|
322
319
|
const builtSchema = await subSchema.buildSchema(resolvedTypes, resolvedRootSchema);
|
|
323
320
|
builtSubSchemas.push(builtSchema);
|
|
324
321
|
}
|
|
325
|
-
const mergedSchema =
|
|
322
|
+
const mergedSchema = schema_1.mergeSchemas({
|
|
326
323
|
schemas: [fullSchema, ...builtSubSchemas]
|
|
327
324
|
});
|
|
328
325
|
this._executePluginsSync('afterBuildSchema', plugin => plugin.afterBuildSchema(this, mergedSchema));
|
|
329
326
|
return mergedSchema;
|
|
330
327
|
}
|
|
331
328
|
get compiledResolvers() {
|
|
332
|
-
let resolvers = this._resolvers ?
|
|
329
|
+
let resolvers = this._resolvers ? lodash_1.clone(this._resolvers) : {};
|
|
333
330
|
if (this._queryResolvers) {
|
|
334
331
|
resolvers['Query'] = util_1.ensureInstantiated(this._queryResolvers);
|
|
335
332
|
}
|
package/unionType.js
CHANGED
|
@@ -18,14 +18,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
22
|
exports.unionType = exports.UnionTypeBuilder = void 0;
|
|
26
23
|
const definition_1 = require("graphql/type/definition");
|
|
27
|
-
const
|
|
28
|
-
const clone_1 = __importDefault(require("lodash/clone"));
|
|
24
|
+
const lodash_1 = require("lodash");
|
|
29
25
|
const Builder_1 = __importStar(require("./Builder"));
|
|
30
26
|
class UnionTypeBuilder extends Builder_1.default {
|
|
31
27
|
constructor(name, types = null) {
|
|
@@ -53,7 +49,8 @@ class UnionTypeBuilder extends Builder_1.default {
|
|
|
53
49
|
}
|
|
54
50
|
async finalizeUnionType(context, info) { }
|
|
55
51
|
build(context) {
|
|
56
|
-
|
|
52
|
+
const info = this.info();
|
|
53
|
+
this._executePluginsSync('beforeBuildUnionType', plugin => plugin.beforeBuildUnionType(this, context, info));
|
|
57
54
|
// Resolve types
|
|
58
55
|
const unionType = new definition_1.GraphQLUnionType({
|
|
59
56
|
name: this.name,
|
|
@@ -61,7 +58,7 @@ class UnionTypeBuilder extends Builder_1.default {
|
|
|
61
58
|
types: () => {
|
|
62
59
|
let resolvedTypes = [];
|
|
63
60
|
for (let type of this._types) {
|
|
64
|
-
if (
|
|
61
|
+
if (lodash_1.isString(type)) {
|
|
65
62
|
const resolved = context.getType(type);
|
|
66
63
|
resolvedTypes.push(resolved);
|
|
67
64
|
}
|
|
@@ -73,7 +70,7 @@ class UnionTypeBuilder extends Builder_1.default {
|
|
|
73
70
|
},
|
|
74
71
|
extensions: Object.assign({ [Builder_1.builderInfoExtensionName]: this.info() }, Object.fromEntries(this._extensions))
|
|
75
72
|
});
|
|
76
|
-
this._executePluginsSync('afterBuildUnionType', plugin => plugin.afterBuildUnionType(this, context, unionType));
|
|
73
|
+
this._executePluginsSync('afterBuildUnionType', plugin => plugin.afterBuildUnionType(this, context, info, unionType));
|
|
77
74
|
return unionType;
|
|
78
75
|
}
|
|
79
76
|
info() {
|
|
@@ -82,7 +79,7 @@ class UnionTypeBuilder extends Builder_1.default {
|
|
|
82
79
|
types: new Set(this._types),
|
|
83
80
|
description: this._description,
|
|
84
81
|
extensions: new Map(this._extensions),
|
|
85
|
-
plugins:
|
|
82
|
+
plugins: lodash_1.clone(this._plugins)
|
|
86
83
|
};
|
|
87
84
|
}
|
|
88
85
|
}
|
package/util.d.ts
CHANGED
|
@@ -8,9 +8,16 @@ export interface BuilderArgs<T> {
|
|
|
8
8
|
name: string;
|
|
9
9
|
configurator: Configurator<T>;
|
|
10
10
|
}
|
|
11
|
+
export interface ResolvedType {
|
|
12
|
+
type: string | any;
|
|
13
|
+
nonNull: boolean;
|
|
14
|
+
list: boolean;
|
|
15
|
+
nonNullList: boolean;
|
|
16
|
+
}
|
|
11
17
|
export declare function resolveAutoBuilderArgs<T>(builderOrConfiguratorOrName: BuilderOrConfiguratorOrName<T>, configuratorArg: Configurator<T>, builderType: any): BuilderArgs<T>;
|
|
12
18
|
export declare function resolveBuilderArgs<T>(builderOrName: T | string, configuratorArg: Configurator<T>, builderType: any): BuilderArgs<T>;
|
|
13
19
|
export declare function resolveBuilder<V>(args: BuilderArgs<V>, defaultBuilderGenerator: (name?: string) => V): V;
|
|
20
|
+
export declare function resolveType(type: string | any): ResolvedType;
|
|
14
21
|
export declare function isTypeInput(type: FieldType, schema: AbstractSchemaBuilder<any>): boolean;
|
|
15
22
|
export declare function isTypeScalar(type: FieldType, schema: AbstractSchemaBuilder<any>): boolean;
|
|
16
23
|
export declare function isFieldId(info: FieldBuilderInfo): boolean;
|
package/util.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.camelize = exports.ensureInstantiated = exports.isFieldId = exports.isTypeScalar = exports.isTypeInput = exports.resolveBuilder = exports.resolveBuilderArgs = exports.resolveAutoBuilderArgs = exports.defaultScalarNames = void 0;
|
|
7
|
-
const
|
|
8
|
-
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
3
|
+
exports.camelize = exports.ensureInstantiated = exports.isFieldId = exports.isTypeScalar = exports.isTypeInput = exports.resolveType = exports.resolveBuilder = exports.resolveBuilderArgs = exports.resolveAutoBuilderArgs = exports.defaultScalarNames = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
9
5
|
const graphql_1 = require("graphql");
|
|
10
6
|
const definition_1 = require("graphql/type/definition");
|
|
11
7
|
const enumType_1 = require("./enumType");
|
|
@@ -19,7 +15,7 @@ function resolveAutoBuilderArgs(builderOrConfiguratorOrName, configuratorArg, bu
|
|
|
19
15
|
builder = builderOrConfiguratorOrName;
|
|
20
16
|
configurator = configuratorArg;
|
|
21
17
|
}
|
|
22
|
-
else if (
|
|
18
|
+
else if (lodash_1.isString(builderOrConfiguratorOrName)) {
|
|
23
19
|
name = builderOrConfiguratorOrName;
|
|
24
20
|
configurator = configuratorArg;
|
|
25
21
|
}
|
|
@@ -39,7 +35,7 @@ function resolveBuilderArgs(builderOrName, configuratorArg, builderType) {
|
|
|
39
35
|
builder = builderOrName;
|
|
40
36
|
configurator = configuratorArg;
|
|
41
37
|
}
|
|
42
|
-
else if (
|
|
38
|
+
else if (lodash_1.isString(builderOrName)) {
|
|
43
39
|
name = builderOrName;
|
|
44
40
|
configurator = configuratorArg;
|
|
45
41
|
}
|
|
@@ -59,8 +55,23 @@ function resolveBuilder(args, defaultBuilderGenerator) {
|
|
|
59
55
|
return resolvedBuilder;
|
|
60
56
|
}
|
|
61
57
|
exports.resolveBuilder = resolveBuilder;
|
|
58
|
+
const nonNullTypePattern = /(.+)!$/;
|
|
59
|
+
const nonNullListTypePattern = /\[(.+)!]/;
|
|
60
|
+
const listTypePattern = /\[(.+)]/;
|
|
61
|
+
const baseTypePattern = /\[?(\w+)]?!?/;
|
|
62
|
+
function resolveType(type) {
|
|
63
|
+
if (!lodash_1.isString(type)) {
|
|
64
|
+
return { type, nonNull: false, nonNullList: false, list: false };
|
|
65
|
+
}
|
|
66
|
+
const nonNull = nonNullTypePattern.test(type);
|
|
67
|
+
const nonNullList = nonNullListTypePattern.test(type);
|
|
68
|
+
const list = listTypePattern.test(type);
|
|
69
|
+
const baseMatches = baseTypePattern.exec(type);
|
|
70
|
+
return { nonNull, list, nonNullList, type: baseMatches[1] };
|
|
71
|
+
}
|
|
72
|
+
exports.resolveType = resolveType;
|
|
62
73
|
function isTypeInput(type, schema) {
|
|
63
|
-
if (
|
|
74
|
+
if (lodash_1.isString(type)) {
|
|
64
75
|
const typeName = type;
|
|
65
76
|
if (exports.defaultScalarNames.indexOf(typeName) >= 0) {
|
|
66
77
|
return true;
|
|
@@ -79,7 +90,7 @@ function isTypeInput(type, schema) {
|
|
|
79
90
|
}
|
|
80
91
|
exports.isTypeInput = isTypeInput;
|
|
81
92
|
function isTypeScalar(type, schema) {
|
|
82
|
-
if (
|
|
93
|
+
if (lodash_1.isString(type)) {
|
|
83
94
|
const typeName = type;
|
|
84
95
|
if (exports.defaultScalarNames.indexOf(typeName) >= 0) {
|
|
85
96
|
return true;
|
|
@@ -102,7 +113,7 @@ function isFieldId(info) {
|
|
|
102
113
|
}
|
|
103
114
|
exports.isFieldId = isFieldId;
|
|
104
115
|
function ensureInstantiated(input, ...args) {
|
|
105
|
-
if (
|
|
116
|
+
if (lodash_1.isFunction(input)) {
|
|
106
117
|
try {
|
|
107
118
|
let inputClass = input;
|
|
108
119
|
return new inputClass(...args);
|
package/plugin/acl/plugin.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SchemaBuilder } from "../../schema";
|
|
2
|
-
import { AbstractAcl, AclOptions } from "./Acl";
|
|
3
|
-
import { AclMiddlewareOptions } from "./middleware";
|
|
4
|
-
import { Plugin } from "../common";
|
|
5
|
-
export interface AclPluginOptions extends AclMiddlewareOptions, AclOptions {
|
|
6
|
-
}
|
|
7
|
-
export declare class AclPlugin extends AbstractAcl<AclPluginOptions> implements Plugin {
|
|
8
|
-
constructor(options?: AclPluginOptions);
|
|
9
|
-
rolePath(path: string): this;
|
|
10
|
-
onForbidden(handler: (resource: string) => void): this;
|
|
11
|
-
beforeBuildSchema(builder: SchemaBuilder): void;
|
|
12
|
-
protected addRules(resource: string, allowed: Set<string>, denied: Set<string>): void;
|
|
13
|
-
}
|
|
14
|
-
export declare function aclPlugin(options?: AclPluginOptions): AclPlugin;
|
|
15
|
-
export default aclPlugin;
|
package/plugin/acl/plugin.js
DELETED
|
@@ -1,50 +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.AclPlugin = void 0;
|
|
7
|
-
const defaults_1 = __importDefault(require("lodash/defaults"));
|
|
8
|
-
const Acl_1 = require("./Acl");
|
|
9
|
-
const middleware_1 = require("./middleware");
|
|
10
|
-
class AclPlugin extends Acl_1.AbstractAcl {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
super();
|
|
13
|
-
this._options = defaults_1.default(options || {}, middleware_1.defaultAclMiddlewareOptions, Acl_1.defaultAclOptions);
|
|
14
|
-
}
|
|
15
|
-
rolePath(path) {
|
|
16
|
-
this._options.rolePath = path;
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
onForbidden(handler) {
|
|
20
|
-
this._options.onForbidden = handler;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
beforeBuildSchema(builder) {
|
|
24
|
-
// Add middleware
|
|
25
|
-
builder.use(middleware_1.graphQLAclMiddleware(this, null, this._options));
|
|
26
|
-
// Add rules
|
|
27
|
-
for (let type of builder.getObjectTypes()) {
|
|
28
|
-
const typeInfo = type.info();
|
|
29
|
-
this.addRules(`${type.name}.*`, typeInfo.allowedRoles, typeInfo.deniedRoles);
|
|
30
|
-
for (let field of type.info().fields) {
|
|
31
|
-
const fieldInfo = field.info();
|
|
32
|
-
this.addRules(`${type.name}.${field.name}`, fieldInfo.allowedRoles, fieldInfo.deniedRoles);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
addRules(resource, allowed, denied) {
|
|
37
|
-
if (allowed.size > 0) {
|
|
38
|
-
this.allow(resource, Array.from(allowed));
|
|
39
|
-
}
|
|
40
|
-
if (denied.size > 0) {
|
|
41
|
-
this.deny(resource, Array.from(denied));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.AclPlugin = AclPlugin;
|
|
46
|
-
function aclPlugin(options) {
|
|
47
|
-
return new AclPlugin(options);
|
|
48
|
-
}
|
|
49
|
-
exports.aclPlugin = aclPlugin;
|
|
50
|
-
exports.default = aclPlugin;
|