@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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.cjs +2250 -0
  3. package/dist/index.js +2118 -35
  4. package/dist/{Builder.d.ts → types/Builder.d.ts} +5 -5
  5. package/dist/{argument.d.ts → types/argument.d.ts} +3 -3
  6. package/dist/{common.d.ts → types/common.d.ts} +2 -2
  7. package/dist/{entity → types/entity}/createInputObjectType.d.ts +3 -3
  8. package/dist/{entity → types/entity}/entitySchema.d.ts +4 -4
  9. package/dist/{entity → types/entity}/updateInputObjectType.d.ts +3 -3
  10. package/dist/{enumType.d.ts → types/enumType.d.ts} +3 -3
  11. package/dist/{enumValue.d.ts → types/enumValue.d.ts} +3 -3
  12. package/dist/{field.d.ts → types/field.d.ts} +7 -7
  13. package/dist/{inputField.d.ts → types/inputField.d.ts} +3 -3
  14. package/dist/{inputObjectType.d.ts → types/inputObjectType.d.ts} +5 -5
  15. package/dist/{naming → types/naming}/common.d.ts +1 -2
  16. package/dist/{naming → types/naming}/compact.d.ts +1 -1
  17. package/dist/{naming → types/naming}/descriptive.d.ts +1 -1
  18. package/dist/{objectType.d.ts → types/objectType.d.ts} +4 -4
  19. package/dist/{plugin → types/plugin}/MultiPlugin.d.ts +14 -14
  20. package/dist/{plugin → types/plugin}/acl/acl.d.ts +5 -5
  21. package/dist/{plugin → types/plugin}/acl/middleware.d.ts +4 -4
  22. package/dist/{plugin → types/plugin}/common.d.ts +13 -13
  23. package/dist/{plugin → types/plugin}/filter/equals.d.ts +5 -5
  24. package/dist/{plugin → types/plugin}/filter/search.d.ts +3 -3
  25. package/dist/{plugin → types/plugin}/pagination/connection.d.ts +3 -3
  26. package/dist/{plugin → types/plugin}/pagination/firstAfter.d.ts +3 -3
  27. package/dist/{plugin → types/plugin}/pagination/items.d.ts +3 -3
  28. package/dist/{plugin → types/plugin}/pagination/offsetLimit.d.ts +3 -3
  29. package/dist/{plugin → types/plugin}/pagination/simple.d.ts +1 -1
  30. package/dist/{plugin → types/plugin}/sort/sort.d.ts +5 -5
  31. package/dist/{schema.d.ts → types/schema.d.ts} +9 -9
  32. package/dist/{unionType.d.ts → types/unionType.d.ts} +3 -3
  33. package/dist/{util.d.ts → types/util.d.ts} +4 -4
  34. package/package.json +43 -34
  35. package/dist/Builder.js +0 -113
  36. package/dist/argument.js +0 -100
  37. package/dist/common.js +0 -2
  38. package/dist/entity/createInputObjectType.js +0 -55
  39. package/dist/entity/entitySchema.js +0 -212
  40. package/dist/entity/index.js +0 -24
  41. package/dist/entity/updateInputObjectType.js +0 -55
  42. package/dist/enumType.js +0 -126
  43. package/dist/enumValue.js +0 -60
  44. package/dist/error/FrameworkError.js +0 -12
  45. package/dist/error/index.js +0 -18
  46. package/dist/error/resolver/DataError.js +0 -11
  47. package/dist/error/resolver/ForbiddenError.js +0 -11
  48. package/dist/error/resolver/InvalidInputError.js +0 -11
  49. package/dist/error/resolver/NotFoundError.js +0 -11
  50. package/dist/error/resolver/ResolverError.js +0 -11
  51. package/dist/error/resolver/index.js +0 -21
  52. package/dist/field.js +0 -193
  53. package/dist/inputField.js +0 -100
  54. package/dist/inputObjectType.js +0 -119
  55. package/dist/naming/common.js +0 -2
  56. package/dist/naming/compact.js +0 -54
  57. package/dist/naming/descriptive.js +0 -54
  58. package/dist/naming/index.js +0 -20
  59. package/dist/naming/util.js +0 -22
  60. package/dist/objectType.js +0 -140
  61. package/dist/plugin/MultiPlugin.js +0 -147
  62. package/dist/plugin/PluginError.js +0 -11
  63. package/dist/plugin/acl/acl.js +0 -205
  64. package/dist/plugin/acl/index.js +0 -18
  65. package/dist/plugin/acl/middleware.js +0 -48
  66. package/dist/plugin/common.js +0 -2
  67. package/dist/plugin/filter/equals.js +0 -124
  68. package/dist/plugin/filter/index.js +0 -18
  69. package/dist/plugin/filter/search.js +0 -24
  70. package/dist/plugin/index.js +0 -23
  71. package/dist/plugin/pagination/connection.js +0 -115
  72. package/dist/plugin/pagination/firstAfter.js +0 -19
  73. package/dist/plugin/pagination/index.js +0 -22
  74. package/dist/plugin/pagination/items.js +0 -78
  75. package/dist/plugin/pagination/offsetLimit.js +0 -19
  76. package/dist/plugin/pagination/relay.js +0 -26
  77. package/dist/plugin/pagination/simple.js +0 -20
  78. package/dist/plugin/sort/index.js +0 -22
  79. package/dist/plugin/sort/sort.js +0 -151
  80. package/dist/schema.js +0 -380
  81. package/dist/unionType.js +0 -75
  82. package/dist/util.js +0 -142
  83. /package/dist/{entity → types/entity}/index.d.ts +0 -0
  84. /package/dist/{error → types/error}/FrameworkError.d.ts +0 -0
  85. /package/dist/{error → types/error}/index.d.ts +0 -0
  86. /package/dist/{error → types/error}/resolver/DataError.d.ts +0 -0
  87. /package/dist/{error → types/error}/resolver/ForbiddenError.d.ts +0 -0
  88. /package/dist/{error → types/error}/resolver/InvalidInputError.d.ts +0 -0
  89. /package/dist/{error → types/error}/resolver/NotFoundError.d.ts +0 -0
  90. /package/dist/{error → types/error}/resolver/ResolverError.d.ts +0 -0
  91. /package/dist/{error → types/error}/resolver/index.d.ts +0 -0
  92. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  93. /package/dist/{naming → types/naming}/index.d.ts +0 -0
  94. /package/dist/{naming → types/naming}/util.d.ts +0 -0
  95. /package/dist/{plugin → types/plugin}/PluginError.d.ts +0 -0
  96. /package/dist/{plugin → types/plugin}/acl/index.d.ts +0 -0
  97. /package/dist/{plugin → types/plugin}/filter/index.d.ts +0 -0
  98. /package/dist/{plugin → types/plugin}/index.d.ts +0 -0
  99. /package/dist/{plugin → types/plugin}/pagination/index.d.ts +0 -0
  100. /package/dist/{plugin → types/plugin}/pagination/relay.d.ts +0 -0
  101. /package/dist/{plugin → types/plugin}/sort/index.d.ts +0 -0
package/dist/enumType.js DELETED
@@ -1,126 +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
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.EnumTypeBuilder = void 0;
37
- exports.enumType = enumType;
38
- const lodash_1 = require("lodash");
39
- const definition_1 = require("graphql/type/definition");
40
- const Builder_1 = __importStar(require("./Builder"));
41
- const enumValue_1 = require("./enumValue");
42
- class EnumTypeBuilder extends Builder_1.default {
43
- constructor(name, valuesObject = null) {
44
- super(name);
45
- this._values = [];
46
- this._extensions = new Map();
47
- if (valuesObject) {
48
- this.valuesObject(valuesObject);
49
- }
50
- }
51
- description(description) {
52
- this._description = description;
53
- return this;
54
- }
55
- extension(name, value) {
56
- this._extensions.set(name, value);
57
- return this;
58
- }
59
- value(builderOrName, value = null, configurator = null) {
60
- let valueBuilder = null;
61
- if (builderOrName instanceof enumValue_1.EnumValueBuilder) {
62
- valueBuilder = builderOrName;
63
- }
64
- else if ((0, lodash_1.isString)(builderOrName)) {
65
- valueBuilder = new enumValue_1.EnumValueBuilder(builderOrName, value);
66
- if (configurator) {
67
- configurator(valueBuilder);
68
- }
69
- }
70
- else {
71
- throw new Builder_1.BuilderError('Invalid value provided', builderOrName);
72
- }
73
- this._values.push(valueBuilder);
74
- return this;
75
- }
76
- valuesObject(object) {
77
- const keys = Object.keys(object).filter(key => isNaN(parseInt(key)));
78
- for (let key of keys) {
79
- this.value(key, object[key]);
80
- }
81
- }
82
- async finalizeBuilder(context) {
83
- const info = this.info();
84
- await this._executePlugins('beforeFinalizeEnumType', plugin => plugin.beforeFinalizeEnumType(this, context, info));
85
- await this.finalizeEnumType(context, info);
86
- await this._executePlugins('afterFinalizeEnumType', plugin => plugin.afterFinalizeEnumType(this, context, info));
87
- // Add plugins to values
88
- for (let value of this._values) {
89
- this._plugins.forEach(plugin => value.use(plugin));
90
- }
91
- for (let value of this._values) {
92
- await value.finalize(context);
93
- }
94
- }
95
- async finalizeEnumType(context, info) { }
96
- build(context) {
97
- const info = this.info();
98
- this._executePluginsSync('beforeBuildEnumType', plugin => plugin.beforeBuildEnumType(this, context, info));
99
- let builtValues = {};
100
- for (let value of this._values) {
101
- builtValues[value.name] = value.build(context);
102
- }
103
- const enumType = new definition_1.GraphQLEnumType({
104
- name: this.name,
105
- description: this._description,
106
- values: builtValues,
107
- extensions: Object.assign({}, Object.fromEntries(this._extensions))
108
- });
109
- this._executePluginsSync('afterBuildEnumType', plugin => plugin.afterBuildEnumType(this, context, info, enumType));
110
- return enumType;
111
- }
112
- info() {
113
- return {
114
- name: this.name,
115
- description: this._description,
116
- values: (0, lodash_1.clone)(this._values),
117
- extensions: new Map(this._extensions),
118
- plugins: (0, lodash_1.clone)(this._plugins)
119
- };
120
- }
121
- }
122
- exports.EnumTypeBuilder = EnumTypeBuilder;
123
- function enumType(name, valuesObject = null) {
124
- return new EnumTypeBuilder(name, valuesObject);
125
- }
126
- exports.default = enumType;
package/dist/enumValue.js DELETED
@@ -1,60 +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.EnumValueBuilder = void 0;
7
- exports.enumValue = enumValue;
8
- const lodash_1 = require("lodash");
9
- const Builder_1 = __importDefault(require("./Builder"));
10
- class EnumValueBuilder extends Builder_1.default {
11
- constructor(name, value = null) {
12
- super(name);
13
- this._extensions = new Map();
14
- this._value = value;
15
- }
16
- value(value) {
17
- this._value = value;
18
- return this;
19
- }
20
- description(description) {
21
- this._description = description;
22
- return this;
23
- }
24
- extension(name, value) {
25
- this._extensions.set(name, value);
26
- return this;
27
- }
28
- async finalizeBuilder(context) {
29
- const info = this.info();
30
- await this._executePlugins('beforeFinalizeEnumValue', plugin => plugin.beforeFinalizeEnumValue(this, context, info));
31
- await this.finalizeEnumValue(context, info);
32
- await this._executePlugins('afterFinalizeEnumValue', plugin => plugin.afterFinalizeEnumValue(this, context, info));
33
- }
34
- async finalizeEnumValue(context, info) { }
35
- build(context) {
36
- const info = this.info();
37
- this._executePluginsSync('beforeBuildEnumValue', plugin => plugin.beforeBuildEnumValue(this, context, info));
38
- const enumValue = {
39
- value: this._value,
40
- description: this._description,
41
- extensions: Object.assign({}, Object.fromEntries(this._extensions))
42
- };
43
- this._executePluginsSync('afterBuildEnumValue', plugin => plugin.afterBuildEnumValue(this, context, info, enumValue));
44
- return enumValue;
45
- }
46
- info() {
47
- return {
48
- name: this.name,
49
- value: this._value,
50
- description: this._description,
51
- extensions: new Map(this._extensions),
52
- plugins: (0, lodash_1.clone)(this._plugins)
53
- };
54
- }
55
- }
56
- exports.EnumValueBuilder = EnumValueBuilder;
57
- function enumValue(name, value = null) {
58
- return new EnumValueBuilder(name, value);
59
- }
60
- exports.default = enumValue;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FrameworkError = void 0;
4
- class FrameworkError extends Error {
5
- constructor(message, developerInfo) {
6
- super(message);
7
- this.name = this.constructor.name;
8
- this.developerInfo = developerInfo;
9
- }
10
- }
11
- exports.FrameworkError = FrameworkError;
12
- exports.default = FrameworkError;
@@ -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("./FrameworkError"), exports);
18
- __exportStar(require("./resolver"), exports);
@@ -1,11 +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.DataError = void 0;
7
- const ResolverError_1 = __importDefault(require("./ResolverError"));
8
- class DataError extends ResolverError_1.default {
9
- }
10
- exports.DataError = DataError;
11
- exports.default = DataError;
@@ -1,11 +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.ForbiddenError = void 0;
7
- const ResolverError_1 = __importDefault(require("./ResolverError"));
8
- class ForbiddenError extends ResolverError_1.default {
9
- }
10
- exports.ForbiddenError = ForbiddenError;
11
- exports.default = ForbiddenError;
@@ -1,11 +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.InvalidInputError = void 0;
7
- const ResolverError_1 = __importDefault(require("./ResolverError"));
8
- class InvalidInputError extends ResolverError_1.default {
9
- }
10
- exports.InvalidInputError = InvalidInputError;
11
- exports.default = InvalidInputError;
@@ -1,11 +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.NotFoundError = void 0;
7
- const ResolverError_1 = __importDefault(require("./ResolverError"));
8
- class NotFoundError extends ResolverError_1.default {
9
- }
10
- exports.NotFoundError = NotFoundError;
11
- exports.default = NotFoundError;
@@ -1,11 +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.ResolverError = void 0;
7
- const FrameworkError_1 = __importDefault(require("../FrameworkError"));
8
- class ResolverError extends FrameworkError_1.default {
9
- }
10
- exports.ResolverError = ResolverError;
11
- exports.default = ResolverError;
@@ -1,21 +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("./ForbiddenError"), exports);
18
- __exportStar(require("./InvalidInputError"), exports);
19
- __exportStar(require("./NotFoundError"), exports);
20
- __exportStar(require("./DataError"), exports);
21
- __exportStar(require("./ResolverError"), exports);
package/dist/field.js DELETED
@@ -1,193 +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
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.FieldBuilder = void 0;
37
- exports.field = field;
38
- const lodash_1 = require("lodash");
39
- const graphql_1 = require("graphql");
40
- const argument_1 = require("./argument");
41
- const Builder_1 = __importStar(require("./Builder"));
42
- const util_1 = require("./util");
43
- class FieldBuilder extends Builder_1.default {
44
- constructor(name, type = null) {
45
- super(name);
46
- this._arguments = [];
47
- this._extensions = new Map();
48
- this._nonNull = false;
49
- this._nonNullList = false;
50
- this._list = false;
51
- this._includeDeleted = false;
52
- this._allowedRoles = new Set();
53
- this._deniedRoles = new Set();
54
- this.type(type);
55
- }
56
- type(type) {
57
- const resolvedType = (0, util_1.resolveType)(type);
58
- this._type = resolvedType.type;
59
- if (resolvedType.nonNull)
60
- this.nonNull();
61
- if (resolvedType.list)
62
- this.list();
63
- if (resolvedType.nonNullList)
64
- this.nonNullList();
65
- return this;
66
- }
67
- description(description) {
68
- this._description = description;
69
- return this;
70
- }
71
- extension(name, value) {
72
- this._extensions.set(name, value);
73
- return this;
74
- }
75
- arg(argOrName, type = null, configurator = null) {
76
- let argument = null;
77
- if (argOrName instanceof argument_1.ArgumentBuilder) {
78
- argument = argOrName;
79
- }
80
- else if ((0, lodash_1.isString)(argOrName) && type) {
81
- argument = new argument_1.ArgumentBuilder(argOrName, type);
82
- if (configurator) {
83
- configurator(argument);
84
- }
85
- }
86
- else {
87
- throw new Builder_1.BuilderError('Invalid argument provided', argOrName);
88
- }
89
- this._arguments.push(argument);
90
- return this;
91
- }
92
- nonNull(nonNull = true) {
93
- this._nonNull = nonNull;
94
- return this;
95
- }
96
- list(list = true) {
97
- this._list = list;
98
- return this;
99
- }
100
- nonNullList(nonNullList = true) {
101
- if (nonNullList) {
102
- this.list();
103
- }
104
- this._nonNullList = nonNullList;
105
- return this;
106
- }
107
- resolver(resolver) {
108
- this._resolver = resolver;
109
- return this;
110
- }
111
- allow(...roles) {
112
- roles.forEach(role => this._allowedRoles.add(role));
113
- return this;
114
- }
115
- deny(...roles) {
116
- roles.forEach(role => this._deniedRoles.add(role));
117
- return this;
118
- }
119
- includeDeleted(includeDeleted = true) {
120
- this._includeDeleted = includeDeleted;
121
- return this;
122
- }
123
- async finalizeBuilder(context) {
124
- const info = this.info();
125
- await this._executePlugins('beforeFinalizeField', plugin => plugin.beforeFinalizeField(this, context, info));
126
- await this.finalizeField(context, info);
127
- await this._executePlugins('afterFinalizeField', plugin => plugin.afterFinalizeField(this, context, info));
128
- // Add plugins to arguments
129
- for (let arg of this._arguments) {
130
- this._plugins.forEach(plugin => arg.use(plugin));
131
- }
132
- for (let argument of this._arguments) {
133
- await argument.finalize(context);
134
- }
135
- }
136
- async finalizeField(context, info) { }
137
- build(context, parentBuilder) {
138
- if (!parentBuilder) {
139
- throw new Builder_1.BuilderError('Build: Field needs parent builder argument to be present');
140
- }
141
- const info = this.info();
142
- this._executePluginsSync('beforeBuildField', plugin => plugin.beforeBuildField(this, context, info));
143
- let builtArgs = {};
144
- for (let arg of this._arguments) {
145
- builtArgs[arg.name] = arg.build(context);
146
- }
147
- let type = (0, lodash_1.isString)(this._type) ? context.getType(this._type) : this._type;
148
- if (type === null) {
149
- throw new Builder_1.BuilderError(`Type "${this._type}" of field "${this.name}" not found`);
150
- }
151
- if (this._list) {
152
- if (this._nonNullList) {
153
- type = new graphql_1.GraphQLNonNull(type);
154
- }
155
- type = new graphql_1.GraphQLList(type);
156
- }
157
- if (this._nonNull) {
158
- type = new graphql_1.GraphQLNonNull(type);
159
- }
160
- const resolver = this._resolver || context.getResolver(parentBuilder.name, this.name);
161
- const field = {
162
- type,
163
- description: this._description,
164
- args: builtArgs,
165
- extensions: Object.assign(Object.assign({}, (0, util_1.getAclExtension)(this._allowedRoles, this._deniedRoles)), Object.fromEntries(this._extensions)),
166
- resolve: resolver
167
- };
168
- this._executePluginsSync('afterBuildField', plugin => plugin.afterBuildField(this, context, info, field));
169
- return field;
170
- }
171
- info() {
172
- return {
173
- name: this.name,
174
- type: this._type,
175
- description: this._description,
176
- arguments: (0, lodash_1.clone)(this._arguments),
177
- extensions: new Map(this._extensions),
178
- nonNull: this._nonNull,
179
- nonNullList: this._nonNullList,
180
- list: this._list,
181
- includeDeleted: this._includeDeleted,
182
- allowedRoles: new Set(this._allowedRoles),
183
- deniedRoles: new Set(this._deniedRoles),
184
- resolver: this._resolver,
185
- plugins: (0, lodash_1.clone)(this._plugins)
186
- };
187
- }
188
- }
189
- exports.FieldBuilder = FieldBuilder;
190
- function field(name, type = null) {
191
- return new FieldBuilder(name, type);
192
- }
193
- exports.default = field;
@@ -1,100 +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.InputFieldBuilder = void 0;
7
- exports.inputField = inputField;
8
- const lodash_1 = require("lodash");
9
- const graphql_1 = require("graphql");
10
- const Builder_1 = __importDefault(require("./Builder"));
11
- const util_1 = require("./util");
12
- class InputFieldBuilder extends Builder_1.default {
13
- constructor(name, type) {
14
- super(name);
15
- this._extensions = new Map();
16
- this._nonNull = false;
17
- this._nonNullList = false;
18
- this._list = false;
19
- this.type(type);
20
- }
21
- type(type) {
22
- const resolvedType = (0, util_1.resolveType)(type);
23
- this._type = resolvedType.type;
24
- if (resolvedType.nonNull)
25
- this.nonNull();
26
- if (resolvedType.list)
27
- this.list();
28
- if (resolvedType.nonNullList)
29
- this.nonNullList();
30
- return this;
31
- }
32
- description(description) {
33
- this._description = description;
34
- return this;
35
- }
36
- extension(name, value) {
37
- this._extensions.set(name, value);
38
- return this;
39
- }
40
- nonNull(nonNull = true) {
41
- this._nonNull = nonNull;
42
- return this;
43
- }
44
- list(list = true) {
45
- this._list = list;
46
- return this;
47
- }
48
- nonNullList(nonNullList = true) {
49
- if (nonNullList) {
50
- this.list();
51
- }
52
- this._nonNullList = nonNullList;
53
- return this;
54
- }
55
- async finalizeBuilder(context) {
56
- const info = this.info();
57
- await this._executePlugins('beforeFinalizeInputField', plugin => plugin.beforeFinalizeInputField(this, context, info));
58
- await this.finalizeInputField(context, info);
59
- await this._executePlugins('afterFinalizeInputField', plugin => plugin.afterFinalizeInputField(this, context, info));
60
- }
61
- async finalizeInputField(context, info) { }
62
- build(context) {
63
- const info = this.info();
64
- this._executePluginsSync('beforeBuildInputField', plugin => plugin.beforeBuildInputField(this, context, info));
65
- let type = (0, lodash_1.isString)(this._type) ? context.getType(this._type) : this._type;
66
- if (this._list) {
67
- if (this._nonNullList) {
68
- type = new graphql_1.GraphQLNonNull(type);
69
- }
70
- type = new graphql_1.GraphQLList(type);
71
- }
72
- if (this._nonNull) {
73
- type = new graphql_1.GraphQLNonNull(type);
74
- }
75
- const inputField = {
76
- type,
77
- description: this._description,
78
- extensions: Object.assign({}, Object.fromEntries(this._extensions))
79
- };
80
- this._executePluginsSync('afterBuildInputField', plugin => plugin.afterBuildInputField(this, context, info, inputField));
81
- return inputField;
82
- }
83
- info() {
84
- return {
85
- name: this.name,
86
- type: this._type,
87
- description: this._description,
88
- extensions: new Map(this._extensions),
89
- nonNull: this._nonNull,
90
- nonNullList: this._nonNullList,
91
- list: this._list,
92
- plugins: (0, lodash_1.clone)(this._plugins)
93
- };
94
- }
95
- }
96
- exports.InputFieldBuilder = InputFieldBuilder;
97
- function inputField(name, type) {
98
- return new InputFieldBuilder(name, type);
99
- }
100
- exports.default = inputField;