@kiwano/core 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,10 @@ import { EntityType } from "./entitySchema";
4
4
  export declare class CreateInputObjectTypeBuilder extends InputObjectTypeBuilder {
5
5
  protected _entityObjectType: EntityType;
6
6
  protected _exclude: Set<string>;
7
+ protected _include: Set<string>;
7
8
  constructor(name: BuilderName, entityType: EntityType);
8
9
  exclude(...fieldNames: string[]): this;
10
+ include(...fieldNames: string[]): this;
9
11
  finalizeInputObjectType(context: FinalizeContext, info: InputObjectTypeBuilderInfo): Promise<any>;
10
12
  }
11
13
  export declare function createInputObjectType(name: BuilderName, entityType: EntityType): CreateInputObjectTypeBuilder;
@@ -9,12 +9,17 @@ class CreateInputObjectTypeBuilder extends inputObjectType_1.InputObjectTypeBuil
9
9
  constructor(name, entityType) {
10
10
  super(name);
11
11
  this._exclude = new Set();
12
+ this._include = new Set();
12
13
  this._entityObjectType = entityType;
13
14
  }
14
15
  exclude(...fieldNames) {
15
16
  fieldNames.forEach(name => this._exclude.add(name));
16
17
  return this;
17
18
  }
19
+ include(...fieldNames) {
20
+ fieldNames.forEach(name => this._include.add(name));
21
+ return this;
22
+ }
18
23
  async finalizeInputObjectType(context, info) {
19
24
  await super.finalizeInputObjectType(context, info);
20
25
  const entity = this._entityObjectType instanceof objectType_1.ObjectTypeBuilder ? this._entityObjectType : this._entityObjectType();
@@ -22,7 +27,10 @@ class CreateInputObjectTypeBuilder extends inputObjectType_1.InputObjectTypeBuil
22
27
  const existingFieldNames = info.fields.map(field => field.name);
23
28
  for (let field of entityInfo.fields) {
24
29
  const fieldInfo = field.info();
25
- if (this._exclude.has(fieldInfo.name) || !(0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema) || (0, util_1.isFieldId)(fieldInfo) || existingFieldNames.indexOf(fieldInfo.name) >= 0) {
30
+ if (!(0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema) || (0, util_1.isFieldId)(fieldInfo) || existingFieldNames.indexOf(fieldInfo.name) >= 0) {
31
+ continue;
32
+ }
33
+ if (this._exclude.has(fieldInfo.name) || (this._include.size > 0 && !this._include.has(fieldInfo.name))) {
26
34
  continue;
27
35
  }
28
36
  const inputField = new inputField_1.InputFieldBuilder(fieldInfo.name, fieldInfo.type);
@@ -4,8 +4,10 @@ import { EntityType } from "./entitySchema";
4
4
  export declare class UpdateInputObjectTypeBuilder extends InputObjectTypeBuilder {
5
5
  protected _entityObjectType: EntityType;
6
6
  protected _exclude: Set<string>;
7
+ protected _include: Set<string>;
7
8
  constructor(name: BuilderName, entityType: EntityType);
8
9
  exclude(...fieldNames: string[]): this;
10
+ include(...fieldNames: string[]): this;
9
11
  finalizeInputObjectType(context: FinalizeContext, info: InputObjectTypeBuilderInfo): Promise<any>;
10
12
  }
11
13
  export declare function updateInputObjectType(name: BuilderName, entityType: EntityType): UpdateInputObjectTypeBuilder;
@@ -9,12 +9,17 @@ class UpdateInputObjectTypeBuilder extends inputObjectType_1.InputObjectTypeBuil
9
9
  constructor(name, entityType) {
10
10
  super(name);
11
11
  this._exclude = new Set();
12
+ this._include = new Set();
12
13
  this._entityObjectType = entityType;
13
14
  }
14
15
  exclude(...fieldNames) {
15
16
  fieldNames.forEach(name => this._exclude.add(name));
16
17
  return this;
17
18
  }
19
+ include(...fieldNames) {
20
+ fieldNames.forEach(name => this._include.add(name));
21
+ return this;
22
+ }
18
23
  async finalizeInputObjectType(context, info) {
19
24
  await super.finalizeInputObjectType(context, info);
20
25
  const entity = this._entityObjectType instanceof objectType_1.ObjectTypeBuilder ? this._entityObjectType : this._entityObjectType();
@@ -22,7 +27,10 @@ class UpdateInputObjectTypeBuilder extends inputObjectType_1.InputObjectTypeBuil
22
27
  const existingFieldNames = info.fields.map(field => field.name);
23
28
  for (let field of entityInfo.fields) {
24
29
  const fieldInfo = field.info();
25
- if (this._exclude.has(fieldInfo.name) || !(0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema) || existingFieldNames.indexOf(fieldInfo.name) >= 0) {
30
+ if (!(0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema) || existingFieldNames.indexOf(fieldInfo.name) >= 0) {
31
+ continue;
32
+ }
33
+ if (this._exclude.has(fieldInfo.name) || (this._include.size > 0 && !this._include.has(fieldInfo.name))) {
26
34
  continue;
27
35
  }
28
36
  const inputField = new inputField_1.InputFieldBuilder(fieldInfo.name, fieldInfo.type);
@@ -6,9 +6,10 @@ import { Plugin } from "../common";
6
6
  import { BuildContext } from "../../Builder";
7
7
  export interface EqualsFilterPluginOptions {
8
8
  multi?: boolean;
9
+ manual?: boolean;
9
10
  fields?: EqualsFilterPluginFieldConfig[];
10
11
  exclude?: string[];
11
- include?: EqualsFilterPluginFieldConfig[];
12
+ include?: string[];
12
13
  argumentName?: string;
13
14
  inputName?: (typeName: string) => string;
14
15
  }
@@ -22,9 +23,11 @@ export declare class EqualsFilterPlugin implements Plugin {
22
23
  constructor(options?: EqualsFilterPluginOptions);
23
24
  multi(): this;
24
25
  multi(multi: boolean): this;
26
+ manual(): this;
27
+ manual(manual: boolean): this;
25
28
  field(name: string, type: InputFieldType): this;
26
29
  exclude(...fieldNames: string[]): this;
27
- include(name: string, type: InputFieldType): this;
30
+ include(...fieldNames: string[]): this;
28
31
  argumentName(name: string): this;
29
32
  inputName(nameFactory: (typeName: string) => string): this;
30
33
  beforeBuildField(builder: FieldBuilder, context: BuildContext, info: FieldBuilderInfo): void;
@@ -11,6 +11,7 @@ const util_1 = require("../../util");
11
11
  const PluginError_1 = __importDefault(require("../PluginError"));
12
12
  exports.defaultEqualsFilterPluginOptions = {
13
13
  multi: false,
14
+ manual: false,
14
15
  argumentName: 'filter',
15
16
  inputName: typeName => `${typeName}EqualsFilter`,
16
17
  };
@@ -25,6 +26,10 @@ class EqualsFilterPlugin {
25
26
  this._options.multi = multi;
26
27
  return this;
27
28
  }
29
+ manual(manual = true) {
30
+ this._options.manual = manual;
31
+ return this;
32
+ }
28
33
  field(name, type) {
29
34
  if (!this._options.fields) {
30
35
  this._options.fields = [];
@@ -36,8 +41,8 @@ class EqualsFilterPlugin {
36
41
  fieldNames.forEach(name => this._options.exclude.push(name));
37
42
  return this;
38
43
  }
39
- include(name, type) {
40
- this._options.include.push({ name, type });
44
+ include(...fieldNames) {
45
+ fieldNames.forEach(name => this._options.include.push(name));
41
46
  return this;
42
47
  }
43
48
  argumentName(name) {
@@ -55,7 +60,7 @@ class EqualsFilterPlugin {
55
60
  const typeName = info.type.toString();
56
61
  const inputTypeName = this._options.inputName(typeName);
57
62
  let targetObjectType;
58
- if (!this._options.fields) {
63
+ if (!this._options.manual) {
59
64
  targetObjectType = context.rootSchema.findType(typeName, true);
60
65
  if (!targetObjectType) {
61
66
  throw new PluginError_1.default(`Filter target object ${typeName} not found`);
@@ -69,26 +74,28 @@ class EqualsFilterPlugin {
69
74
  builder.arg(this._options.argumentName, inputTypeName, _ => _.description(`Configuration for how the nodes should be filtered`));
70
75
  }
71
76
  _createFilterInputType(context, name, targetObjectType) {
77
+ var _a;
72
78
  const inputObjectType = (0, inputObjectType_1.default)(name)
73
79
  .description(`Configuration for how the nodes should be filtered`);
74
80
  let fields = new Set();
75
81
  if (targetObjectType) {
76
82
  for (let field of targetObjectType.info().fields) {
77
83
  const fieldInfo = field.info();
78
- if (!fieldInfo.list && (0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema)) {
79
- fields.add({
80
- name: field.name,
81
- type: fieldInfo.type
82
- });
84
+ if (fieldInfo.list || !(0, util_1.isTypeInput)(fieldInfo.type, context.rootSchema)) {
85
+ continue;
83
86
  }
87
+ if (((_a = this._options.include) === null || _a === void 0 ? void 0 : _a.length) && !this._options.include.includes(field.name)) {
88
+ continue;
89
+ }
90
+ fields.add({
91
+ name: field.name,
92
+ type: fieldInfo.type
93
+ });
84
94
  }
85
95
  }
86
- else if (this._options.fields) {
96
+ if (this._options.fields) {
87
97
  this._options.fields.forEach(field => fields.add(field));
88
98
  }
89
- if (this._options.include) {
90
- this._options.include.forEach(field => fields.add(field));
91
- }
92
99
  const extraFields = this._getExtraFieldConfigs(context, name, targetObjectType);
93
100
  if (extraFields) {
94
101
  extraFields.forEach(extraField => fields.add(extraField));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiwano/core",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",