@graphql-inspector/similar-command 0.0.0-canary.9cf9b2c → 0.0.0-canary.e88122e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- import { GlobalArgs } from '@graphql-inspector/commands';
2
- declare const _default: import("../../commands/src").CommandFactory<{}, {
1
+ import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
2
+ import { GraphQLSchema } from 'graphql';
3
+ export { CommandFactory };
4
+ export declare function handler({ schema, writePath, type, threshold, }: {
5
+ schema: GraphQLSchema;
6
+ writePath?: string;
7
+ type?: string;
8
+ threshold?: number;
9
+ }): void;
10
+ declare const _default: CommandFactory<{}, {
3
11
  schema: string;
4
12
  name?: string | undefined;
5
13
  threshold?: number | undefined;
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  const tslib = require('tslib');
4
6
  const commands = require('@graphql-inspector/commands');
5
7
  const logger = require('@graphql-inspector/logger');
@@ -7,7 +9,52 @@ const core = require('@graphql-inspector/core');
7
9
  const path = require('path');
8
10
  const fs = require('fs');
9
11
 
12
+ function handler({ schema, writePath, type, threshold, }) {
13
+ const shouldWrite = typeof writePath !== 'undefined';
14
+ const similarMap = core.similar(schema, type, threshold);
15
+ if (!Object.keys(similarMap).length) {
16
+ logger.Logger.info('No similar types found');
17
+ }
18
+ else {
19
+ for (const typeName in similarMap) {
20
+ if (similarMap.hasOwnProperty(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
+ }
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, {
46
+ encoding: 'utf-8',
47
+ });
48
+ logger.Logger.success(`Available at ${absPath}\n`);
49
+ }
50
+ else {
51
+ throw new Error(`Extension ${ext} is not supported`);
52
+ }
53
+ }
54
+ }
55
+ }
10
56
  const index = commands.createCommand((api) => {
57
+ const { loaders } = api;
11
58
  return {
12
59
  command: 'similar <schema>',
13
60
  describe: 'Find similar types in a schema',
@@ -37,56 +84,21 @@ const index = commands.createCommand((api) => {
37
84
  });
38
85
  },
39
86
  handler(args) {
87
+ var _a;
40
88
  return tslib.__awaiter(this, void 0, void 0, function* () {
41
- const { loaders } = api;
42
89
  const { headers, token } = commands.parseGlobalArgs(args);
43
90
  const writePath = args.write;
44
- const shouldWrite = typeof writePath !== 'undefined';
91
+ const type = args.name;
92
+ const threshold = args.threshold;
93
+ const apolloFederation = args.federation || false;
94
+ const aws = args.aws || false;
95
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
45
96
  const schema = yield loaders.loadSchema(args.schema, {
46
97
  headers,
47
98
  token,
48
- });
49
- const similarMap = core.similar(schema, args.name, args.threshold);
50
- if (!Object.keys(similarMap).length) {
51
- logger.Logger.info('No similar types found');
52
- }
53
- else {
54
- for (const typeName in similarMap) {
55
- if (similarMap.hasOwnProperty(typeName)) {
56
- const matches = similarMap[typeName];
57
- const prefix = core.getTypePrefix(schema.getType(typeName));
58
- const sourceType = logger.chalk.bold(typeName);
59
- const name = matches.bestMatch.target.typeId;
60
- logger.Logger.log('');
61
- logger.Logger.log(`${prefix} ${sourceType}`);
62
- logger.Logger.log(printResult(name, matches.bestMatch.rating));
63
- matches.ratings.forEach((match) => {
64
- logger.Logger.log(printResult(match.target.typeId, match.rating));
65
- });
66
- }
67
- }
68
- if (shouldWrite) {
69
- if (typeof writePath !== 'string') {
70
- throw new Error(`--write is not valid file path: ${writePath}`);
71
- }
72
- const absPath = commands.ensureAbsolute(writePath);
73
- const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
74
- let output = undefined;
75
- const results = transformMap(similarMap);
76
- if (ext === 'json') {
77
- output = outputJSON(results);
78
- }
79
- if (output) {
80
- fs.writeFileSync(absPath, output, {
81
- encoding: 'utf-8',
82
- });
83
- logger.Logger.success(`Available at ${absPath}\n`);
84
- }
85
- else {
86
- throw new Error(`Extension ${ext} is not supported`);
87
- }
88
- }
89
- }
99
+ method,
100
+ }, apolloFederation, aws);
101
+ return handler({ schema, writePath, type, threshold });
90
102
  });
91
103
  },
92
104
  };
@@ -135,5 +147,5 @@ function formatRating(ratio) {
135
147
  return Math.floor(ratio * 100);
136
148
  }
137
149
 
138
- module.exports = index;
139
- //# sourceMappingURL=index.cjs.js.map
150
+ exports.default = index;
151
+ exports.handler = handler;
@@ -5,7 +5,52 @@ import { similar, getTypePrefix } from '@graphql-inspector/core';
5
5
  import { extname } from 'path';
6
6
  import { writeFileSync } from 'fs';
7
7
 
8
+ function handler({ schema, writePath, type, threshold, }) {
9
+ const shouldWrite = typeof writePath !== 'undefined';
10
+ const similarMap = similar(schema, type, threshold);
11
+ if (!Object.keys(similarMap).length) {
12
+ Logger.info('No similar types found');
13
+ }
14
+ else {
15
+ for (const typeName in similarMap) {
16
+ if (similarMap.hasOwnProperty(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
+ }
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, {
42
+ encoding: 'utf-8',
43
+ });
44
+ Logger.success(`Available at ${absPath}\n`);
45
+ }
46
+ else {
47
+ throw new Error(`Extension ${ext} is not supported`);
48
+ }
49
+ }
50
+ }
51
+ }
8
52
  const index = createCommand((api) => {
53
+ const { loaders } = api;
9
54
  return {
10
55
  command: 'similar <schema>',
11
56
  describe: 'Find similar types in a schema',
@@ -35,56 +80,21 @@ const index = createCommand((api) => {
35
80
  });
36
81
  },
37
82
  handler(args) {
83
+ var _a;
38
84
  return __awaiter(this, void 0, void 0, function* () {
39
- const { loaders } = api;
40
85
  const { headers, token } = parseGlobalArgs(args);
41
86
  const writePath = args.write;
42
- const shouldWrite = typeof writePath !== 'undefined';
87
+ const type = args.name;
88
+ const threshold = args.threshold;
89
+ const apolloFederation = args.federation || false;
90
+ const aws = args.aws || false;
91
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
43
92
  const schema = yield loaders.loadSchema(args.schema, {
44
93
  headers,
45
94
  token,
46
- });
47
- const similarMap = similar(schema, args.name, args.threshold);
48
- if (!Object.keys(similarMap).length) {
49
- Logger.info('No similar types found');
50
- }
51
- else {
52
- for (const typeName in similarMap) {
53
- if (similarMap.hasOwnProperty(typeName)) {
54
- const matches = similarMap[typeName];
55
- const prefix = getTypePrefix(schema.getType(typeName));
56
- const sourceType = chalk.bold(typeName);
57
- const name = matches.bestMatch.target.typeId;
58
- Logger.log('');
59
- Logger.log(`${prefix} ${sourceType}`);
60
- Logger.log(printResult(name, matches.bestMatch.rating));
61
- matches.ratings.forEach((match) => {
62
- Logger.log(printResult(match.target.typeId, match.rating));
63
- });
64
- }
65
- }
66
- if (shouldWrite) {
67
- if (typeof writePath !== 'string') {
68
- throw new Error(`--write is not valid file path: ${writePath}`);
69
- }
70
- const absPath = ensureAbsolute(writePath);
71
- const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
72
- let output = undefined;
73
- const results = transformMap(similarMap);
74
- if (ext === 'json') {
75
- output = outputJSON(results);
76
- }
77
- if (output) {
78
- writeFileSync(absPath, output, {
79
- encoding: 'utf-8',
80
- });
81
- Logger.success(`Available at ${absPath}\n`);
82
- }
83
- else {
84
- throw new Error(`Extension ${ext} is not supported`);
85
- }
86
- }
87
- }
95
+ method,
96
+ }, apolloFederation, aws);
97
+ return handler({ schema, writePath, type, threshold });
88
98
  });
89
99
  },
90
100
  };
@@ -134,4 +144,4 @@ function formatRating(ratio) {
134
144
  }
135
145
 
136
146
  export default index;
137
- //# sourceMappingURL=index.esm.js.map
147
+ export { handler };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-inspector/similar-command",
3
- "version": "0.0.0-canary.9cf9b2c",
3
+ "version": "0.0.0-canary.e88122e",
4
4
  "description": "Find similar types in GraphQL Schema",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0"
7
+ "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-inspector/commands": "0.0.0-canary.9cf9b2c",
11
- "@graphql-inspector/core": "0.0.0-canary.9cf9b2c",
12
- "@graphql-inspector/logger": "0.0.0-canary.9cf9b2c",
10
+ "@graphql-inspector/commands": "0.0.0-canary.e88122e",
11
+ "@graphql-inspector/core": "0.0.0-canary.e88122e",
12
+ "@graphql-inspector/logger": "0.0.0-canary.e88122e",
13
13
  "tslib": "^2.0.0"
14
14
  },
15
15
  "repository": {
@@ -29,10 +29,20 @@
29
29
  "url": "https://github.com/kamilkisiela"
30
30
  },
31
31
  "license": "MIT",
32
- "main": "index.cjs.js",
33
- "module": "index.esm.js",
32
+ "main": "index.js",
33
+ "module": "index.mjs",
34
34
  "typings": "index.d.ts",
35
35
  "typescript": {
36
36
  "definition": "index.d.ts"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "require": "./index.js",
41
+ "import": "./index.mjs"
42
+ },
43
+ "./*": {
44
+ "require": "./*.js",
45
+ "import": "./*.mjs"
46
+ }
37
47
  }
38
48
  }
package/index.cjs.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../dist/commands/similar/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { Logger, figures, chalk } from '@graphql-inspector/logger';\nimport { similar as findSimilar, getTypePrefix, } from '@graphql-inspector/core';\nimport { extname } from 'path';\nimport { writeFileSync } from 'fs';\nexport default createCommand((api) => {\n return {\n command: 'similar <schema>',\n describe: 'Find similar types in a schema',\n builder(yargs) {\n return yargs\n .positional('schema', {\n describe: 'Point to a schema',\n type: 'string',\n demandOption: true,\n })\n .options({\n n: {\n alias: 'name',\n describe: 'Name of a type',\n type: 'string',\n },\n t: {\n alias: 'threshold',\n describe: 'Threshold of similarity ratio',\n type: 'number',\n },\n w: {\n alias: 'write',\n describe: 'Write a file with stats',\n type: 'string',\n },\n });\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n const { loaders } = api;\n const { headers, token } = parseGlobalArgs(args);\n const writePath = args.write;\n const shouldWrite = typeof writePath !== 'undefined';\n const schema = yield loaders.loadSchema(args.schema, {\n headers,\n token,\n });\n const similarMap = findSimilar(schema, args.name, args.threshold);\n if (!Object.keys(similarMap).length) {\n Logger.info('No similar types found');\n }\n else {\n for (const typeName in similarMap) {\n if (similarMap.hasOwnProperty(typeName)) {\n const matches = similarMap[typeName];\n const prefix = getTypePrefix(schema.getType(typeName));\n const sourceType = chalk.bold(typeName);\n const name = matches.bestMatch.target.typeId;\n Logger.log('');\n Logger.log(`${prefix} ${sourceType}`);\n Logger.log(printResult(name, matches.bestMatch.rating));\n matches.ratings.forEach((match) => {\n Logger.log(printResult(match.target.typeId, match.rating));\n });\n }\n }\n if (shouldWrite) {\n if (typeof writePath !== 'string') {\n throw new Error(`--write is not valid file path: ${writePath}`);\n }\n const absPath = ensureAbsolute(writePath);\n const ext = extname(absPath).replace('.', '').toLocaleLowerCase();\n let output = undefined;\n const results = transformMap(similarMap);\n if (ext === 'json') {\n output = outputJSON(results);\n }\n if (output) {\n writeFileSync(absPath, output, {\n encoding: 'utf-8',\n });\n Logger.success(`Available at ${absPath}\\n`);\n }\n else {\n throw new Error(`Extension ${ext} is not supported`);\n }\n }\n }\n });\n },\n };\n});\nfunction indent(line, space) {\n return line.padStart(line.length + space, ' ');\n}\nfunction transformMap(similarMap) {\n const results = {};\n for (const typename in similarMap) {\n if (similarMap.hasOwnProperty(typename)) {\n const result = similarMap[typename];\n results[typename] = [];\n if (result.bestMatch) {\n results[typename].push(trasformResult(result.bestMatch));\n }\n if (result.ratings) {\n results[typename].push(...result.ratings.map(trasformResult));\n }\n }\n }\n return results;\n}\nfunction trasformResult(record) {\n return {\n typename: record.target.typeId,\n rating: record.rating,\n };\n}\nfunction outputJSON(results) {\n return JSON.stringify(results);\n}\nfunction printResult(name, rating) {\n const percentage = chalk.grey(`(${formatRating(rating)}%)`);\n return indent(`${printScale(rating)} ${percentage} ${name}`, 0);\n}\nfunction printScale(ratio) {\n const percentage = Math.floor(ratio * 100);\n const levels = [0, 30, 50, 70, 90];\n return levels\n .map((level) => percentage >= level)\n .map((enabled) => (enabled ? figures.bullet : chalk.gray(figures.bullet)))\n .join('');\n}\nfunction formatRating(ratio) {\n return Math.floor(ratio * 100);\n}\n//# sourceMappingURL=index.js.map"],"names":["createCommand","__awaiter","parseGlobalArgs","findSimilar","Logger","getTypePrefix","chalk","ensureAbsolute","extname","writeFileSync","figures"],"mappings":";;;;;;;;;AAMA,cAAeA,sBAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,kBAAkB;AACnC,QAAQ,QAAQ,EAAE,gCAAgC;AAClD,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,QAAQ,EAAE;AACtC,gBAAgB,QAAQ,EAAE,mBAAmB;AAC7C,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC;AACd,iBAAiB,OAAO,CAAC;AACzB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,MAAM;AACjC,oBAAoB,QAAQ,EAAE,gBAAgB;AAC9C,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,WAAW;AACtC,oBAAoB,QAAQ,EAAE,+BAA+B;AAC7D,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,OAAO;AAClC,oBAAoB,QAAQ,EAAE,yBAAyB;AACvD,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,aAAa,CAAC,CAAC;AACf,SAAS;AACT,QAAQ,OAAO,CAAC,IAAI,EAAE;AACtB,YAAY,OAAOC,eAAS,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,aAAa;AAChE,gBAAgB,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;AACxC,gBAAgB,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAGC,wBAAe,CAA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AAC,OAAO,EAAE;AAC7B,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AACD,SAAS,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE;AACnC,IAAI,MAAM,UAAU,GAAGE,YAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAChE,IAAI,OAAO,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC;AACD,SAAS,UAAU,CAAC,KAAK,EAAE;AAC3B,IAAI,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;AAC/C,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACvC,IAAI,OAAO,MAAM;AACjB,SAAS,GAAG,CAAC,CAAC,KAAK,KAAK,UAAU,IAAI,KAAK,CAAC;AAC5C,SAAS,GAAG,CAAC,CAAC,OAAO,MAAM,OAAO,GAAGI,cAAO,CAAC,MAAM,GAAGJ,YAAK,CAAC,IAAI,CAACI,cAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAClF,SAAS,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AACD,SAAS,YAAY,CAAC,KAAK,EAAE;AAC7B,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;AACnC;;;;"}
package/index.esm.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../dist/commands/similar/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { Logger, figures, chalk } from '@graphql-inspector/logger';\nimport { similar as findSimilar, getTypePrefix, } from '@graphql-inspector/core';\nimport { extname } from 'path';\nimport { writeFileSync } from 'fs';\nexport default createCommand((api) => {\n return {\n command: 'similar <schema>',\n describe: 'Find similar types in a schema',\n builder(yargs) {\n return yargs\n .positional('schema', {\n describe: 'Point to a schema',\n type: 'string',\n demandOption: true,\n })\n .options({\n n: {\n alias: 'name',\n describe: 'Name of a type',\n type: 'string',\n },\n t: {\n alias: 'threshold',\n describe: 'Threshold of similarity ratio',\n type: 'number',\n },\n w: {\n alias: 'write',\n describe: 'Write a file with stats',\n type: 'string',\n },\n });\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n const { loaders } = api;\n const { headers, token } = parseGlobalArgs(args);\n const writePath = args.write;\n const shouldWrite = typeof writePath !== 'undefined';\n const schema = yield loaders.loadSchema(args.schema, {\n headers,\n token,\n });\n const similarMap = findSimilar(schema, args.name, args.threshold);\n if (!Object.keys(similarMap).length) {\n Logger.info('No similar types found');\n }\n else {\n for (const typeName in similarMap) {\n if (similarMap.hasOwnProperty(typeName)) {\n const matches = similarMap[typeName];\n const prefix = getTypePrefix(schema.getType(typeName));\n const sourceType = chalk.bold(typeName);\n const name = matches.bestMatch.target.typeId;\n Logger.log('');\n Logger.log(`${prefix} ${sourceType}`);\n Logger.log(printResult(name, matches.bestMatch.rating));\n matches.ratings.forEach((match) => {\n Logger.log(printResult(match.target.typeId, match.rating));\n });\n }\n }\n if (shouldWrite) {\n if (typeof writePath !== 'string') {\n throw new Error(`--write is not valid file path: ${writePath}`);\n }\n const absPath = ensureAbsolute(writePath);\n const ext = extname(absPath).replace('.', '').toLocaleLowerCase();\n let output = undefined;\n const results = transformMap(similarMap);\n if (ext === 'json') {\n output = outputJSON(results);\n }\n if (output) {\n writeFileSync(absPath, output, {\n encoding: 'utf-8',\n });\n Logger.success(`Available at ${absPath}\\n`);\n }\n else {\n throw new Error(`Extension ${ext} is not supported`);\n }\n }\n }\n });\n },\n };\n});\nfunction indent(line, space) {\n return line.padStart(line.length + space, ' ');\n}\nfunction transformMap(similarMap) {\n const results = {};\n for (const typename in similarMap) {\n if (similarMap.hasOwnProperty(typename)) {\n const result = similarMap[typename];\n results[typename] = [];\n if (result.bestMatch) {\n results[typename].push(trasformResult(result.bestMatch));\n }\n if (result.ratings) {\n results[typename].push(...result.ratings.map(trasformResult));\n }\n }\n }\n return results;\n}\nfunction trasformResult(record) {\n return {\n typename: record.target.typeId,\n rating: record.rating,\n };\n}\nfunction outputJSON(results) {\n return JSON.stringify(results);\n}\nfunction printResult(name, rating) {\n const percentage = chalk.grey(`(${formatRating(rating)}%)`);\n return indent(`${printScale(rating)} ${percentage} ${name}`, 0);\n}\nfunction printScale(ratio) {\n const percentage = Math.floor(ratio * 100);\n const levels = [0, 30, 50, 70, 90];\n return levels\n .map((level) => percentage >= level)\n .map((enabled) => (enabled ? figures.bullet : chalk.gray(figures.bullet)))\n .join('');\n}\nfunction formatRating(ratio) {\n return Math.floor(ratio * 100);\n}\n//# sourceMappingURL=index.js.map"],"names":["findSimilar"],"mappings":";;;;;;;AAMA,cAAe,aAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,kBAAkB;AACnC,QAAQ,QAAQ,EAAE,gCAAgC;AAClD,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,QAAQ,EAAE;AACtC,gBAAgB,QAAQ,EAAE,mBAAmB;AAC7C,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC;AACd,iBAAiB,OAAO,CAAC;AACzB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,MAAM;AACjC,oBAAoB,QAAQ,EAAE,gBAAgB;AAC9C,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,gBAAgB,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