@graphql-inspector/similar-command 3.4.2 → 3.4.3-alpha-20230215160253-30a6364f

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 (3) hide show
  1. package/index.js +31 -32
  2. package/index.mjs +31 -32
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -14,40 +14,39 @@ function handler({ schema, writePath, type, threshold, }) {
14
14
  const similarMap = core.similar(schema, type, threshold);
15
15
  if (!Object.keys(similarMap).length) {
16
16
  logger.Logger.info('No similar types found');
17
+ return;
17
18
  }
18
- else {
19
- for (const typeName in similarMap) {
20
- if (Object.prototype.hasOwnProperty.call(similarMap, typeName)) {
21
- const matches = similarMap[typeName];
22
- const prefix = core.getTypePrefix(schema.getType(typeName));
23
- const sourceType = logger.chalk.bold(typeName);
24
- const name = matches.bestMatch.target.typeId;
25
- logger.Logger.log('');
26
- logger.Logger.log(`${prefix} ${sourceType}`);
27
- logger.Logger.log(printResult(name, matches.bestMatch.rating));
28
- matches.ratings.forEach(match => {
29
- logger.Logger.log(printResult(match.target.typeId, match.rating));
30
- });
31
- }
19
+ for (const typeName in similarMap) {
20
+ if (Object.prototype.hasOwnProperty.call(similarMap, typeName)) {
21
+ const matches = similarMap[typeName];
22
+ const prefix = core.getTypePrefix(schema.getType(typeName));
23
+ const sourceType = logger.chalk.bold(typeName);
24
+ const name = matches.bestMatch.target.typeId;
25
+ logger.Logger.log('');
26
+ logger.Logger.log(`${prefix} ${sourceType}`);
27
+ logger.Logger.log(printResult(name, matches.bestMatch.rating));
28
+ matches.ratings.forEach(match => {
29
+ logger.Logger.log(printResult(match.target.typeId, match.rating));
30
+ });
32
31
  }
33
- if (shouldWrite) {
34
- if (typeof writePath !== 'string') {
35
- throw new Error(`--write is not valid file path: ${writePath}`);
36
- }
37
- const absPath = commands.ensureAbsolute(writePath);
38
- const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
39
- let output = undefined;
40
- const results = transformMap(similarMap);
41
- if (ext === 'json') {
42
- output = outputJSON(results);
43
- }
44
- if (output) {
45
- fs.writeFileSync(absPath, output, 'utf8');
46
- logger.Logger.success(`Available at ${absPath}\n`);
47
- }
48
- else {
49
- throw new Error(`Extension ${ext} is not supported`);
50
- }
32
+ }
33
+ if (shouldWrite) {
34
+ if (typeof writePath !== 'string') {
35
+ throw new Error(`--write is not valid file path: ${writePath}`);
36
+ }
37
+ const absPath = commands.ensureAbsolute(writePath);
38
+ const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
39
+ let output = undefined;
40
+ const results = transformMap(similarMap);
41
+ if (ext === 'json') {
42
+ output = outputJSON(results);
43
+ }
44
+ if (output) {
45
+ fs.writeFileSync(absPath, output, 'utf8');
46
+ logger.Logger.success(`Available at ${absPath}\n`);
47
+ }
48
+ else {
49
+ throw new Error(`Extension ${ext} is not supported`);
51
50
  }
52
51
  }
53
52
  }
package/index.mjs CHANGED
@@ -10,40 +10,39 @@ function handler({ schema, writePath, type, threshold, }) {
10
10
  const similarMap = similar(schema, type, threshold);
11
11
  if (!Object.keys(similarMap).length) {
12
12
  Logger.info('No similar types found');
13
+ return;
13
14
  }
14
- else {
15
- for (const typeName in similarMap) {
16
- if (Object.prototype.hasOwnProperty.call(similarMap, typeName)) {
17
- const matches = similarMap[typeName];
18
- const prefix = getTypePrefix(schema.getType(typeName));
19
- const sourceType = chalk.bold(typeName);
20
- const name = matches.bestMatch.target.typeId;
21
- Logger.log('');
22
- Logger.log(`${prefix} ${sourceType}`);
23
- Logger.log(printResult(name, matches.bestMatch.rating));
24
- matches.ratings.forEach(match => {
25
- Logger.log(printResult(match.target.typeId, match.rating));
26
- });
27
- }
15
+ for (const typeName in similarMap) {
16
+ if (Object.prototype.hasOwnProperty.call(similarMap, typeName)) {
17
+ const matches = similarMap[typeName];
18
+ const prefix = getTypePrefix(schema.getType(typeName));
19
+ const sourceType = chalk.bold(typeName);
20
+ const name = matches.bestMatch.target.typeId;
21
+ Logger.log('');
22
+ Logger.log(`${prefix} ${sourceType}`);
23
+ Logger.log(printResult(name, matches.bestMatch.rating));
24
+ matches.ratings.forEach(match => {
25
+ Logger.log(printResult(match.target.typeId, match.rating));
26
+ });
28
27
  }
29
- if (shouldWrite) {
30
- if (typeof writePath !== 'string') {
31
- throw new Error(`--write is not valid file path: ${writePath}`);
32
- }
33
- const absPath = ensureAbsolute(writePath);
34
- const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
35
- let output = undefined;
36
- const results = transformMap(similarMap);
37
- if (ext === 'json') {
38
- output = outputJSON(results);
39
- }
40
- if (output) {
41
- writeFileSync(absPath, output, 'utf8');
42
- Logger.success(`Available at ${absPath}\n`);
43
- }
44
- else {
45
- throw new Error(`Extension ${ext} is not supported`);
46
- }
28
+ }
29
+ if (shouldWrite) {
30
+ if (typeof writePath !== 'string') {
31
+ throw new Error(`--write is not valid file path: ${writePath}`);
32
+ }
33
+ const absPath = ensureAbsolute(writePath);
34
+ const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
35
+ let output = undefined;
36
+ const results = transformMap(similarMap);
37
+ if (ext === 'json') {
38
+ output = outputJSON(results);
39
+ }
40
+ if (output) {
41
+ writeFileSync(absPath, output, 'utf8');
42
+ Logger.success(`Available at ${absPath}\n`);
43
+ }
44
+ else {
45
+ throw new Error(`Extension ${ext} is not supported`);
47
46
  }
48
47
  }
49
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-inspector/similar-command",
3
- "version": "3.4.2",
3
+ "version": "3.4.3-alpha-20230215160253-30a6364f",
4
4
  "description": "Find similar types in GraphQL Schema",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -8,8 +8,8 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@graphql-inspector/commands": "3.4.1",
11
- "@graphql-inspector/core": "3.5.0",
12
- "@graphql-inspector/logger": "3.4.0",
11
+ "@graphql-inspector/core": "3.5.1",
12
+ "@graphql-inspector/logger": "3.4.2-alpha-20230215160253-30a6364f",
13
13
  "tslib": "^2.0.0"
14
14
  },
15
15
  "repository": {