@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/index.cjs ADDED
@@ -0,0 +1,2250 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ SearchFilterPlugin: ()=>SearchFilterPlugin,
37
+ pluralize: ()=>external_pluralize_default(),
38
+ graphQLAclMiddleware: ()=>graphQLAclMiddleware,
39
+ itemsPaginationPlugin: ()=>itemsPaginationPlugin,
40
+ getAclExtension: ()=>getAclExtension,
41
+ objectType: ()=>objectType_objectType,
42
+ defaultAclMiddlewareOptions: ()=>defaultAclMiddlewareOptions,
43
+ offsetLimitPaginationPlugin: ()=>offsetLimitPaginationPlugin,
44
+ ObjectTypeBuilder: ()=>ObjectTypeBuilder,
45
+ DataError: ()=>DataError_DataError,
46
+ resolveName: ()=>resolveName,
47
+ searchFilterPlugin: ()=>searchFilterPlugin,
48
+ ItemsPaginationPlugin: ()=>ItemsPaginationPlugin,
49
+ FieldBuilder: ()=>FieldBuilder,
50
+ NotFoundError: ()=>NotFoundError,
51
+ UpdateInputObjectTypeBuilder: ()=>UpdateInputObjectTypeBuilder,
52
+ InvalidInputError: ()=>InvalidInputError,
53
+ CompactNamingStrategy: ()=>CompactNamingStrategy,
54
+ createInputObjectType: ()=>createInputObjectType,
55
+ defaultEqualsFilterPluginOptions: ()=>defaultEqualsFilterPluginOptions,
56
+ getPathResource: ()=>getPathResource,
57
+ AbstractEntitySchemaBuilder: ()=>AbstractEntitySchemaBuilder,
58
+ isTypeInput: ()=>isTypeInput,
59
+ resolveAutoBuilderArgs: ()=>resolveAutoBuilderArgs,
60
+ PluginError: ()=>PluginError_PluginError,
61
+ unionType: ()=>unionType_unionType,
62
+ SortPlugin: ()=>SortPlugin,
63
+ resolveBuilderArgs: ()=>resolveBuilderArgs,
64
+ RelayPaginationPlugin: ()=>RelayPaginationPlugin,
65
+ BuildContext: ()=>BuildContext,
66
+ resolveType: ()=>resolveType,
67
+ FinalizeContext: ()=>FinalizeContext,
68
+ enumType: ()=>enumType_enumType,
69
+ inputObjectType: ()=>inputObjectType_inputObjectType,
70
+ SchemaBuilder: ()=>SchemaBuilder,
71
+ DescriptiveNamingStrategy: ()=>DescriptiveNamingStrategy,
72
+ lcFirst: ()=>lcFirst,
73
+ descriptiveNamingStrategy: ()=>descriptiveNamingStrategy,
74
+ relayPaginationPlugin: ()=>relayPaginationPlugin,
75
+ defaultSearchFilterPluginOptions: ()=>defaultSearchFilterPluginOptions,
76
+ sortPlugin: ()=>sortPlugin,
77
+ ConnectionPaginationPlugin: ()=>ConnectionPaginationPlugin,
78
+ EnumTypeBuilder: ()=>EnumTypeBuilder,
79
+ ensureInstantiated: ()=>ensureInstantiated,
80
+ camelize: ()=>camelize,
81
+ EntitySchemaBuilder: ()=>EntitySchemaBuilder,
82
+ enumValue: ()=>enumValue_enumValue,
83
+ isFieldId: ()=>isFieldId,
84
+ updateInputObjectType: ()=>updateInputObjectType_updateInputObjectType,
85
+ EntityFieldType: ()=>entitySchema_EntityFieldType,
86
+ equalsFilterPlugin: ()=>equalsFilterPlugin,
87
+ ucFirst: ()=>ucFirst,
88
+ BuilderError: ()=>BuilderError,
89
+ EqualsFilterPlugin: ()=>EqualsFilterPlugin,
90
+ InputObjectTypeBuilder: ()=>InputObjectTypeBuilder,
91
+ SimplePaginationPlugin: ()=>SimplePaginationPlugin,
92
+ argument: ()=>argument_argument,
93
+ aclPlugin: ()=>aclPlugin,
94
+ EnumValueBuilder: ()=>EnumValueBuilder,
95
+ entitySchema: ()=>entitySchema_entitySchema,
96
+ schema: ()=>schema_schema,
97
+ ForbiddenError: ()=>ForbiddenError_ForbiddenError,
98
+ AbstractEntitySchemaBuilderBase: ()=>AbstractEntitySchemaBuilderBase,
99
+ connectionPaginationPlugin: ()=>connectionPaginationPlugin,
100
+ compactNamingStrategy: ()=>compactNamingStrategy,
101
+ SortDirection: ()=>sort_SortDirection,
102
+ defaultAclOptions: ()=>defaultAclOptions,
103
+ isTypeScalar: ()=>isTypeScalar,
104
+ AclPlugin: ()=>AclPlugin,
105
+ default: ()=>ts_rslib_entry_,
106
+ firstAfterPaginationPlugin: ()=>firstAfterPaginationPlugin,
107
+ inputField: ()=>inputField_inputField,
108
+ defaultScalarNames: ()=>defaultScalarNames,
109
+ ResolverError: ()=>ResolverError,
110
+ ArgumentBuilder: ()=>ArgumentBuilder,
111
+ resolveBuilder: ()=>resolveBuilder,
112
+ CreateInputObjectTypeBuilder: ()=>CreateInputObjectTypeBuilder,
113
+ InputFieldBuilder: ()=>InputFieldBuilder,
114
+ AbstractSchemaBuilder: ()=>AbstractSchemaBuilder,
115
+ OffsetLimitPaginationPlugin: ()=>OffsetLimitPaginationPlugin,
116
+ FrameworkError: ()=>FrameworkError,
117
+ UnionTypeBuilder: ()=>UnionTypeBuilder,
118
+ honoAclMiddleware: ()=>honoAclMiddleware,
119
+ MultiPlugin: ()=>MultiPlugin,
120
+ AclAction: ()=>acl_AclAction,
121
+ FirstAfterPaginationPlugin: ()=>FirstAfterPaginationPlugin,
122
+ entityFieldTypeExtensionName: ()=>entityFieldTypeExtensionName,
123
+ defaultSortPluginOptions: ()=>defaultSortPluginOptions,
124
+ field: ()=>field_field,
125
+ simplePaginationPlugin: ()=>simplePaginationPlugin
126
+ });
127
+ const compat_namespaceObject = require("es-toolkit/compat");
128
+ const schema_namespaceObject = require("@graphql-tools/schema");
129
+ const external_graphql_middleware_namespaceObject = require("graphql-middleware");
130
+ const external_graphql_namespaceObject = require("graphql");
131
+ class FrameworkError extends Error {
132
+ constructor(message, developerInfo){
133
+ super(message);
134
+ this.name = this.constructor.name;
135
+ this.developerInfo = developerInfo;
136
+ }
137
+ }
138
+ const error_FrameworkError = FrameworkError;
139
+ class BuilderError extends error_FrameworkError {
140
+ }
141
+ class Builder {
142
+ use(...plugins) {
143
+ plugins.forEach((plugin)=>this._plugins.push(plugin));
144
+ return this;
145
+ }
146
+ async _executePlugins(methodName, fn) {
147
+ for (const plugin of this._plugins)if (plugin[methodName]) await fn(plugin);
148
+ }
149
+ _executePluginsSync(methodName, fn) {
150
+ for (const plugin of this._plugins)if (plugin[methodName]) fn(plugin);
151
+ }
152
+ get name() {
153
+ return resolveName(this._name);
154
+ }
155
+ async finalize(context) {
156
+ if (this._finalized) return;
157
+ await this.finalizeBuilder(context);
158
+ this._finalized = true;
159
+ }
160
+ constructor(name = null){
161
+ this._plugins = [];
162
+ this._finalized = false;
163
+ this._name = name;
164
+ }
165
+ }
166
+ class BuildContext {
167
+ getType(name) {
168
+ if (this.resolvedTypes.has(name)) return this.resolvedTypes.get(name);
169
+ const typeResult = this.schema.locateType(name, false) ?? this.rootSchema.locateType(name, true);
170
+ if (!typeResult) return null;
171
+ const { type, schema } = typeResult;
172
+ let resolvedType = null;
173
+ if (type instanceof Builder) {
174
+ let context = this;
175
+ if (schema != this.schema) context = new BuildContext(schema, this.rootSchema, this.resolvedTypes);
176
+ resolvedType = type.build(context);
177
+ } else if (type instanceof external_graphql_namespaceObject.GraphQLScalarType) resolvedType = type;
178
+ if (!resolvedType) throw new BuilderError(`Type ${name} not found`);
179
+ this.resolvedTypes.set(name, resolvedType);
180
+ return resolvedType;
181
+ }
182
+ getResolver(typeName, fieldName) {
183
+ return this.schema.findResolver(typeName, fieldName);
184
+ }
185
+ constructor(schema, rootSchema, resolvedTypes){
186
+ this.schema = schema;
187
+ this.rootSchema = rootSchema;
188
+ this.resolvedTypes = resolvedTypes;
189
+ }
190
+ }
191
+ class FinalizeContext {
192
+ async getType(name) {
193
+ const typeResult = this.schema.locateType(name, false) ?? this.rootSchema.locateType(name, true);
194
+ if (!typeResult) return null;
195
+ const { type, schema } = typeResult;
196
+ if (type instanceof Builder) {
197
+ let context = this;
198
+ if (schema != this.schema) context = new FinalizeContext(schema, this.rootSchema);
199
+ await type.finalize(context);
200
+ }
201
+ return type;
202
+ }
203
+ constructor(schema, rootSchema){
204
+ this.schema = schema;
205
+ this.rootSchema = rootSchema;
206
+ }
207
+ }
208
+ function resolveName(name) {
209
+ return (0, compat_namespaceObject.isFunction)(name) ? name() : name;
210
+ }
211
+ const definition_namespaceObject = require("graphql/type/definition");
212
+ class EnumValueBuilder extends Builder {
213
+ value(value) {
214
+ this._value = value;
215
+ return this;
216
+ }
217
+ description(description) {
218
+ this._description = description;
219
+ return this;
220
+ }
221
+ extension(name, value) {
222
+ this._extensions.set(name, value);
223
+ return this;
224
+ }
225
+ async finalizeBuilder(context) {
226
+ const info = this.info();
227
+ await this._executePlugins('beforeFinalizeEnumValue', (plugin)=>plugin.beforeFinalizeEnumValue(this, context, info));
228
+ await this.finalizeEnumValue(context, info);
229
+ await this._executePlugins('afterFinalizeEnumValue', (plugin)=>plugin.afterFinalizeEnumValue(this, context, info));
230
+ }
231
+ async finalizeEnumValue(context, info) {}
232
+ build(context) {
233
+ const info = this.info();
234
+ this._executePluginsSync('beforeBuildEnumValue', (plugin)=>plugin.beforeBuildEnumValue(this, context, info));
235
+ const enumValue = {
236
+ value: this._value,
237
+ description: this._description,
238
+ extensions: {
239
+ ...Object.fromEntries(this._extensions)
240
+ }
241
+ };
242
+ this._executePluginsSync('afterBuildEnumValue', (plugin)=>plugin.afterBuildEnumValue(this, context, info, enumValue));
243
+ return enumValue;
244
+ }
245
+ info() {
246
+ return {
247
+ name: this.name,
248
+ value: this._value,
249
+ description: this._description,
250
+ extensions: new Map(this._extensions),
251
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
252
+ };
253
+ }
254
+ constructor(name, value = null){
255
+ super(name), this._extensions = new Map();
256
+ this._value = value;
257
+ }
258
+ }
259
+ function enumValue_enumValue(name, value = null) {
260
+ return new EnumValueBuilder(name, value);
261
+ }
262
+ class EnumTypeBuilder extends Builder {
263
+ description(description) {
264
+ this._description = description;
265
+ return this;
266
+ }
267
+ extension(name, value) {
268
+ this._extensions.set(name, value);
269
+ return this;
270
+ }
271
+ value(builderOrName, value = null, configurator = null) {
272
+ let valueBuilder = null;
273
+ if (builderOrName instanceof EnumValueBuilder) valueBuilder = builderOrName;
274
+ else if ((0, compat_namespaceObject.isString)(builderOrName)) {
275
+ valueBuilder = new EnumValueBuilder(builderOrName, value);
276
+ if (configurator) configurator(valueBuilder);
277
+ } else throw new BuilderError('Invalid value provided', builderOrName);
278
+ this._values.push(valueBuilder);
279
+ return this;
280
+ }
281
+ valuesObject(object) {
282
+ const keys = Object.keys(object).filter((key)=>isNaN(Number.parseInt(key)));
283
+ for (const key of keys)this.value(key, object[key]);
284
+ }
285
+ async finalizeBuilder(context) {
286
+ const info = this.info();
287
+ await this._executePlugins('beforeFinalizeEnumType', (plugin)=>plugin.beforeFinalizeEnumType(this, context, info));
288
+ await this.finalizeEnumType(context, info);
289
+ await this._executePlugins('afterFinalizeEnumType', (plugin)=>plugin.afterFinalizeEnumType(this, context, info));
290
+ for (const value of this._values)this._plugins.forEach((plugin)=>value.use(plugin));
291
+ for (const value of this._values)await value.finalize(context);
292
+ }
293
+ async finalizeEnumType(context, info) {}
294
+ build(context) {
295
+ const info = this.info();
296
+ this._executePluginsSync('beforeBuildEnumType', (plugin)=>plugin.beforeBuildEnumType(this, context, info));
297
+ const builtValues = {};
298
+ for (const value of this._values)builtValues[value.name] = value.build(context);
299
+ const enumType = new definition_namespaceObject.GraphQLEnumType({
300
+ name: this.name,
301
+ description: this._description,
302
+ values: builtValues,
303
+ extensions: {
304
+ ...Object.fromEntries(this._extensions)
305
+ }
306
+ });
307
+ this._executePluginsSync('afterBuildEnumType', (plugin)=>plugin.afterBuildEnumType(this, context, info, enumType));
308
+ return enumType;
309
+ }
310
+ info() {
311
+ return {
312
+ name: this.name,
313
+ description: this._description,
314
+ values: (0, compat_namespaceObject.clone)(this._values),
315
+ extensions: new Map(this._extensions),
316
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
317
+ };
318
+ }
319
+ constructor(name, valuesObject = null){
320
+ super(name), this._values = [], this._extensions = new Map();
321
+ if (valuesObject) this.valuesObject(valuesObject);
322
+ }
323
+ }
324
+ function enumType_enumType(name, valuesObject = null) {
325
+ return new EnumTypeBuilder(name, valuesObject);
326
+ }
327
+ const ts_enumType = enumType_enumType;
328
+ class InputFieldBuilder extends Builder {
329
+ type(type) {
330
+ const resolvedType = resolveType(type);
331
+ this._type = resolvedType.type;
332
+ if (resolvedType.nonNull) this.nonNull();
333
+ if (resolvedType.list) this.list();
334
+ if (resolvedType.nonNullList) this.nonNullList();
335
+ return this;
336
+ }
337
+ description(description) {
338
+ this._description = description;
339
+ return this;
340
+ }
341
+ extension(name, value) {
342
+ this._extensions.set(name, value);
343
+ return this;
344
+ }
345
+ nonNull(nonNull = true) {
346
+ this._nonNull = nonNull;
347
+ return this;
348
+ }
349
+ list(list = true) {
350
+ this._list = list;
351
+ return this;
352
+ }
353
+ nonNullList(nonNullList = true) {
354
+ if (nonNullList) this.list();
355
+ this._nonNullList = nonNullList;
356
+ return this;
357
+ }
358
+ async finalizeBuilder(context) {
359
+ const info = this.info();
360
+ await this._executePlugins('beforeFinalizeInputField', (plugin)=>plugin.beforeFinalizeInputField(this, context, info));
361
+ await this.finalizeInputField(context, info);
362
+ await this._executePlugins('afterFinalizeInputField', (plugin)=>plugin.afterFinalizeInputField(this, context, info));
363
+ }
364
+ async finalizeInputField(context, info) {}
365
+ build(context) {
366
+ const info = this.info();
367
+ this._executePluginsSync('beforeBuildInputField', (plugin)=>plugin.beforeBuildInputField(this, context, info));
368
+ let type = (0, compat_namespaceObject.isString)(this._type) ? context.getType(this._type) : this._type;
369
+ if (this._list) {
370
+ if (this._nonNullList) type = new external_graphql_namespaceObject.GraphQLNonNull(type);
371
+ type = new external_graphql_namespaceObject.GraphQLList(type);
372
+ }
373
+ if (this._nonNull) type = new external_graphql_namespaceObject.GraphQLNonNull(type);
374
+ const inputField = {
375
+ type,
376
+ description: this._description,
377
+ extensions: {
378
+ ...Object.fromEntries(this._extensions)
379
+ }
380
+ };
381
+ this._executePluginsSync('afterBuildInputField', (plugin)=>plugin.afterBuildInputField(this, context, info, inputField));
382
+ return inputField;
383
+ }
384
+ info() {
385
+ return {
386
+ name: this.name,
387
+ type: this._type,
388
+ description: this._description,
389
+ extensions: new Map(this._extensions),
390
+ nonNull: this._nonNull,
391
+ nonNullList: this._nonNullList,
392
+ list: this._list,
393
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
394
+ };
395
+ }
396
+ constructor(name, type){
397
+ super(name), this._extensions = new Map(), this._nonNull = false, this._nonNullList = false, this._list = false;
398
+ this.type(type);
399
+ }
400
+ }
401
+ function inputField_inputField(name, type) {
402
+ return new InputFieldBuilder(name, type);
403
+ }
404
+ class InputObjectTypeBuilder extends Builder {
405
+ description(description) {
406
+ this._description = description;
407
+ return this;
408
+ }
409
+ extension(name, value) {
410
+ this._extensions.set(name, value);
411
+ return this;
412
+ }
413
+ field(fieldOrName, type = null, configurator = null) {
414
+ let field = null;
415
+ if (fieldOrName instanceof InputFieldBuilder) field = fieldOrName;
416
+ else if ((0, compat_namespaceObject.isString)(fieldOrName) && type) {
417
+ field = new InputFieldBuilder(fieldOrName, type);
418
+ if (configurator) configurator(field);
419
+ } else throw new BuilderError('Invalid input field provided', fieldOrName);
420
+ this._fields.push(field);
421
+ return this;
422
+ }
423
+ async finalizeBuilder(context) {
424
+ const info = this.info();
425
+ await this._executePlugins('beforeFinalizeInputObjectType', (plugin)=>plugin.beforeFinalizeInputObjectType(this, context, info));
426
+ await this.finalizeInputObjectType(context, info);
427
+ await this._executePlugins('afterFinalizeInputObjectType', (plugin)=>plugin.afterFinalizeInputObjectType(this, context, info));
428
+ for (const field of this._fields)this._plugins.forEach((plugin)=>field.use(plugin));
429
+ for (const field of this._fields)await field.finalize(context);
430
+ }
431
+ async finalizeInputObjectType(context, info) {}
432
+ build(context) {
433
+ const info = this.info();
434
+ this._executePluginsSync('beforeBuildInputObjectType', (plugin)=>plugin.beforeBuildInputObjectType(this, context, info));
435
+ const inputObjectType = new external_graphql_namespaceObject.GraphQLInputObjectType({
436
+ name: this.name,
437
+ description: this._description,
438
+ extensions: {
439
+ ...Object.fromEntries(this._extensions)
440
+ },
441
+ fields: ()=>{
442
+ const builtFields = {};
443
+ for (const field of this._fields)builtFields[field.name] = field.build(context);
444
+ return builtFields;
445
+ }
446
+ });
447
+ this._executePluginsSync('afterBuildInputObjectType', (plugin)=>plugin.afterBuildInputObjectType(this, context, info, inputObjectType));
448
+ return inputObjectType;
449
+ }
450
+ info() {
451
+ return {
452
+ name: this.name,
453
+ description: this._description,
454
+ fields: (0, compat_namespaceObject.clone)(this._fields),
455
+ extensions: new Map(this._extensions),
456
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
457
+ };
458
+ }
459
+ constructor(...args){
460
+ super(...args), this._fields = [], this._extensions = new Map();
461
+ }
462
+ }
463
+ function inputObjectType_inputObjectType(name) {
464
+ return new InputObjectTypeBuilder(name);
465
+ }
466
+ const ts_inputObjectType = inputObjectType_inputObjectType;
467
+ const defaultScalarNames = [
468
+ 'Int',
469
+ 'Float',
470
+ 'String',
471
+ 'Boolean',
472
+ 'ID'
473
+ ];
474
+ function resolveAutoBuilderArgs(builderOrConfiguratorOrName, configuratorArg, builderType) {
475
+ let builder = null;
476
+ let name = null;
477
+ let configurator = null;
478
+ if (builderOrConfiguratorOrName instanceof builderType) {
479
+ builder = builderOrConfiguratorOrName;
480
+ configurator = configuratorArg;
481
+ } else if ((0, compat_namespaceObject.isString)(builderOrConfiguratorOrName)) {
482
+ name = builderOrConfiguratorOrName;
483
+ configurator = configuratorArg;
484
+ } else configurator = builderOrConfiguratorOrName;
485
+ return {
486
+ builder,
487
+ name,
488
+ configurator
489
+ };
490
+ }
491
+ function resolveBuilderArgs(builderOrName, configuratorArg, builderType) {
492
+ let builder = null;
493
+ let name = null;
494
+ let configurator = null;
495
+ if (builderOrName instanceof builderType) {
496
+ builder = builderOrName;
497
+ configurator = configuratorArg;
498
+ } else if ((0, compat_namespaceObject.isString)(builderOrName)) {
499
+ name = builderOrName;
500
+ configurator = configuratorArg;
501
+ }
502
+ return {
503
+ builder,
504
+ name,
505
+ configurator
506
+ };
507
+ }
508
+ function resolveBuilder(args, defaultBuilderGenerator) {
509
+ let resolvedBuilder = args.builder;
510
+ if (!resolvedBuilder) resolvedBuilder = defaultBuilderGenerator(args.name);
511
+ if (args.configurator) args.configurator(resolvedBuilder);
512
+ return resolvedBuilder;
513
+ }
514
+ const nonNullTypePattern = /(.+)!$/;
515
+ const nonNullListTypePattern = /\[(.+)!]/;
516
+ const listTypePattern = /\[(.+)]/;
517
+ const baseTypePattern = /\[?(\w+)]?!?/;
518
+ function resolveType(type) {
519
+ if (!(0, compat_namespaceObject.isString)(type)) return {
520
+ type,
521
+ nonNull: false,
522
+ nonNullList: false,
523
+ list: false
524
+ };
525
+ const nonNull = nonNullTypePattern.test(type);
526
+ const nonNullList = nonNullListTypePattern.test(type);
527
+ const list = listTypePattern.test(type);
528
+ const baseMatches = baseTypePattern.exec(type);
529
+ return {
530
+ nonNull,
531
+ list,
532
+ nonNullList,
533
+ type: baseMatches[1]
534
+ };
535
+ }
536
+ function isTypeInput(type, schema) {
537
+ if ((0, compat_namespaceObject.isString)(type)) {
538
+ const typeName = type;
539
+ if (defaultScalarNames.indexOf(typeName) >= 0) return true;
540
+ {
541
+ const builderType = schema.findType(typeName, true);
542
+ if (builderType && (builderType instanceof EnumTypeBuilder || builderType instanceof external_graphql_namespaceObject.GraphQLScalarType || builderType instanceof InputObjectTypeBuilder)) return true;
543
+ }
544
+ } else if (type instanceof external_graphql_namespaceObject.GraphQLScalarType || type instanceof definition_namespaceObject.GraphQLEnumType) return true;
545
+ return false;
546
+ }
547
+ function isTypeScalar(type, schema) {
548
+ if ((0, compat_namespaceObject.isString)(type)) {
549
+ const typeName = type;
550
+ if (defaultScalarNames.indexOf(typeName) >= 0) return true;
551
+ {
552
+ const builderType = schema.findType(typeName, true);
553
+ if (builderType && builderType instanceof external_graphql_namespaceObject.GraphQLScalarType) return true;
554
+ }
555
+ } else if (type instanceof external_graphql_namespaceObject.GraphQLScalarType) return true;
556
+ return false;
557
+ }
558
+ function isFieldId(info) {
559
+ return 'ID' === info.type && 'id' === info.name;
560
+ }
561
+ function ensureInstantiated(input, ...args) {
562
+ if ((0, compat_namespaceObject.isFunction)(input)) try {
563
+ const inputClass = input;
564
+ return new inputClass(...args);
565
+ } catch {}
566
+ return input;
567
+ }
568
+ function getAclExtension(allowed, denied) {
569
+ return {
570
+ allowedRoles: Array.from(allowed).join(','),
571
+ deniedRoles: Array.from(denied).join(',')
572
+ };
573
+ }
574
+ function camelize(text) {
575
+ return text.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2)=>{
576
+ if (p2) return p2.toUpperCase();
577
+ return p1.toLowerCase();
578
+ });
579
+ }
580
+ class ArgumentBuilder extends Builder {
581
+ type(type) {
582
+ const resolvedType = resolveType(type);
583
+ this._type = resolvedType.type;
584
+ if (resolvedType.nonNull) this.nonNull();
585
+ if (resolvedType.list) this.list();
586
+ if (resolvedType.nonNullList) this.nonNullList();
587
+ return this;
588
+ }
589
+ description(description) {
590
+ this._description = description;
591
+ return this;
592
+ }
593
+ extension(name, value) {
594
+ this._extensions.set(name, value);
595
+ return this;
596
+ }
597
+ nonNull(nonNull = true) {
598
+ this._nonNull = nonNull;
599
+ return this;
600
+ }
601
+ list(list = true) {
602
+ this._list = list;
603
+ return this;
604
+ }
605
+ nonNullList(nonNullList = true) {
606
+ if (nonNullList) this.list();
607
+ this._nonNullList = nonNullList;
608
+ return this;
609
+ }
610
+ async finalizeBuilder(context) {
611
+ const info = this.info();
612
+ await this._executePlugins('beforeFinalizeArgument', (plugin)=>plugin.beforeFinalizeArgument(this, context, info));
613
+ await this.finalizeArgument(context, info);
614
+ await this._executePlugins('afterFinalizeArgument', (plugin)=>plugin.afterFinalizeArgument(this, context, info));
615
+ }
616
+ async finalizeArgument(context, info) {}
617
+ build(context) {
618
+ const info = this.info();
619
+ this._executePluginsSync('beforeBuildArgument', (plugin)=>plugin.beforeBuildArgument(this, context, info));
620
+ let type = (0, compat_namespaceObject.isString)(this._type) ? context.getType(this._type) : this._type;
621
+ if (this._list) {
622
+ if (this._nonNullList) type = new external_graphql_namespaceObject.GraphQLNonNull(type);
623
+ type = new external_graphql_namespaceObject.GraphQLList(type);
624
+ }
625
+ if (this._nonNull) type = new external_graphql_namespaceObject.GraphQLNonNull(type);
626
+ const argument = {
627
+ type,
628
+ description: this._description,
629
+ extensions: {
630
+ ...Object.fromEntries(this._extensions)
631
+ }
632
+ };
633
+ this._executePluginsSync('afterBuildArgument', (plugin)=>plugin.afterBuildArgument(this, context, info, argument));
634
+ return argument;
635
+ }
636
+ info() {
637
+ return {
638
+ name: this.name,
639
+ type: this._type,
640
+ description: this._description,
641
+ extensions: new Map(this._extensions),
642
+ nonNull: this._nonNull,
643
+ nonNullList: this._nonNullList,
644
+ list: this._list,
645
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
646
+ };
647
+ }
648
+ constructor(name, type){
649
+ super(name), this._extensions = new Map(), this._nonNull = false, this._nonNullList = false, this._list = false;
650
+ this.type(type);
651
+ }
652
+ }
653
+ function argument_argument(name, type) {
654
+ return new ArgumentBuilder(name, type);
655
+ }
656
+ class FieldBuilder extends Builder {
657
+ type(type) {
658
+ const resolvedType = resolveType(type);
659
+ this._type = resolvedType.type;
660
+ if (resolvedType.nonNull) this.nonNull();
661
+ if (resolvedType.list) this.list();
662
+ if (resolvedType.nonNullList) this.nonNullList();
663
+ return this;
664
+ }
665
+ description(description) {
666
+ this._description = description;
667
+ return this;
668
+ }
669
+ extension(name, value) {
670
+ this._extensions.set(name, value);
671
+ return this;
672
+ }
673
+ arg(argOrName, type = null, configurator = null) {
674
+ let argument = null;
675
+ if (argOrName instanceof ArgumentBuilder) argument = argOrName;
676
+ else if ((0, compat_namespaceObject.isString)(argOrName) && type) {
677
+ argument = new ArgumentBuilder(argOrName, type);
678
+ if (configurator) configurator(argument);
679
+ } else throw new BuilderError('Invalid argument provided', argOrName);
680
+ this._arguments.push(argument);
681
+ return this;
682
+ }
683
+ nonNull(nonNull = true) {
684
+ this._nonNull = nonNull;
685
+ return this;
686
+ }
687
+ list(list = true) {
688
+ this._list = list;
689
+ return this;
690
+ }
691
+ nonNullList(nonNullList = true) {
692
+ if (nonNullList) this.list();
693
+ this._nonNullList = nonNullList;
694
+ return this;
695
+ }
696
+ resolver(resolver) {
697
+ this._resolver = resolver;
698
+ return this;
699
+ }
700
+ allow(...roles) {
701
+ roles.forEach((role)=>this._allowedRoles.add(role));
702
+ return this;
703
+ }
704
+ deny(...roles) {
705
+ roles.forEach((role)=>this._deniedRoles.add(role));
706
+ return this;
707
+ }
708
+ includeDeleted(includeDeleted = true) {
709
+ this._includeDeleted = includeDeleted;
710
+ return this;
711
+ }
712
+ async finalizeBuilder(context) {
713
+ const info = this.info();
714
+ await this._executePlugins('beforeFinalizeField', (plugin)=>plugin.beforeFinalizeField(this, context, info));
715
+ await this.finalizeField(context, info);
716
+ await this._executePlugins('afterFinalizeField', (plugin)=>plugin.afterFinalizeField(this, context, info));
717
+ for (const arg of this._arguments)this._plugins.forEach((plugin)=>arg.use(plugin));
718
+ for (const argument of this._arguments)await argument.finalize(context);
719
+ }
720
+ async finalizeField(context, info) {}
721
+ build(context, parentBuilder) {
722
+ if (!parentBuilder) throw new BuilderError('Build: Field needs parent builder argument to be present');
723
+ const info = this.info();
724
+ this._executePluginsSync('beforeBuildField', (plugin)=>plugin.beforeBuildField(this, context, info));
725
+ const builtArgs = {};
726
+ for (const arg of this._arguments)builtArgs[arg.name] = arg.build(context);
727
+ let type = (0, compat_namespaceObject.isString)(this._type) ? context.getType(this._type) : this._type;
728
+ if (null === type) throw new BuilderError(`Type "${this._type}" of field "${this.name}" not found`);
729
+ if (this._list) {
730
+ if (this._nonNullList) type = new external_graphql_namespaceObject.GraphQLNonNull(type);
731
+ type = new external_graphql_namespaceObject.GraphQLList(type);
732
+ }
733
+ if (this._nonNull) type = new external_graphql_namespaceObject.GraphQLNonNull(type);
734
+ const resolver = this._resolver || context.getResolver(parentBuilder.name, this.name);
735
+ const field = {
736
+ type,
737
+ description: this._description,
738
+ args: builtArgs,
739
+ extensions: {
740
+ ...getAclExtension(this._allowedRoles, this._deniedRoles),
741
+ ...Object.fromEntries(this._extensions)
742
+ },
743
+ resolve: resolver
744
+ };
745
+ this._executePluginsSync('afterBuildField', (plugin)=>plugin.afterBuildField(this, context, info, field));
746
+ return field;
747
+ }
748
+ info() {
749
+ return {
750
+ name: this.name,
751
+ type: this._type,
752
+ description: this._description,
753
+ arguments: (0, compat_namespaceObject.clone)(this._arguments),
754
+ extensions: new Map(this._extensions),
755
+ nonNull: this._nonNull,
756
+ nonNullList: this._nonNullList,
757
+ list: this._list,
758
+ includeDeleted: this._includeDeleted,
759
+ allowedRoles: new Set(this._allowedRoles),
760
+ deniedRoles: new Set(this._deniedRoles),
761
+ resolver: this._resolver,
762
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
763
+ };
764
+ }
765
+ constructor(name, type = null){
766
+ super(name), this._arguments = [], this._extensions = new Map(), this._nonNull = false, this._nonNullList = false, this._list = false, this._includeDeleted = false, this._allowedRoles = new Set(), this._deniedRoles = new Set();
767
+ this.type(type);
768
+ }
769
+ }
770
+ function field_field(name, type = null) {
771
+ return new FieldBuilder(name, type);
772
+ }
773
+ class ObjectTypeBuilder extends Builder {
774
+ description(description) {
775
+ this._description = description;
776
+ return this;
777
+ }
778
+ extension(name, value) {
779
+ this._extensions.set(name, value);
780
+ return this;
781
+ }
782
+ resolvers(resolvers) {
783
+ this._resolvers = resolvers;
784
+ return this;
785
+ }
786
+ getResolvers() {
787
+ return this._resolvers;
788
+ }
789
+ field(fieldOrName, type = null, configurator = null) {
790
+ let field = null;
791
+ if (fieldOrName instanceof FieldBuilder) field = fieldOrName;
792
+ else if ((0, compat_namespaceObject.isString)(fieldOrName) && type) {
793
+ field = new FieldBuilder(fieldOrName, type);
794
+ if (configurator) configurator(field);
795
+ } else throw new BuilderError('Invalid field provided', fieldOrName);
796
+ this._fields.push(field);
797
+ return this;
798
+ }
799
+ allow(...roles) {
800
+ roles.forEach((role)=>this._allowedRoles.add(role));
801
+ return this;
802
+ }
803
+ deny(...roles) {
804
+ roles.forEach((role)=>this._deniedRoles.add(role));
805
+ return this;
806
+ }
807
+ async finalizeBuilder(context) {
808
+ const info = this.info();
809
+ await this._executePlugins('beforeFinalizeObjectType', (plugin)=>plugin.beforeFinalizeObjectType(this, context, info));
810
+ await this.finalizeObjectType(context, info);
811
+ await this._executePlugins('afterFinalizeObjectType', (plugin)=>plugin.afterFinalizeObjectType(this, context, info));
812
+ for (const field of this._fields)this._plugins.forEach((plugin)=>field.use(plugin));
813
+ for (const field of this._fields)await field.finalize(context);
814
+ }
815
+ async finalizeObjectType(context, info) {}
816
+ build(context) {
817
+ const info = this.info();
818
+ this._executePluginsSync('beforeBuildObjectType', (plugin)=>plugin.beforeBuildObjectType(this, context, info));
819
+ const objectType = new external_graphql_namespaceObject.GraphQLObjectType({
820
+ name: this.name,
821
+ description: this._description,
822
+ extensions: {
823
+ ...getAclExtension(this._allowedRoles, this._deniedRoles),
824
+ ...Object.fromEntries(this._extensions)
825
+ },
826
+ fields: ()=>{
827
+ const builtFields = {};
828
+ for (const field of this._fields)builtFields[field.name] = field.build(context, this);
829
+ return builtFields;
830
+ }
831
+ });
832
+ this._executePluginsSync('afterBuildObjectType', (plugin)=>plugin.afterBuildObjectType(this, context, info, objectType));
833
+ return objectType;
834
+ }
835
+ info() {
836
+ return {
837
+ name: this.name,
838
+ description: this._description,
839
+ fields: (0, compat_namespaceObject.clone)(this._fields),
840
+ extensions: new Map(this._extensions),
841
+ allowedRoles: new Set(this._allowedRoles),
842
+ deniedRoles: new Set(this._deniedRoles),
843
+ resolvers: this._resolvers,
844
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
845
+ };
846
+ }
847
+ constructor(...args){
848
+ super(...args), this._fields = [], this._extensions = new Map(), this._allowedRoles = new Set(), this._deniedRoles = new Set();
849
+ }
850
+ }
851
+ function objectType_objectType(name) {
852
+ return new ObjectTypeBuilder(name);
853
+ }
854
+ const ts_objectType = objectType_objectType;
855
+ class UnionTypeBuilder extends Builder {
856
+ type(...types) {
857
+ types.forEach((role)=>this._types.add(role));
858
+ return this;
859
+ }
860
+ description(description) {
861
+ this._description = description;
862
+ return this;
863
+ }
864
+ extension(name, value) {
865
+ this._extensions.set(name, value);
866
+ return this;
867
+ }
868
+ async finalizeBuilder(context) {
869
+ const info = this.info();
870
+ await this._executePlugins('beforeFinalizeUnionType', (plugin)=>plugin.beforeFinalizeUnionType(this, context, info));
871
+ await this.finalizeUnionType(context, info);
872
+ await this._executePlugins('afterFinalizeUnionType', (plugin)=>plugin.afterFinalizeUnionType(this, context, info));
873
+ }
874
+ async finalizeUnionType(context, info) {}
875
+ build(context) {
876
+ const info = this.info();
877
+ this._executePluginsSync('beforeBuildUnionType', (plugin)=>plugin.beforeBuildUnionType(this, context, info));
878
+ const unionType = new definition_namespaceObject.GraphQLUnionType({
879
+ name: this.name,
880
+ description: this._description,
881
+ types: ()=>{
882
+ const resolvedTypes = [];
883
+ for (const type of this._types)if ((0, compat_namespaceObject.isString)(type)) {
884
+ const resolved = context.getType(type);
885
+ resolvedTypes.push(resolved);
886
+ } else resolvedTypes.push(type);
887
+ return resolvedTypes;
888
+ },
889
+ extensions: {
890
+ ...Object.fromEntries(this._extensions)
891
+ }
892
+ });
893
+ this._executePluginsSync('afterBuildUnionType', (plugin)=>plugin.afterBuildUnionType(this, context, info, unionType));
894
+ return unionType;
895
+ }
896
+ info() {
897
+ return {
898
+ name: this.name,
899
+ types: new Set(this._types),
900
+ description: this._description,
901
+ extensions: new Map(this._extensions),
902
+ plugins: (0, compat_namespaceObject.clone)(this._plugins)
903
+ };
904
+ }
905
+ constructor(name, types = null){
906
+ super(name), this._extensions = new Map();
907
+ this._types = new Set(types || []);
908
+ }
909
+ }
910
+ function unionType_unionType(name, types = null) {
911
+ return new UnionTypeBuilder(name, types);
912
+ }
913
+ const DefaultScalars = [
914
+ external_graphql_namespaceObject.GraphQLInt,
915
+ external_graphql_namespaceObject.GraphQLFloat,
916
+ external_graphql_namespaceObject.GraphQLString,
917
+ external_graphql_namespaceObject.GraphQLBoolean,
918
+ external_graphql_namespaceObject.GraphQLID
919
+ ];
920
+ class AbstractSchemaBuilder {
921
+ naming(strategy) {
922
+ this._namingStrategy = strategy;
923
+ return this;
924
+ }
925
+ setDefaultNamingStrategy(strategy) {
926
+ this._defaultNamingStrategy = strategy;
927
+ }
928
+ get namingStrategy() {
929
+ return this._namingStrategy || this._defaultNamingStrategy;
930
+ }
931
+ customConfig(config) {
932
+ this._customConfig = config;
933
+ return this;
934
+ }
935
+ object(objectOrName, configurator = null) {
936
+ const resolvedArgs = resolveBuilderArgs(objectOrName, configurator, ObjectTypeBuilder);
937
+ const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new ObjectTypeBuilder(name));
938
+ this._objectTypes.set(resolvedBuilder.name, resolvedBuilder);
939
+ return this;
940
+ }
941
+ getObjectTypes() {
942
+ return (0, compat_namespaceObject.compact)([
943
+ this._queryObject,
944
+ this._mutationObject,
945
+ ...Array.from(this._objectTypes.values())
946
+ ]);
947
+ }
948
+ inputObject(objectOrName, configurator = null) {
949
+ const resolvedArgs = resolveBuilderArgs(objectOrName, configurator, InputObjectTypeBuilder);
950
+ const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new InputObjectTypeBuilder(name));
951
+ this._inputObjectTypes.set(resolvedBuilder.name, resolvedBuilder);
952
+ return this;
953
+ }
954
+ getInputObjectTypes() {
955
+ return Array.from(this._inputObjectTypes.values());
956
+ }
957
+ enum(enumOrName, configuratorOrValuesObject = null) {
958
+ let builder = null;
959
+ let name = null;
960
+ let configurator = null;
961
+ let valuesObject = null;
962
+ if (enumOrName instanceof EnumTypeBuilder) {
963
+ builder = enumOrName;
964
+ if ((0, compat_namespaceObject.isFunction)(configuratorOrValuesObject)) configurator = configuratorOrValuesObject;
965
+ } else if ((0, compat_namespaceObject.isString)(enumOrName)) {
966
+ name = enumOrName;
967
+ if ((0, compat_namespaceObject.isFunction)(configuratorOrValuesObject)) configurator = configuratorOrValuesObject;
968
+ else valuesObject = configuratorOrValuesObject;
969
+ }
970
+ const resolvedArgs = {
971
+ builder,
972
+ name,
973
+ configurator
974
+ };
975
+ const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new EnumTypeBuilder(name, valuesObject));
976
+ this._enumTypes.set(resolvedBuilder.name, resolvedBuilder);
977
+ return this;
978
+ }
979
+ getEnumTypes() {
980
+ return Array.from(this._enumTypes.values());
981
+ }
982
+ union(objectOrName, configuratorOrTypes = null) {
983
+ let builder = null;
984
+ let name = null;
985
+ let configurator = null;
986
+ let resolvedTypes = null;
987
+ if (objectOrName instanceof UnionTypeBuilder) {
988
+ builder = objectOrName;
989
+ if ((0, compat_namespaceObject.isFunction)(configuratorOrTypes)) configurator = configuratorOrTypes;
990
+ } else if ((0, compat_namespaceObject.isString)(objectOrName)) {
991
+ name = objectOrName;
992
+ if ((0, compat_namespaceObject.isFunction)(configuratorOrTypes)) configurator = configuratorOrTypes;
993
+ else if ((0, compat_namespaceObject.isArray)(configuratorOrTypes)) resolvedTypes = configuratorOrTypes;
994
+ }
995
+ const resolvedArgs = {
996
+ builder,
997
+ name,
998
+ configurator
999
+ };
1000
+ const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new UnionTypeBuilder(name, resolvedTypes));
1001
+ this._unionTypes.set(resolvedBuilder.name, resolvedBuilder);
1002
+ return this;
1003
+ }
1004
+ getUnionTypes() {
1005
+ return Array.from(this._unionTypes.values());
1006
+ }
1007
+ scalar(scalar) {
1008
+ this._scalarTypes.set(scalar.name, scalar);
1009
+ return this;
1010
+ }
1011
+ query(fieldOrName, type = null, configurator = null) {
1012
+ this._queryObject.field(fieldOrName, type, configurator);
1013
+ return this;
1014
+ }
1015
+ mutation(fieldOrName, type = null, configurator = null) {
1016
+ if (!this._mutationObject) this._mutationObject = new ObjectTypeBuilder('Mutation');
1017
+ this._mutationObject.field(fieldOrName, type, configurator);
1018
+ return this;
1019
+ }
1020
+ resolvers(resolvers) {
1021
+ this._resolvers = resolvers;
1022
+ return this;
1023
+ }
1024
+ queryResolvers(resolvers) {
1025
+ this._queryResolvers = resolvers;
1026
+ return this;
1027
+ }
1028
+ mutationResolvers(resolvers) {
1029
+ this._mutationResolvers = resolvers;
1030
+ return this;
1031
+ }
1032
+ allow(...roles) {
1033
+ roles.forEach((role)=>this._allowedRoles.add(role));
1034
+ return this;
1035
+ }
1036
+ deny(...roles) {
1037
+ roles.forEach((role)=>this._deniedRoles.add(role));
1038
+ return this;
1039
+ }
1040
+ allowQuery(...roles) {
1041
+ roles.forEach((role)=>this._allowedQueryRoles.add(role));
1042
+ return this;
1043
+ }
1044
+ denyQuery(...roles) {
1045
+ roles.forEach((role)=>this._deniedQueryRoles.add(role));
1046
+ return this;
1047
+ }
1048
+ allowMutation(...roles) {
1049
+ roles.forEach((role)=>this._allowedMutationRoles.add(role));
1050
+ return this;
1051
+ }
1052
+ denyMutation(...roles) {
1053
+ roles.forEach((role)=>this._deniedMutationRoles.add(role));
1054
+ return this;
1055
+ }
1056
+ merge(schema) {
1057
+ this._subSchemas.push(schema);
1058
+ return this;
1059
+ }
1060
+ use(...middlewareOrPlugins) {
1061
+ for (const item of middlewareOrPlugins)if ((0, compat_namespaceObject.isObjectLike)(item)) this._plugins.push(item);
1062
+ else if ((0, compat_namespaceObject.isFunction)(item)) this._middleware.push(item);
1063
+ return this;
1064
+ }
1065
+ findType(name, deep = false) {
1066
+ var _this_locateType;
1067
+ return null === (_this_locateType = this.locateType(name, deep)) || void 0 === _this_locateType ? void 0 : _this_locateType.type;
1068
+ }
1069
+ locateType(name, deep = false) {
1070
+ var _this__mutationObject;
1071
+ let type = null;
1072
+ type = name === this._queryObject.name ? this._queryObject : name === (null === (_this__mutationObject = this._mutationObject) || void 0 === _this__mutationObject ? void 0 : _this__mutationObject.name) ? this._mutationObject : this._objectTypes.get(name) ?? this._inputObjectTypes.get(name) ?? this._enumTypes.get(name) ?? this._unionTypes.get(name) ?? this._scalarTypes.get(name) ?? null;
1073
+ if (!type && deep) for (const sub of this._subSchemas){
1074
+ const result = sub.locateType(name, true);
1075
+ if (result) return result;
1076
+ }
1077
+ return type ? {
1078
+ schema: this,
1079
+ type
1080
+ } : null;
1081
+ }
1082
+ hasType(name, deep = false) {
1083
+ return !!this.findType(name, deep);
1084
+ }
1085
+ findResolver(typeName, fieldName) {
1086
+ const resolvers = this.compiledResolvers;
1087
+ let resolver = null;
1088
+ const typeResolvers = resolvers[typeName];
1089
+ if (typeResolvers && typeResolvers[fieldName]) resolver = typeResolvers[fieldName].bind(typeResolvers);
1090
+ return resolver;
1091
+ }
1092
+ get name() {
1093
+ return resolveName(this._name);
1094
+ }
1095
+ get tag() {
1096
+ return this._tag;
1097
+ }
1098
+ async finalize(rootSchema) {
1099
+ const resolvedRootSchema = rootSchema || this;
1100
+ if (this._namingStrategy) for (const subSchema of this._subSchemas)subSchema.setDefaultNamingStrategy(this._namingStrategy);
1101
+ for (const subSchema of this._subSchemas){
1102
+ this._plugins.forEach((plugin)=>subSchema.use(plugin));
1103
+ this._middleware.forEach((middleware)=>subSchema.use(middleware));
1104
+ subSchema.allow(...Array.from(this._allowedRoles));
1105
+ subSchema.deny(...Array.from(this._deniedRoles));
1106
+ subSchema.allowQuery(...Array.from(this._allowedQueryRoles));
1107
+ subSchema.denyQuery(...Array.from(this._deniedQueryRoles));
1108
+ subSchema.allowMutation(...Array.from(this._allowedMutationRoles));
1109
+ subSchema.denyMutation(...Array.from(this._deniedMutationRoles));
1110
+ }
1111
+ await this._executePlugins('beforeFinalizeSchema', (plugin)=>plugin.beforeFinalizeSchema(this));
1112
+ await this.finalizeSchema();
1113
+ await this._executePlugins('afterFinalizeSchema', (plugin)=>plugin.afterFinalizeSchema(this));
1114
+ for (const objectType of this.getObjectTypes())this._plugins.forEach((plugin)=>objectType.use(plugin));
1115
+ for (const inputObject of this._inputObjectTypes.values())this._plugins.forEach((plugin)=>inputObject.use(plugin));
1116
+ for (const unionType of this._unionTypes.values())this._plugins.forEach((plugin)=>unionType.use(plugin));
1117
+ for (const enumType of this._enumTypes.values())this._plugins.forEach((plugin)=>enumType.use(plugin));
1118
+ for (const objectType of Array.from(this._objectTypes.values()))objectType.allow(...Array.from(this._allowedRoles)).deny(...Array.from(this._deniedRoles));
1119
+ const fullAllowedQueryRoles = [
1120
+ ...Array.from(this._allowedRoles),
1121
+ ...Array.from(this._allowedQueryRoles)
1122
+ ];
1123
+ const fullDeniedQueryRoles = [
1124
+ ...Array.from(this._deniedRoles),
1125
+ ...Array.from(this._deniedQueryRoles)
1126
+ ];
1127
+ for (const queryField of this._queryObject.info().fields)queryField.allow(...fullAllowedQueryRoles).deny(...fullDeniedQueryRoles);
1128
+ if (this._mutationObject) {
1129
+ const fullAllowedMutationRoles = [
1130
+ ...Array.from(this._allowedRoles),
1131
+ ...Array.from(this._allowedMutationRoles)
1132
+ ];
1133
+ const fullDeniedMutationRoles = [
1134
+ ...Array.from(this._deniedRoles),
1135
+ ...Array.from(this._deniedMutationRoles)
1136
+ ];
1137
+ for (const mutationField of this._mutationObject.info().fields)mutationField.allow(...fullAllowedMutationRoles).deny(...fullDeniedMutationRoles);
1138
+ }
1139
+ const finalizeContext = new FinalizeContext(this, resolvedRootSchema);
1140
+ for (const objectType of this.getObjectTypes())await objectType.finalize(finalizeContext);
1141
+ for (const inputObjectType of this._inputObjectTypes.values())await inputObjectType.finalize(finalizeContext);
1142
+ for (const unionType of this._unionTypes.values())await unionType.finalize(finalizeContext);
1143
+ for (const enumType of this._enumTypes.values())await enumType.finalize(finalizeContext);
1144
+ for (const subSchema of this._subSchemas)await subSchema.finalize(resolvedRootSchema);
1145
+ }
1146
+ async finalizeSchema() {}
1147
+ async build() {
1148
+ await this.finalize();
1149
+ this._executePluginsSync('beforeBuild', (plugin)=>plugin.beforeBuild(this));
1150
+ const resolvedTypes = new Map();
1151
+ const schema = await this.buildSchema(resolvedTypes);
1152
+ this._executePluginsSync('afterBuild', (plugin)=>plugin.afterBuild(this, schema));
1153
+ return schema;
1154
+ }
1155
+ async buildSchema(resolvedTypes, rootSchema) {
1156
+ const resolvedRootSchema = rootSchema || this;
1157
+ this._executePluginsSync('beforeBuildSchema', (plugin)=>plugin.beforeBuildSchema(this, resolvedRootSchema));
1158
+ const context = new BuildContext(this, resolvedRootSchema, resolvedTypes);
1159
+ const schemaConfig = {
1160
+ ...this._customConfig || {},
1161
+ query: this._queryObject.build(context)
1162
+ };
1163
+ if (this._mutationObject) schemaConfig['mutation'] = this._mutationObject.build(context);
1164
+ const schema = new external_graphql_namespaceObject.GraphQLSchema(schemaConfig);
1165
+ const fullSchema = (0, external_graphql_middleware_namespaceObject.applyMiddleware)(schema, ...this._middleware);
1166
+ const builtSubSchemas = [];
1167
+ for (const subSchema of this._subSchemas){
1168
+ const builtSchema = await subSchema.buildSchema(resolvedTypes, resolvedRootSchema);
1169
+ builtSubSchemas.push(builtSchema);
1170
+ }
1171
+ const mergedSchema = (0, schema_namespaceObject.mergeSchemas)({
1172
+ schemas: [
1173
+ fullSchema,
1174
+ ...builtSubSchemas
1175
+ ]
1176
+ });
1177
+ this._executePluginsSync('afterBuildSchema', (plugin)=>plugin.afterBuildSchema(this, mergedSchema, resolvedRootSchema));
1178
+ return mergedSchema;
1179
+ }
1180
+ get compiledResolvers() {
1181
+ const resolvers = this._resolvers ? (0, compat_namespaceObject.clone)(this._resolvers) : {};
1182
+ if (this._queryResolvers) resolvers['Query'] = ensureInstantiated(this._queryResolvers);
1183
+ if (this._mutationResolvers && this._mutationObject) resolvers['Mutation'] = ensureInstantiated(this._mutationResolvers);
1184
+ for (const objectType of this._objectTypes.values()){
1185
+ const objectResolvers = objectType.getResolvers();
1186
+ if (objectResolvers) resolvers[objectType.name] = objectResolvers;
1187
+ }
1188
+ return resolvers;
1189
+ }
1190
+ async _executePlugins(methodName, fn) {
1191
+ for (const plugin of this._plugins)if (plugin[methodName]) await fn(plugin);
1192
+ }
1193
+ _executePluginsSync(methodName, fn) {
1194
+ for (const plugin of this._plugins)if (plugin[methodName]) fn(plugin);
1195
+ }
1196
+ _addDefaultScalars() {
1197
+ DefaultScalars.forEach((scalar)=>this.scalar(scalar));
1198
+ }
1199
+ constructor(name = null){
1200
+ this._plugins = [];
1201
+ this._middleware = [];
1202
+ this._subSchemas = [];
1203
+ this._objectTypes = new Map();
1204
+ this._inputObjectTypes = new Map();
1205
+ this._enumTypes = new Map();
1206
+ this._unionTypes = new Map();
1207
+ this._scalarTypes = new Map();
1208
+ this._allowedRoles = new Set();
1209
+ this._deniedRoles = new Set();
1210
+ this._allowedQueryRoles = new Set();
1211
+ this._deniedQueryRoles = new Set();
1212
+ this._allowedMutationRoles = new Set();
1213
+ this._deniedMutationRoles = new Set();
1214
+ this._queryObject = new ObjectTypeBuilder('Query');
1215
+ this._name = name;
1216
+ this._tag = Math.round(1000000 * Math.random());
1217
+ this._addDefaultScalars();
1218
+ }
1219
+ }
1220
+ class SchemaBuilder extends AbstractSchemaBuilder {
1221
+ }
1222
+ function schema_schema(name = null) {
1223
+ return new SchemaBuilder(name);
1224
+ }
1225
+ const ts_schema = schema_schema;
1226
+ class CreateInputObjectTypeBuilder extends InputObjectTypeBuilder {
1227
+ exclude(...fieldNames) {
1228
+ fieldNames.forEach((name)=>this._exclude.add(name));
1229
+ return this;
1230
+ }
1231
+ include(...fieldNames) {
1232
+ fieldNames.forEach((name)=>this._include.add(name));
1233
+ return this;
1234
+ }
1235
+ async finalizeInputObjectType(context, info) {
1236
+ await super.finalizeInputObjectType(context, info);
1237
+ const entity = this._entityObjectType instanceof ObjectTypeBuilder ? this._entityObjectType : this._entityObjectType();
1238
+ const entityInfo = entity.info();
1239
+ const existingFieldNames = info.fields.map((field)=>field.name);
1240
+ for (const field of entityInfo.fields){
1241
+ const fieldInfo = field.info();
1242
+ if (!isTypeInput(fieldInfo.type, context.rootSchema) || isFieldId(fieldInfo) || existingFieldNames.indexOf(fieldInfo.name) >= 0) continue;
1243
+ if (this._exclude.has(fieldInfo.name) || this._include.size > 0 && !this._include.has(fieldInfo.name)) continue;
1244
+ const inputField = new InputFieldBuilder(fieldInfo.name, fieldInfo.type);
1245
+ if (fieldInfo.nonNull) inputField.nonNull();
1246
+ if (fieldInfo.list) inputField.list();
1247
+ if (fieldInfo.nonNullList) inputField.nonNullList();
1248
+ this.field(inputField);
1249
+ }
1250
+ }
1251
+ constructor(name, entityType){
1252
+ super(name), this._exclude = new Set(), this._include = new Set();
1253
+ this._entityObjectType = entityType;
1254
+ }
1255
+ }
1256
+ function createInputObjectType(name, entityType) {
1257
+ return new CreateInputObjectTypeBuilder(name, entityType);
1258
+ }
1259
+ const external_pluralize_namespaceObject = require("pluralize");
1260
+ var external_pluralize_default = /*#__PURE__*/ __webpack_require__.n(external_pluralize_namespaceObject);
1261
+ function ucFirst(input) {
1262
+ if (null === input || 0 === input.length) return null;
1263
+ return input.charAt(0).toUpperCase() + input.slice(1);
1264
+ }
1265
+ function lcFirst(input) {
1266
+ if (null === input || 0 === input.length) return null;
1267
+ return input.charAt(0).toLowerCase() + input.slice(1);
1268
+ }
1269
+ class CompactNamingStrategy {
1270
+ entityObject(schemaName) {
1271
+ return ucFirst(schemaName);
1272
+ }
1273
+ allField(schemaName) {
1274
+ return external_pluralize_default()(lcFirst(schemaName));
1275
+ }
1276
+ findField(schemaName) {
1277
+ return lcFirst(schemaName);
1278
+ }
1279
+ createField(schemaName) {
1280
+ return `create${ucFirst(schemaName)}`;
1281
+ }
1282
+ updateField(schemaName) {
1283
+ return `update${ucFirst(schemaName)}`;
1284
+ }
1285
+ deleteField(schemaName) {
1286
+ return `delete${ucFirst(schemaName)}`;
1287
+ }
1288
+ restoreField(schemaName) {
1289
+ return `restore${ucFirst(schemaName)}`;
1290
+ }
1291
+ findFieldIdArgument(schemaName) {
1292
+ return 'id';
1293
+ }
1294
+ deleteFieldIdArgument(schemaName) {
1295
+ return 'id';
1296
+ }
1297
+ restoreFieldIdArgument(schemaName) {
1298
+ return 'id';
1299
+ }
1300
+ createInputObject(schemaName) {
1301
+ return `Create${ucFirst(schemaName)}Input`;
1302
+ }
1303
+ createFieldInputArgument(schemaName) {
1304
+ return 'input';
1305
+ }
1306
+ updateInputObject(schemaName) {
1307
+ return `Update${ucFirst(schemaName)}Input`;
1308
+ }
1309
+ updateFieldInputArgument(schemaName) {
1310
+ return 'input';
1311
+ }
1312
+ }
1313
+ function compactNamingStrategy() {
1314
+ return new CompactNamingStrategy();
1315
+ }
1316
+ class UpdateInputObjectTypeBuilder extends InputObjectTypeBuilder {
1317
+ exclude(...fieldNames) {
1318
+ fieldNames.forEach((name)=>this._exclude.add(name));
1319
+ return this;
1320
+ }
1321
+ include(...fieldNames) {
1322
+ fieldNames.forEach((name)=>this._include.add(name));
1323
+ return this;
1324
+ }
1325
+ async finalizeInputObjectType(context, info) {
1326
+ await super.finalizeInputObjectType(context, info);
1327
+ const entity = this._entityObjectType instanceof ObjectTypeBuilder ? this._entityObjectType : this._entityObjectType();
1328
+ const entityInfo = entity.info();
1329
+ const existingFieldNames = info.fields.map((field)=>field.name);
1330
+ for (const field of entityInfo.fields){
1331
+ const fieldInfo = field.info();
1332
+ if (!isTypeInput(fieldInfo.type, context.rootSchema) || existingFieldNames.indexOf(fieldInfo.name) >= 0) continue;
1333
+ if (this._exclude.has(fieldInfo.name) || this._include.size > 0 && !this._include.has(fieldInfo.name)) continue;
1334
+ const inputField = new InputFieldBuilder(fieldInfo.name, fieldInfo.type);
1335
+ if (isFieldId(fieldInfo)) inputField.nonNull();
1336
+ if (fieldInfo.list) inputField.list();
1337
+ if (fieldInfo.nonNullList) inputField.nonNullList();
1338
+ this.field(inputField);
1339
+ }
1340
+ }
1341
+ constructor(name, entityType){
1342
+ super(name), this._exclude = new Set(), this._include = new Set();
1343
+ this._entityObjectType = entityType;
1344
+ }
1345
+ }
1346
+ function updateInputObjectType_updateInputObjectType(name, entityType) {
1347
+ return new UpdateInputObjectTypeBuilder(name, entityType);
1348
+ }
1349
+ var entitySchema_EntityFieldType = /*#__PURE__*/ function(EntityFieldType) {
1350
+ EntityFieldType["ALL"] = "ALL";
1351
+ EntityFieldType["FIND"] = "FIND";
1352
+ EntityFieldType["CREATE"] = "CREATE";
1353
+ EntityFieldType["UPDATE"] = "UPDATE";
1354
+ EntityFieldType["DELETE"] = "DELETE";
1355
+ EntityFieldType["RESTORE"] = "RESTORE";
1356
+ EntityFieldType["RELATION"] = "RELATION";
1357
+ return EntityFieldType;
1358
+ }({});
1359
+ const entityFieldTypeExtensionName = "$entityFieldType";
1360
+ class AbstractEntitySchemaBuilderBase extends AbstractSchemaBuilder {
1361
+ entity(builderOrConfiguratorOrName, configurator = null) {
1362
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, ObjectTypeBuilder);
1363
+ const defaultName = ()=>this.namingStrategy.entityObject(this.name);
1364
+ this._entityObjectType = resolveBuilder(resolvedArgs, (name)=>this.createEntityObjectType(name || defaultName));
1365
+ return this;
1366
+ }
1367
+ all(builderOrConfiguratorOrName = null, configurator = null) {
1368
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1369
+ const defaultName = ()=>this.namingStrategy.allField(this.name);
1370
+ this._allField = resolveBuilder(resolvedArgs, (name)=>this.createAllField(name || defaultName));
1371
+ return this;
1372
+ }
1373
+ find(builderOrConfiguratorOrName = null, configurator = null) {
1374
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1375
+ const defaultName = ()=>this.namingStrategy.findField(this.name);
1376
+ this._findField = resolveBuilder(resolvedArgs, (name)=>this.createFindField(name || defaultName));
1377
+ return this;
1378
+ }
1379
+ create(builderOrConfiguratorOrName = null, configurator = null) {
1380
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1381
+ const defaultName = ()=>this.namingStrategy.createField(this.name);
1382
+ this._createField = resolveBuilder(resolvedArgs, (name)=>this.createCreateField(name || defaultName));
1383
+ return this;
1384
+ }
1385
+ update(builderOrConfiguratorOrName = null, configurator = null) {
1386
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1387
+ const defaultName = ()=>this.namingStrategy.updateField(this.name);
1388
+ this._updateField = resolveBuilder(resolvedArgs, (name)=>this.createUpdateField(name || defaultName));
1389
+ return this;
1390
+ }
1391
+ delete(builderOrConfiguratorOrName = null, configurator = null) {
1392
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1393
+ const defaultName = ()=>this.namingStrategy.deleteField(this.name);
1394
+ this._deleteField = resolveBuilder(resolvedArgs, (name)=>this.createDeleteField(name || defaultName));
1395
+ return this;
1396
+ }
1397
+ restore(builderOrConfiguratorOrName = null, configurator = null) {
1398
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1399
+ const defaultName = ()=>this.namingStrategy.restoreField(this.name);
1400
+ this._restoreField = resolveBuilder(resolvedArgs, (name)=>this.createRestoreField(name || defaultName));
1401
+ return this;
1402
+ }
1403
+ allowEntity(...roles) {
1404
+ roles.forEach((role)=>this._allowedEntityRoles.add(role));
1405
+ return this;
1406
+ }
1407
+ denyEntity(...roles) {
1408
+ roles.forEach((role)=>this._deniedEntityRoles.add(role));
1409
+ return this;
1410
+ }
1411
+ entityResolvers(resolvers) {
1412
+ this._entityResolvers = resolvers;
1413
+ return this;
1414
+ }
1415
+ async finalizeSchema() {
1416
+ await super.finalizeSchema();
1417
+ if (!this._entityObjectType) this._entityObjectType = this.createEntityObjectType(this.namingStrategy.entityObject(this.name));
1418
+ this._entityObjectType.allow(...Array.from(this._allowedEntityRoles)).deny(...Array.from(this._deniedEntityRoles));
1419
+ this.object(this._entityObjectType);
1420
+ if (this._allField) {
1421
+ this._allField.type(this._entityObjectType.name);
1422
+ this._allField.extension(entityFieldTypeExtensionName, "ALL");
1423
+ this.query(this._allField);
1424
+ }
1425
+ if (this._findField) {
1426
+ this._findField.type(this._entityObjectType.name);
1427
+ this._findField.extension(entityFieldTypeExtensionName, "FIND");
1428
+ this.query(this._findField);
1429
+ }
1430
+ if (this._createField) {
1431
+ this._createField.type(this._entityObjectType.name);
1432
+ this._createField.extension(entityFieldTypeExtensionName, "CREATE");
1433
+ this.mutation(this._createField);
1434
+ }
1435
+ if (this._updateField) {
1436
+ this._updateField.type(this._entityObjectType.name);
1437
+ this._updateField.extension(entityFieldTypeExtensionName, "UPDATE");
1438
+ this.mutation(this._updateField);
1439
+ }
1440
+ if (this._deleteField) {
1441
+ this._deleteField.extension(entityFieldTypeExtensionName, "DELETE");
1442
+ this.mutation(this._deleteField);
1443
+ }
1444
+ if (this._restoreField) {
1445
+ this._restoreField.type(this._entityObjectType.name);
1446
+ this._restoreField.extension(entityFieldTypeExtensionName, "RESTORE");
1447
+ this.mutation(this._restoreField);
1448
+ }
1449
+ if (this._entityResolvers) this._resolvers = {
1450
+ [this._entityObjectType.name]: ensureInstantiated(this._entityResolvers),
1451
+ ...this._resolvers
1452
+ };
1453
+ }
1454
+ constructor(...args){
1455
+ super(...args), this._allowedEntityRoles = new Set(), this._deniedEntityRoles = new Set();
1456
+ }
1457
+ }
1458
+ class AbstractEntitySchemaBuilder extends AbstractEntitySchemaBuilderBase {
1459
+ createInput(builderOrConfiguratorOrName = null, configurator = null) {
1460
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1461
+ const defaultName = ()=>this.namingStrategy.createInputObject(this.name);
1462
+ this._createInputObject = resolveBuilder(resolvedArgs, (name)=>this.createCreateInputObject(name || defaultName));
1463
+ return this;
1464
+ }
1465
+ updateInput(builderOrConfiguratorOrName = null, configurator = null) {
1466
+ const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
1467
+ const defaultName = ()=>this.namingStrategy.updateInputObject(this.name);
1468
+ this._updateInputObject = resolveBuilder(resolvedArgs, (name)=>this.createUpdateInputObject(name || defaultName));
1469
+ return this;
1470
+ }
1471
+ async finalizeSchema() {
1472
+ await super.finalizeSchema();
1473
+ if (this._findField) this._findField.arg(this.namingStrategy.findFieldIdArgument(this.name), 'ID', (_)=>_.nonNull());
1474
+ if (this._deleteField) this._deleteField.arg(this.namingStrategy.deleteFieldIdArgument(this.name), 'ID', (_)=>_.nonNull());
1475
+ if (this._restoreField) this._restoreField.arg(this.namingStrategy.restoreFieldIdArgument(this.name), 'ID', (_)=>_.nonNull());
1476
+ if (this._createField) {
1477
+ if (!this._createInputObject) this._createInputObject = this.createCreateInputObject(this.namingStrategy.createInputObject(this.name));
1478
+ this._createField.arg(this.namingStrategy.createFieldInputArgument(this.name), this._createInputObject.name, (_)=>_.nonNull());
1479
+ }
1480
+ if (this._createInputObject) this.inputObject(this._createInputObject);
1481
+ if (this._updateField) {
1482
+ if (!this._updateInputObject) this._updateInputObject = this.createUpdateInputObject(this.namingStrategy.updateInputObject(this.name));
1483
+ this._updateField.arg(this.namingStrategy.updateFieldInputArgument(this.name), this._updateInputObject.name, (_)=>_.nonNull());
1484
+ }
1485
+ if (this._updateInputObject) this.inputObject(this._updateInputObject);
1486
+ }
1487
+ }
1488
+ class EntitySchemaBuilder extends AbstractEntitySchemaBuilder {
1489
+ createEntityObjectType(name) {
1490
+ return new ObjectTypeBuilder(name);
1491
+ }
1492
+ createAllField(name) {
1493
+ return new FieldBuilder(name).list();
1494
+ }
1495
+ createFindField(name) {
1496
+ return new FieldBuilder(name);
1497
+ }
1498
+ createCreateField(name) {
1499
+ return new FieldBuilder(name);
1500
+ }
1501
+ createUpdateField(name) {
1502
+ return new FieldBuilder(name);
1503
+ }
1504
+ createDeleteField(name) {
1505
+ return new FieldBuilder(name, 'Boolean');
1506
+ }
1507
+ createRestoreField(name) {
1508
+ return new FieldBuilder(name);
1509
+ }
1510
+ createCreateInputObject(name) {
1511
+ return new CreateInputObjectTypeBuilder(name, ()=>this._entityObjectType);
1512
+ }
1513
+ createUpdateInputObject(name) {
1514
+ return new UpdateInputObjectTypeBuilder(name, ()=>this._entityObjectType);
1515
+ }
1516
+ constructor(name = null){
1517
+ super(name);
1518
+ this._defaultNamingStrategy = EntitySchemaBuilder.defaultNamingStrategy;
1519
+ }
1520
+ }
1521
+ EntitySchemaBuilder.defaultNamingStrategy = compactNamingStrategy();
1522
+ function entitySchema_entitySchema(name) {
1523
+ return new EntitySchemaBuilder(name);
1524
+ }
1525
+ class ResolverError extends error_FrameworkError {
1526
+ }
1527
+ const resolver_ResolverError = ResolverError;
1528
+ class ForbiddenError_ForbiddenError extends resolver_ResolverError {
1529
+ }
1530
+ class InvalidInputError extends resolver_ResolverError {
1531
+ }
1532
+ class NotFoundError extends resolver_ResolverError {
1533
+ }
1534
+ class DataError_DataError extends resolver_ResolverError {
1535
+ }
1536
+ class DescriptiveNamingStrategy {
1537
+ entityObject(schemaName) {
1538
+ return ucFirst(schemaName);
1539
+ }
1540
+ allField(schemaName) {
1541
+ return `all${external_pluralize_default()(ucFirst(schemaName))}`;
1542
+ }
1543
+ findField(schemaName) {
1544
+ return `find${ucFirst(schemaName)}`;
1545
+ }
1546
+ createField(schemaName) {
1547
+ return `create${ucFirst(schemaName)}`;
1548
+ }
1549
+ updateField(schemaName) {
1550
+ return `update${ucFirst(schemaName)}`;
1551
+ }
1552
+ deleteField(schemaName) {
1553
+ return `delete${ucFirst(schemaName)}`;
1554
+ }
1555
+ restoreField(schemaName) {
1556
+ return `restore${ucFirst(schemaName)}`;
1557
+ }
1558
+ findFieldIdArgument(schemaName) {
1559
+ return 'id';
1560
+ }
1561
+ deleteFieldIdArgument(schemaName) {
1562
+ return 'id';
1563
+ }
1564
+ restoreFieldIdArgument(schemaName) {
1565
+ return 'id';
1566
+ }
1567
+ createInputObject(schemaName) {
1568
+ return `Create${ucFirst(schemaName)}Input`;
1569
+ }
1570
+ createFieldInputArgument(schemaName) {
1571
+ return 'input';
1572
+ }
1573
+ updateInputObject(schemaName) {
1574
+ return `Update${ucFirst(schemaName)}Input`;
1575
+ }
1576
+ updateFieldInputArgument(schemaName) {
1577
+ return 'input';
1578
+ }
1579
+ }
1580
+ function descriptiveNamingStrategy() {
1581
+ return new DescriptiveNamingStrategy();
1582
+ }
1583
+ const defaultAclMiddlewareOptions = {
1584
+ rolePath: "role",
1585
+ onForbidden: (resource)=>{
1586
+ throw new ForbiddenError_ForbiddenError(`No access to ${resource}`);
1587
+ }
1588
+ };
1589
+ function honoAclMiddleware(acl, config = null, options = null) {
1590
+ const fullOptions = getOptions(options);
1591
+ return async (c, next)=>{
1592
+ const fullPath = c.req.path;
1593
+ if (!config) config = {
1594
+ resource: fullPath
1595
+ };
1596
+ const role = c.get(fullOptions.rolePath) ?? null;
1597
+ const allowed = acl.validate(config, role);
1598
+ if (!allowed) fullOptions.onForbidden(fullPath);
1599
+ return await next();
1600
+ };
1601
+ }
1602
+ function graphQLAclMiddleware(acl, schemaName, options = null) {
1603
+ const fullOptions = getOptions(options);
1604
+ return (resolve, root, args, context, info)=>{
1605
+ const pathResource = getPathResource(info.path);
1606
+ const parsedConfig = {
1607
+ resource: `${schemaName}:${pathResource}`
1608
+ };
1609
+ const role = context.get(fullOptions.rolePath) ?? null;
1610
+ const allowed = acl.validate(parsedConfig, role);
1611
+ if (!allowed) fullOptions.onForbidden(pathResource);
1612
+ return resolve(root, args, context, info);
1613
+ };
1614
+ }
1615
+ function getPathResource(path) {
1616
+ return [
1617
+ path.typename,
1618
+ path.key
1619
+ ].join('.');
1620
+ }
1621
+ function getOptions(options) {
1622
+ return (0, compat_namespaceObject.defaults)({}, options || {}, defaultAclMiddlewareOptions);
1623
+ }
1624
+ var acl_AclAction = /*#__PURE__*/ function(AclAction) {
1625
+ AclAction[AclAction["DENY"] = 0] = "DENY";
1626
+ AclAction[AclAction["ALLOW"] = 1] = "ALLOW";
1627
+ return AclAction;
1628
+ }({});
1629
+ const defaultAclOptions = {
1630
+ defaultAction: 0,
1631
+ learn: true
1632
+ };
1633
+ class AclPlugin {
1634
+ defaultAction(action) {
1635
+ this._options.defaultAction = action;
1636
+ return this;
1637
+ }
1638
+ learn(learn = true) {
1639
+ this._options.learn = learn;
1640
+ return this;
1641
+ }
1642
+ role(identifier, parent = null) {
1643
+ this._roles.set(identifier, {
1644
+ identifier,
1645
+ parent
1646
+ });
1647
+ return this;
1648
+ }
1649
+ allow(resource, roles) {
1650
+ const parsedRoles = new Set((0, compat_namespaceObject.isArray)(roles) ? roles : [
1651
+ roles
1652
+ ]);
1653
+ if (this._options.learn) this._learnRoles(parsedRoles);
1654
+ if (this._allowRules.has(resource)) {
1655
+ const config = this._allowRules.get(resource);
1656
+ parsedRoles.forEach((role)=>config.roles.add(role));
1657
+ } else this._allowRules.set(resource, this._getRuleConfig(resource, parsedRoles));
1658
+ return this;
1659
+ }
1660
+ deny(resource, roles) {
1661
+ const parsedRoles = new Set((0, compat_namespaceObject.isArray)(roles) ? roles : [
1662
+ roles
1663
+ ]);
1664
+ if (this._options.learn) this._learnRoles(parsedRoles);
1665
+ if (this._denyRules.has(resource)) {
1666
+ const config = this._denyRules.get(resource);
1667
+ parsedRoles.forEach((role)=>config.roles.add(role));
1668
+ } else this._denyRules.set(resource, this._getRuleConfig(resource, parsedRoles));
1669
+ return this;
1670
+ }
1671
+ isAllowed(role, resource) {
1672
+ let determinedAction = this._options.defaultAction;
1673
+ const allowRules = this._findRules(resource, this._allowRules);
1674
+ const denyRules = this._findRules(resource, this._denyRules);
1675
+ const rules = (0, compat_namespaceObject.sortBy)([
1676
+ ...allowRules.map((rule)=>({
1677
+ rule,
1678
+ action: 1
1679
+ })),
1680
+ ...denyRules.map((rule)=>({
1681
+ rule,
1682
+ action: 0
1683
+ }))
1684
+ ], (rule)=>rule.rule.name.length);
1685
+ for (const { rule, action } of rules)if (this.isRoleIncluded(role, rule.roles)) determinedAction = action;
1686
+ return 1 === determinedAction;
1687
+ }
1688
+ isRoleIncluded(role, compareRoles) {
1689
+ const roleConfig = this._roles.get(role);
1690
+ if (!roleConfig) throw new error_FrameworkError(`Role "${role}" not registered`);
1691
+ if (compareRoles.has(role)) return true;
1692
+ const roleList = this._getRoleList(roleConfig);
1693
+ for (const candidate of compareRoles)if (roleList.indexOf(candidate) >= 0) return true;
1694
+ return false;
1695
+ }
1696
+ validate(config, role = null) {
1697
+ let parsedConfig;
1698
+ if ((0, compat_namespaceObject.isArray)(config)) parsedConfig = {
1699
+ allowedRoles: config
1700
+ };
1701
+ else if ((0, compat_namespaceObject.isString)(config) || (0, compat_namespaceObject.isNumber)(config)) parsedConfig = {
1702
+ allowedRoles: [
1703
+ config
1704
+ ]
1705
+ };
1706
+ else if (config) parsedConfig = config;
1707
+ let allowed = 1 === this._options.defaultAction;
1708
+ if (role) {
1709
+ if (parsedConfig.allowedRoles) allowed = this.isRoleIncluded(role, new Set(parsedConfig.allowedRoles));
1710
+ else if (parsedConfig.resource) allowed = this.isAllowed(role, parsedConfig.resource);
1711
+ }
1712
+ return allowed;
1713
+ }
1714
+ middleware(config = null) {
1715
+ return honoAclMiddleware(this, config, this._options);
1716
+ }
1717
+ rolePath(path) {
1718
+ this._options.rolePath = path;
1719
+ return this;
1720
+ }
1721
+ onForbidden(handler) {
1722
+ this._options.onForbidden = handler;
1723
+ return this;
1724
+ }
1725
+ beforeBuildSchema(builder, rootBuilder) {
1726
+ builder.use(graphQLAclMiddleware(this, rootBuilder.name || rootBuilder.tag.toString(), this._options));
1727
+ }
1728
+ afterBuildSchema(builder, schema, rootBuilder) {
1729
+ const schemaId = rootBuilder.name || rootBuilder.tag.toString();
1730
+ for (const type of builder.getObjectTypes()){
1731
+ const typeInfo = type.info();
1732
+ this.addRules(`${schemaId}:${type.name}.*`, typeInfo.allowedRoles, typeInfo.deniedRoles);
1733
+ for (const field of type.info().fields){
1734
+ const fieldInfo = field.info();
1735
+ this.addRules(`${schemaId}:${type.name}.${field.name}`, fieldInfo.allowedRoles, fieldInfo.deniedRoles);
1736
+ }
1737
+ }
1738
+ }
1739
+ addRules(resource, allowed, denied) {
1740
+ if (allowed.size > 0) this.allow(resource, Array.from(allowed));
1741
+ if (denied.size > 0) this.deny(resource, Array.from(denied));
1742
+ }
1743
+ _findRules(resource, collection) {
1744
+ const allRules = Array.from(collection.values());
1745
+ return allRules.filter((rule)=>{
1746
+ if ((0, compat_namespaceObject.isString)(rule.resource)) return rule.resource === resource;
1747
+ if (rule.resource instanceof RegExp) return rule.resource.test(resource);
1748
+ return false;
1749
+ });
1750
+ }
1751
+ _learnRoles(roles) {
1752
+ for (const role of roles)if (!this._roles.has(role)) this.role(role);
1753
+ }
1754
+ _getRoleList(roleConfig) {
1755
+ if (!roleConfig) return [];
1756
+ if (!roleConfig.parent) return [
1757
+ roleConfig.identifier
1758
+ ];
1759
+ return [
1760
+ roleConfig.identifier,
1761
+ ...this._getRoleList(this._roles.get(roleConfig.parent))
1762
+ ];
1763
+ }
1764
+ _getRuleConfig(name, roles) {
1765
+ let resource = name;
1766
+ if (name.indexOf('*') >= 0) {
1767
+ const pattern = (0, compat_namespaceObject.escapeRegExp)(name).replace('\\*', '(.*)');
1768
+ resource = new RegExp(`^${pattern}$`);
1769
+ }
1770
+ return {
1771
+ name,
1772
+ resource,
1773
+ roles
1774
+ };
1775
+ }
1776
+ constructor(options){
1777
+ this._roles = new Map();
1778
+ this._allowRules = new Map();
1779
+ this._denyRules = new Map();
1780
+ this._options = (0, compat_namespaceObject.defaults)(options || {}, defaultAclMiddlewareOptions, defaultAclOptions);
1781
+ }
1782
+ }
1783
+ function aclPlugin(options) {
1784
+ return new AclPlugin(options);
1785
+ }
1786
+ class PluginError_PluginError extends error_FrameworkError {
1787
+ }
1788
+ const PluginError = PluginError_PluginError;
1789
+ const defaultEqualsFilterPluginOptions = {
1790
+ multi: false,
1791
+ manual: false,
1792
+ argumentName: 'filter',
1793
+ inputName: (typeName)=>`${typeName}EqualsFilter`
1794
+ };
1795
+ class EqualsFilterPlugin {
1796
+ multi(multi = true) {
1797
+ this._options.multi = multi;
1798
+ return this;
1799
+ }
1800
+ manual(manual = true) {
1801
+ this._options.manual = manual;
1802
+ return this;
1803
+ }
1804
+ field(name, type) {
1805
+ if (!this._options.fields) this._options.fields = [];
1806
+ this._options.fields.push({
1807
+ name,
1808
+ type
1809
+ });
1810
+ return this;
1811
+ }
1812
+ exclude(...fieldNames) {
1813
+ fieldNames.forEach((name)=>this._options.exclude.push(name));
1814
+ return this;
1815
+ }
1816
+ include(...fieldNames) {
1817
+ fieldNames.forEach((name)=>this._options.include.push(name));
1818
+ return this;
1819
+ }
1820
+ argumentName(name) {
1821
+ this._options.argumentName = name;
1822
+ return this;
1823
+ }
1824
+ inputName(nameFactory) {
1825
+ this._options.inputName = nameFactory;
1826
+ return this;
1827
+ }
1828
+ beforeBuildField(builder, context, info) {
1829
+ if (!info.list) return;
1830
+ const typeName = info.type.toString();
1831
+ const inputTypeName = this._options.inputName(typeName);
1832
+ let targetObjectType;
1833
+ if (!this._options.manual) {
1834
+ targetObjectType = context.rootSchema.findType(typeName, true);
1835
+ if (!targetObjectType) throw new PluginError(`Filter target object ${typeName} not found`);
1836
+ if (!(targetObjectType instanceof ObjectTypeBuilder)) throw new PluginError(`Filter target ${typeName} is not an object type`);
1837
+ }
1838
+ const inputType = this._createFilterInputType(context, inputTypeName, targetObjectType);
1839
+ context.schema.inputObject(inputType);
1840
+ builder.arg(this._options.argumentName, inputTypeName, (_)=>_.description("Configuration for how the nodes should be filtered"));
1841
+ }
1842
+ _createFilterInputType(context, name, targetObjectType) {
1843
+ const inputObjectType = ts_inputObjectType(name).description("Configuration for how the nodes should be filtered");
1844
+ const fields = new Set();
1845
+ if (targetObjectType) for (const field of targetObjectType.info().fields){
1846
+ var _this__options_include;
1847
+ const fieldInfo = field.info();
1848
+ if (!fieldInfo.list && !!isTypeInput(fieldInfo.type, context.rootSchema)) {
1849
+ if ((null === (_this__options_include = this._options.include) || void 0 === _this__options_include ? !void 0 : !_this__options_include.length) || !!this._options.include.includes(field.name)) fields.add({
1850
+ name: field.name,
1851
+ type: fieldInfo.type
1852
+ });
1853
+ }
1854
+ }
1855
+ if (this._options.fields) this._options.fields.forEach((field)=>fields.add(field));
1856
+ const extraFields = this._getExtraFieldConfigs(context, name, targetObjectType);
1857
+ if (extraFields) extraFields.forEach((extraField)=>fields.add(extraField));
1858
+ for (const field of fields)if (!(this._options.exclude && this._options.exclude.indexOf(field.name) >= 0)) inputObjectType.field(field.name, field.type, (_)=>{
1859
+ if (this._options.multi) _.list();
1860
+ });
1861
+ return inputObjectType;
1862
+ }
1863
+ _getExtraFieldConfigs(context, name, targetObjectType) {
1864
+ return null;
1865
+ }
1866
+ constructor(options){
1867
+ this._options = (0, compat_namespaceObject.defaults)(options || {}, defaultEqualsFilterPluginOptions, {
1868
+ exclude: [],
1869
+ include: []
1870
+ });
1871
+ }
1872
+ }
1873
+ function equalsFilterPlugin(options) {
1874
+ return new EqualsFilterPlugin(options);
1875
+ }
1876
+ const defaultSearchFilterPluginOptions = {
1877
+ argumentName: 'search'
1878
+ };
1879
+ class SearchFilterPlugin {
1880
+ beforeBuildField(builder, context, info) {
1881
+ if (!info.list) return;
1882
+ builder.arg(this._options.argumentName, 'String', (_)=>_.description('Search query'));
1883
+ }
1884
+ constructor(options){
1885
+ this._options = (0, compat_namespaceObject.defaults)(options || {}, defaultSearchFilterPluginOptions);
1886
+ }
1887
+ }
1888
+ function searchFilterPlugin() {
1889
+ return new SearchFilterPlugin();
1890
+ }
1891
+ const PageInfoObjectTypeName = "PageInfo";
1892
+ class ConnectionPaginationPlugin {
1893
+ totalCount(totalCount = true) {
1894
+ this._totalCount = totalCount;
1895
+ return this;
1896
+ }
1897
+ beforeBuildField(builder, context, info) {
1898
+ if (!info.list) return;
1899
+ if (!context.schema.hasType(PageInfoObjectTypeName)) context.schema.object(this._createPageInfoObjectType());
1900
+ const typeName = info.type.toString();
1901
+ const targetType = context.rootSchema.findType(typeName, true);
1902
+ if (!targetType) throw new PluginError(`Edges target type "${typeName}" not found`);
1903
+ if (!(targetType instanceof ObjectTypeBuilder)) throw new PluginError(`Edges target "${typeName}" is not an object type`);
1904
+ const targetObjectInfo = targetType.info();
1905
+ const pageInfoType = context.schema.findType(PageInfoObjectTypeName);
1906
+ pageInfoType.allow(...Array.from(targetObjectInfo.allowedRoles));
1907
+ pageInfoType.deny(...Array.from(targetObjectInfo.deniedRoles));
1908
+ const edgeObjectTypeName = `${typeName}Edge`;
1909
+ const edgeObjectType = this._createEdgeObjectType(edgeObjectTypeName, typeName);
1910
+ edgeObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
1911
+ edgeObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
1912
+ context.schema.object(edgeObjectType);
1913
+ const connectionObjectTypeName = `${typeName}Connection`;
1914
+ const connectionObjectType = this._createConnectionObjectType(connectionObjectTypeName, edgeObjectTypeName);
1915
+ connectionObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
1916
+ connectionObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
1917
+ context.schema.object(connectionObjectType);
1918
+ builder.type(connectionObjectTypeName).list(false);
1919
+ }
1920
+ _createPageInfoObjectType() {
1921
+ return ts_objectType(PageInfoObjectTypeName).description('Provides information about the paging state').field('hasNextPage', 'Boolean', (_)=>_.nonNull().description('Indicates whether there is a next page')).field('hasPreviousPage', 'Boolean', (_)=>_.nonNull().description('Indicates whether there is a previous page')).field('startCursor', 'String', (_)=>_.description('Cursor for the first node')).field('endCursor', 'String', (_)=>_.description('Cursor for the last node'));
1922
+ }
1923
+ _createConnectionObjectType(name, edgeTypeName) {
1924
+ const type = ts_objectType(name).description(`Connection with ${edgeTypeName}`).field('pageInfo', PageInfoObjectTypeName, (_)=>_.nonNull().description('Provides information about the paging state')).field('edges', edgeTypeName, (_)=>_.list().description('List of the queried edges'));
1925
+ if (this._totalCount) type.field('totalCount', 'Int', (_)=>_.nonNull().description('Total number of nodes'));
1926
+ return type;
1927
+ }
1928
+ _createEdgeObjectType(name, typeName) {
1929
+ return ts_objectType(name).description(`${typeName} edge`).field('node', typeName, (_)=>_.description('Current node')).field('cursor', 'String', (_)=>_.nonNull().description('Cursor for the current node'));
1930
+ }
1931
+ constructor(){
1932
+ this._totalCount = false;
1933
+ }
1934
+ }
1935
+ function connectionPaginationPlugin() {
1936
+ return new ConnectionPaginationPlugin();
1937
+ }
1938
+ class FirstAfterPaginationPlugin {
1939
+ beforeBuildField(builder, context, info) {
1940
+ if (!info.list) return;
1941
+ builder.arg('first', 'Int', (_)=>_.description('Number of nodes to return')).arg('after', 'String', (_)=>_.description('Cursor for item after which results are to be selected'));
1942
+ }
1943
+ }
1944
+ function firstAfterPaginationPlugin() {
1945
+ return new FirstAfterPaginationPlugin();
1946
+ }
1947
+ class ItemsPaginationPlugin {
1948
+ beforeBuildField(builder, context, info) {
1949
+ if (!info.list) return;
1950
+ const typeName = info.type.toString();
1951
+ const targetType = context.rootSchema.findType(typeName, true);
1952
+ if (!targetType) throw new PluginError(`Items target type "${typeName}" not found`);
1953
+ if (!(targetType instanceof ObjectTypeBuilder)) throw new PluginError(`Items target "${typeName}" is not an object type`);
1954
+ const targetObjectInfo = targetType.info();
1955
+ const listObjectTypeName = `${typeName}List`;
1956
+ const listObjectType = this._createListObjectType(listObjectTypeName, typeName);
1957
+ listObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
1958
+ listObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
1959
+ context.schema.object(listObjectType);
1960
+ builder.type(listObjectTypeName).list(false);
1961
+ }
1962
+ _createListObjectType(name, typeName) {
1963
+ return ts_objectType(name).description(`Collection of ${typeName} nodes`).field('items', typeName, (_)=>_.list().nonNull().description('List of the queried nodes')).field('totalCount', 'Int', (_)=>_.nonNull().description('Total number of nodes'));
1964
+ }
1965
+ }
1966
+ function itemsPaginationPlugin() {
1967
+ return new ItemsPaginationPlugin();
1968
+ }
1969
+ class OffsetLimitPaginationPlugin {
1970
+ beforeBuildField(builder, context, info) {
1971
+ if (!info.list) return;
1972
+ builder.arg('offset', 'Int', (_)=>_.description('Offset for the nodes to return')).arg('limit', 'Int', (_)=>_.description('Number of nodes to return'));
1973
+ }
1974
+ }
1975
+ function offsetLimitPaginationPlugin() {
1976
+ return new OffsetLimitPaginationPlugin();
1977
+ }
1978
+ class MultiPlugin {
1979
+ getPlugins() {
1980
+ return [];
1981
+ }
1982
+ async execute(methodName, fn) {
1983
+ const results = [];
1984
+ for (const plugin of this._plugins)if (plugin[methodName]) {
1985
+ const result = await fn(plugin);
1986
+ results.push(result);
1987
+ }
1988
+ return results;
1989
+ }
1990
+ executeSync(methodName, fn) {
1991
+ const results = [];
1992
+ for (const plugin of this._plugins)if (plugin[methodName]) {
1993
+ const result = fn(plugin);
1994
+ results.push(result);
1995
+ }
1996
+ return results;
1997
+ }
1998
+ async beforeFinalizeSchema(builder) {
1999
+ await this.execute('beforeFinalizeSchema', (plugin)=>plugin.beforeFinalizeSchema(builder));
2000
+ }
2001
+ async afterFinalizeSchema(builder) {
2002
+ await this.execute('afterFinalizeSchema', (plugin)=>plugin.afterFinalizeSchema(builder));
2003
+ }
2004
+ async beforeFinalizeObjectType(builder, context, info) {
2005
+ await this.execute('beforeFinalizeObjectType', (plugin)=>plugin.beforeFinalizeObjectType(builder, context, info));
2006
+ }
2007
+ async afterFinalizeObjectType(builder, context, info) {
2008
+ await this.execute('afterFinalizeObjectType', (plugin)=>plugin.afterFinalizeObjectType(builder, context, info));
2009
+ }
2010
+ async beforeFinalizeInputObjectType(builder, context, info) {
2011
+ await this.execute('beforeFinalizeInputObjectType', (plugin)=>plugin.beforeFinalizeInputObjectType(builder, context, info));
2012
+ }
2013
+ async afterFinalizeInputObjectType(builder, context, info) {
2014
+ await this.execute('afterFinalizeInputObjectType', (plugin)=>plugin.afterFinalizeInputObjectType(builder, context, info));
2015
+ }
2016
+ async beforeFinalizeEnumType(builder, context, info) {
2017
+ await this.execute('beforeFinalizeEnumType', (plugin)=>plugin.beforeFinalizeEnumType(builder, context, info));
2018
+ }
2019
+ async afterFinalizeEnumType(builder, context, info) {
2020
+ await this.execute('afterFinalizeEnumType', (plugin)=>plugin.afterFinalizeEnumType(builder, context, info));
2021
+ }
2022
+ async beforeFinalizeEnumValue(builder, context, info) {
2023
+ await this.execute('beforeFinalizeEnumValue', (plugin)=>plugin.beforeFinalizeEnumValue(builder, context, info));
2024
+ }
2025
+ async afterFinalizeEnumValue(builder, context, info) {
2026
+ await this.execute('afterFinalizeEnumValue', (plugin)=>plugin.afterFinalizeEnumValue(builder, context, info));
2027
+ }
2028
+ async beforeFinalizeUnionType(builder, context, info) {
2029
+ await this.execute('beforeFinalizeUnionType', (plugin)=>plugin.beforeFinalizeUnionType(builder, context, info));
2030
+ }
2031
+ async afterFinalizeUnionType(builder, context, info) {
2032
+ await this.execute('afterFinalizeUnionType', (plugin)=>plugin.afterFinalizeUnionType(builder, context, info));
2033
+ }
2034
+ async beforeFinalizeField(builder, context, info) {
2035
+ await this.execute('beforeFinalizeField', (plugin)=>plugin.beforeFinalizeField(builder, context, info));
2036
+ }
2037
+ async afterFinalizeField(builder, context, info) {
2038
+ await this.execute('afterFinalizeField', (plugin)=>plugin.afterFinalizeField(builder, context, info));
2039
+ }
2040
+ async beforeFinalizeInputField(builder, context, info) {
2041
+ await this.execute('beforeFinalizeInputField', (plugin)=>plugin.beforeFinalizeInputField(builder, context, info));
2042
+ }
2043
+ async afterFinalizeInputField(builder, context, info) {
2044
+ await this.execute('afterFinalizeInputField', (plugin)=>plugin.afterFinalizeInputField(builder, context, info));
2045
+ }
2046
+ async beforeFinalizeArgument(builder, context, info) {
2047
+ await this.execute('beforeFinalizeArgument', (plugin)=>plugin.beforeFinalizeArgument(builder, context, info));
2048
+ }
2049
+ async afterFinalizeArgument(builder, context, info) {
2050
+ await this.execute('afterFinalizeArgument', (plugin)=>plugin.afterFinalizeArgument(builder, context, info));
2051
+ }
2052
+ beforeBuild(rootBuilder) {
2053
+ this.executeSync('beforeBuild', (plugin)=>plugin.beforeBuild(rootBuilder));
2054
+ }
2055
+ afterBuild(rootBuilder, schema) {
2056
+ this.executeSync('afterBuild', (plugin)=>plugin.afterBuild(rootBuilder, schema));
2057
+ }
2058
+ beforeBuildSchema(builder, rootBuilder) {
2059
+ this.executeSync('beforeBuildSchema', (plugin)=>plugin.beforeBuildSchema(builder, rootBuilder));
2060
+ }
2061
+ afterBuildSchema(builder, schema, rootBuilder) {
2062
+ this.executeSync('afterBuildSchema', (plugin)=>plugin.afterBuildSchema(builder, schema, rootBuilder));
2063
+ }
2064
+ beforeBuildObjectType(builder, context, info) {
2065
+ this.executeSync('beforeBuildObjectType', (plugin)=>plugin.beforeBuildObjectType(builder, context, info));
2066
+ }
2067
+ afterBuildObjectType(builder, context, info, objectType) {
2068
+ this.executeSync('afterBuildObjectType', (plugin)=>plugin.afterBuildObjectType(builder, context, info, objectType));
2069
+ }
2070
+ beforeBuildInputObjectType(builder, context, info) {
2071
+ this.executeSync('beforeBuildInputObjectType', (plugin)=>plugin.beforeBuildInputObjectType(builder, context, info));
2072
+ }
2073
+ afterBuildInputObjectType(builder, context, info, inputObjectType) {
2074
+ this.executeSync('afterBuildInputObjectType', (plugin)=>plugin.afterBuildInputObjectType(builder, context, info, inputObjectType));
2075
+ }
2076
+ beforeBuildEnumType(builder, context, info) {
2077
+ this.executeSync('beforeBuildEnumType', (plugin)=>plugin.beforeBuildEnumType(builder, context, info));
2078
+ }
2079
+ afterBuildEnumType(builder, context, info, enumType) {
2080
+ this.executeSync('afterBuildEnumType', (plugin)=>plugin.afterBuildEnumType(builder, context, info, enumType));
2081
+ }
2082
+ beforeBuildEnumValue(builder, context, info) {
2083
+ this.executeSync('beforeBuildEnumValue', (plugin)=>plugin.beforeBuildEnumValue(builder, context, info));
2084
+ }
2085
+ afterBuildEnumValue(builder, context, info, enumValue) {
2086
+ this.executeSync('afterBuildEnumValue', (plugin)=>plugin.afterBuildEnumValue(builder, context, info, enumValue));
2087
+ }
2088
+ beforeBuildUnionType(builder, context, info) {
2089
+ this.executeSync('beforeBuildUnionType', (plugin)=>plugin.beforeBuildUnionType(builder, context, info));
2090
+ }
2091
+ afterBuildUnionType(builder, context, info, unionType) {
2092
+ this.executeSync('afterBuildUnionType', (plugin)=>plugin.afterBuildUnionType(builder, context, info, unionType));
2093
+ }
2094
+ beforeBuildField(builder, context, info) {
2095
+ this.executeSync('beforeBuildField', (plugin)=>plugin.beforeBuildField(builder, context, info));
2096
+ }
2097
+ afterBuildField(builder, context, info, field) {
2098
+ this.executeSync('afterBuildField', (plugin)=>plugin.afterBuildField(builder, context, info, field));
2099
+ }
2100
+ beforeBuildInputField(builder, context, info) {
2101
+ this.executeSync('beforeBuildInputField', (plugin)=>plugin.beforeBuildInputField(builder, context, info));
2102
+ }
2103
+ afterBuildInputField(builder, context, info, inputField) {
2104
+ this.executeSync('afterBuildInputField', (plugin)=>plugin.afterBuildInputField(builder, context, info, inputField));
2105
+ }
2106
+ beforeBuildArgument(builder, context, info) {
2107
+ this.executeSync('beforeBuildArgument', (plugin)=>plugin.beforeBuildArgument(builder, context, info));
2108
+ }
2109
+ afterBuildArgument(builder, context, info, argument) {
2110
+ this.executeSync('afterBuildArgument', (plugin)=>plugin.afterBuildArgument(builder, context, info, argument));
2111
+ }
2112
+ constructor(plugins = null){
2113
+ this._plugins = plugins || this.getPlugins();
2114
+ }
2115
+ }
2116
+ const plugin_MultiPlugin = MultiPlugin;
2117
+ class RelayPaginationPlugin extends plugin_MultiPlugin {
2118
+ getPlugins() {
2119
+ this._firstAfterPlugin = new FirstAfterPaginationPlugin();
2120
+ this._connectionPlugin = new ConnectionPaginationPlugin();
2121
+ return [
2122
+ this._firstAfterPlugin,
2123
+ this._connectionPlugin
2124
+ ];
2125
+ }
2126
+ totalCount(totalCount = true) {
2127
+ this._connectionPlugin.totalCount(totalCount);
2128
+ return this;
2129
+ }
2130
+ }
2131
+ function relayPaginationPlugin() {
2132
+ return new RelayPaginationPlugin();
2133
+ }
2134
+ class SimplePaginationPlugin extends plugin_MultiPlugin {
2135
+ getPlugins() {
2136
+ return [
2137
+ new OffsetLimitPaginationPlugin(),
2138
+ new ItemsPaginationPlugin()
2139
+ ];
2140
+ }
2141
+ }
2142
+ function simplePaginationPlugin() {
2143
+ return new SimplePaginationPlugin();
2144
+ }
2145
+ var sort_SortDirection = /*#__PURE__*/ function(SortDirection) {
2146
+ SortDirection["ASC"] = "ASC";
2147
+ SortDirection["DESC"] = "DESC";
2148
+ return SortDirection;
2149
+ }({});
2150
+ const defaultSortPluginOptions = {
2151
+ multi: false,
2152
+ directionEnumName: 'SortDirection',
2153
+ argumentName: 'sort',
2154
+ inputName: (typeName)=>`${typeName}SortConfiguration`,
2155
+ fieldEnumName: (typeName)=>`${typeName}SortField`
2156
+ };
2157
+ class SortPlugin {
2158
+ multi(multi = true) {
2159
+ this._options.multi = multi;
2160
+ return this;
2161
+ }
2162
+ field(...fieldNames) {
2163
+ if (!this._options.fields) this._options.fields = [];
2164
+ fieldNames.forEach((name)=>this._options.fields.push(name));
2165
+ return this;
2166
+ }
2167
+ exclude(...fieldNames) {
2168
+ fieldNames.forEach((name)=>this._options.exclude.push(name));
2169
+ return this;
2170
+ }
2171
+ include(...fieldNames) {
2172
+ fieldNames.forEach((name)=>this._options.include.push(name));
2173
+ return this;
2174
+ }
2175
+ directionEnumName(name) {
2176
+ this._options.directionEnumName = name;
2177
+ return this;
2178
+ }
2179
+ argumentName(name) {
2180
+ this._options.argumentName = name;
2181
+ return this;
2182
+ }
2183
+ inputName(nameFactory) {
2184
+ this._options.inputName = nameFactory;
2185
+ return this;
2186
+ }
2187
+ fieldEnumName(nameFactory) {
2188
+ this._options.fieldEnumName = nameFactory;
2189
+ return this;
2190
+ }
2191
+ beforeBuildField(builder, context, info) {
2192
+ if (!info.list) return;
2193
+ if (!context.schema.hasType(this._options.directionEnumName)) context.schema.enum(this._createSortDirectionEnum());
2194
+ const typeName = info.type.toString();
2195
+ const inputTypeName = this._options.inputName(typeName);
2196
+ const fieldEnumName = this._options.fieldEnumName(typeName);
2197
+ let targetObjectType;
2198
+ if (!this._options.fields) {
2199
+ targetObjectType = context.rootSchema.findType(typeName, true);
2200
+ if (!targetObjectType) throw new PluginError(`Sort target object "${typeName}" not found`);
2201
+ if (!(targetObjectType instanceof ObjectTypeBuilder)) throw new PluginError(`Sort target "${typeName}" is not an object type`);
2202
+ }
2203
+ const enumType = this._createSortFieldEnum(context, fieldEnumName, typeName, targetObjectType);
2204
+ context.schema.enum(enumType);
2205
+ const inputType = this._createSortInputType(inputTypeName, fieldEnumName);
2206
+ context.schema.inputObject(inputType);
2207
+ builder.arg(this._options.argumentName, inputTypeName, (_)=>{
2208
+ if (this._options.multi) _.list().description('Collection of sort configurations');
2209
+ else _.description('Sort configuration');
2210
+ });
2211
+ }
2212
+ _createSortInputType(name, enumName) {
2213
+ return ts_inputObjectType(name).description("Configuration for how the nodes should be sorted").field('field', enumName, (_)=>_.nonNull().description('Field to sort on')).field('direction', this._options.directionEnumName, (_)=>_.nonNull().description('Direction to sort'));
2214
+ }
2215
+ _createSortFieldEnum(context, name, typeName, targetObjectType) {
2216
+ const enumBuilder = ts_enumType(name).description(`Field to sort ${typeName} on`);
2217
+ const fields = new Set();
2218
+ if (targetObjectType) for (const field of targetObjectType.info().fields){
2219
+ const fieldInfo = field.info();
2220
+ if (!fieldInfo.list && isTypeInput(fieldInfo.type, context.rootSchema)) fields.add(field.name);
2221
+ }
2222
+ else if (this._options.fields) this._options.fields.forEach((field)=>fields.add(field));
2223
+ if (this._options.include) this._options.include.forEach((field)=>fields.add(field));
2224
+ const extraValues = this._getExtraEnumValues(context, name, typeName, targetObjectType);
2225
+ if (extraValues) extraValues.forEach((extraField)=>fields.add(extraField));
2226
+ for (const field of fields)if (!(this._options.exclude && this._options.exclude.indexOf(field) >= 0)) enumBuilder.value(field, field);
2227
+ return enumBuilder;
2228
+ }
2229
+ _createSortDirectionEnum() {
2230
+ return ts_enumType(this._options.directionEnumName).description('Direction to sort').value("ASC", "ASC", (_)=>_.description('Sort ascending')).value("DESC", "DESC", (_)=>_.description('Sort descending'));
2231
+ }
2232
+ _getExtraEnumValues(context, name, typeName, targetObjectType) {
2233
+ return null;
2234
+ }
2235
+ constructor(options){
2236
+ this._options = (0, compat_namespaceObject.defaults)(options || {}, defaultSortPluginOptions, {
2237
+ exclude: [],
2238
+ include: []
2239
+ });
2240
+ }
2241
+ }
2242
+ function sortPlugin(options) {
2243
+ return new SortPlugin(options);
2244
+ }
2245
+ const ts_rslib_entry_ = ts_schema;
2246
+ var __webpack_export_target__ = exports;
2247
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
2248
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
2249
+ value: true
2250
+ });