@looker/sdk-codegen-scripts 21.4.7 → 21.5.0

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 (82) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/lib/convert.js +0 -10
  3. package/lib/convert.js.map +1 -1
  4. package/lib/declarationMiner.js +11 -37
  5. package/lib/declarationMiner.js.map +1 -1
  6. package/lib/esm/convert.js +20 -18
  7. package/lib/esm/convert.js.map +1 -1
  8. package/lib/esm/declarationMiner.js +32 -41
  9. package/lib/esm/declarationMiner.js.map +1 -1
  10. package/lib/esm/exampleMiner.js +52 -77
  11. package/lib/esm/exampleMiner.js.map +1 -1
  12. package/lib/esm/fetchSpec.js +65 -83
  13. package/lib/esm/fetchSpec.js.map +1 -1
  14. package/lib/esm/index.js +93 -8
  15. package/lib/esm/index.js.map +1 -1
  16. package/lib/esm/languages.js +16 -11
  17. package/lib/esm/languages.js.map +1 -1
  18. package/lib/esm/legacy.js +8 -9
  19. package/lib/esm/legacy.js.map +1 -1
  20. package/lib/esm/legacyGenerator.js +19 -22
  21. package/lib/esm/legacyGenerator.js.map +1 -1
  22. package/lib/esm/nodeUtils.js +39 -22
  23. package/lib/esm/nodeUtils.js.map +1 -1
  24. package/lib/esm/prettify.js +15 -9
  25. package/lib/esm/prettify.js.map +1 -1
  26. package/lib/esm/reformatter.js +53 -102
  27. package/lib/esm/reformatter.js.map +1 -1
  28. package/lib/esm/sdkConfig.js +19 -13
  29. package/lib/esm/sdkConfig.js.map +1 -1
  30. package/lib/esm/sdkGen.js +43 -59
  31. package/lib/esm/sdkGen.js.map +1 -1
  32. package/lib/esm/sdkGenerator.js +34 -47
  33. package/lib/esm/sdkGenerator.js.map +1 -1
  34. package/lib/esm/specConvert.js +20 -27
  35. package/lib/esm/specConvert.js.map +1 -1
  36. package/lib/esm/testUtils/index.js +28 -0
  37. package/lib/esm/testUtils/index.js.map +1 -0
  38. package/lib/esm/testUtils/mocks.js +16 -0
  39. package/lib/esm/testUtils/mocks.js.map +1 -0
  40. package/lib/esm/testUtils/testUtils.js +66 -0
  41. package/lib/esm/testUtils/testUtils.js.map +1 -0
  42. package/lib/esm/utils.js +43 -60
  43. package/lib/esm/utils.js.map +1 -1
  44. package/lib/esm/yamlToJson.js +8 -6
  45. package/lib/esm/yamlToJson.js.map +1 -1
  46. package/lib/exampleMiner.js +4 -89
  47. package/lib/exampleMiner.js.map +1 -1
  48. package/lib/fetchSpec.js +6 -76
  49. package/lib/fetchSpec.js.map +1 -1
  50. package/lib/index.js +0 -16
  51. package/lib/index.js.map +1 -1
  52. package/lib/languages.js +0 -11
  53. package/lib/languages.js.map +1 -1
  54. package/lib/legacy.js +0 -5
  55. package/lib/legacy.js.map +1 -1
  56. package/lib/legacyGenerator.js +0 -15
  57. package/lib/legacyGenerator.js.map +1 -1
  58. package/lib/nodeUtils.js +1 -34
  59. package/lib/nodeUtils.js.map +1 -1
  60. package/lib/prettify.js +5 -14
  61. package/lib/prettify.js.map +1 -1
  62. package/lib/reformatter.js +3 -70
  63. package/lib/reformatter.js.map +1 -1
  64. package/lib/sdkConfig.js +0 -16
  65. package/lib/sdkConfig.js.map +1 -1
  66. package/lib/sdkGen.js +0 -41
  67. package/lib/sdkGen.js.map +1 -1
  68. package/lib/sdkGenerator.js +4 -52
  69. package/lib/sdkGenerator.js.map +1 -1
  70. package/lib/specConvert.js +0 -19
  71. package/lib/specConvert.js.map +1 -1
  72. package/lib/testUtils/index.js +0 -4
  73. package/lib/testUtils/index.js.map +1 -1
  74. package/lib/testUtils/mocks.js +0 -4
  75. package/lib/testUtils/mocks.js.map +1 -1
  76. package/lib/testUtils/testUtils.js +1 -17
  77. package/lib/testUtils/testUtils.js.map +1 -1
  78. package/lib/utils.js +6 -48
  79. package/lib/utils.js.map +1 -1
  80. package/lib/yamlToJson.js +0 -7
  81. package/lib/yamlToJson.js.map +1 -1
  82. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Changelog
2
2
 
3
+ ## [21.5.0](https://github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.4.8...sdk-codegen-scripts-v21.5.0) (2023-02-22)
4
+
5
+
6
+ ### Features
7
+
8
+ * generate SDKs for Looker 23.0 ([#1237](https://github.com/looker-open-source/sdk-codegen/issues/1237)) ([2ade858](https://github.com/looker-open-source/sdk-codegen/commit/2ade85815c43383169263659f5dddd783c062c09))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @looker/sdk bumped from ^22.20.1 to ^23.0.0
16
+ * @looker/sdk-codegen bumped from ^21.7.4 to ^21.8.0
17
+ * @looker/sdk-node bumped from ^22.20.1 to ^23.0.0
18
+ * @looker/sdk-rtl bumped from ^21.5.0 to ^21.6.0
19
+
20
+ ### [21.4.8](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.4.7...sdk-codegen-scripts-v21.4.8) (2022-12-09)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * Hack App Wholly Artifact Refactor ([#1210](https://www.github.com/looker-open-source/sdk-codegen/issues/1210)) ([d508fa8](https://www.github.com/looker-open-source/sdk-codegen/commit/d508fa878ca23f6ed298359d3ec1b25a3f333fac))
26
+
27
+
28
+ ### Dependencies
29
+
30
+ * The following workspace dependencies were updated
31
+ * dependencies
32
+ * @looker/sdk bumped from ^22.20.0 to ^22.20.1
33
+ * @looker/sdk-codegen bumped from ^21.7.3 to ^21.7.4
34
+ * @looker/sdk-node bumped from ^22.20.0 to ^22.20.1
35
+ * @looker/sdk-rtl bumped from ^21.4.0 to ^21.5.0
36
+
3
37
  ### [21.4.7](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.4.6...sdk-codegen-scripts-v21.4.7) (2022-11-10)
4
38
 
5
39
 
package/lib/convert.js CHANGED
@@ -4,24 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.convertSpec = void 0;
7
-
8
7
  var _sdkCodegenUtils = require("@looker/sdk-codegen-utils");
9
-
10
8
  var _sdkCodegen = require("@looker/sdk-codegen");
11
-
12
9
  var _nodeUtils = require("./nodeUtils");
13
-
14
10
  var convertSpec = function convertSpec(specFileName, openApiFilename) {
15
11
  var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
16
-
17
12
  if ((0, _nodeUtils.isFileSync)(openApiFilename) && !force) {
18
13
  (0, _sdkCodegenUtils.log)("".concat(openApiFilename, " already exists. Skipping conversion."));
19
14
  return openApiFilename;
20
15
  }
21
-
22
16
  var spec = (0, _nodeUtils.readFileSync)(specFileName);
23
17
  var swagger = JSON.parse(spec);
24
-
25
18
  if (swagger.swagger) {
26
19
  (0, _nodeUtils.run)('yarn swagger2openapi', [specFileName, '-p', '-i', '""', '-o', openApiFilename]);
27
20
  } else if (swagger.openapi) {
@@ -29,15 +22,12 @@ var convertSpec = function convertSpec(specFileName, openApiFilename) {
29
22
  } else {
30
23
  throw new Error("Bad specification file ".concat(specFileName));
31
24
  }
32
-
33
25
  if (!(0, _nodeUtils.isFileSync)(openApiFilename)) {
34
26
  return (0, _nodeUtils.fail)('convertSpec', "creating ".concat(openApiFilename, " failed"));
35
27
  }
36
-
37
28
  var source = (0, _sdkCodegen.upgradeSpec)((0, _nodeUtils.readFileSync)(openApiFilename));
38
29
  (0, _nodeUtils.createJsonFile)(openApiFilename, source);
39
30
  return openApiFilename;
40
31
  };
41
-
42
32
  exports.convertSpec = convertSpec;
43
33
  //# sourceMappingURL=convert.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/convert.ts"],"names":["convertSpec","specFileName","openApiFilename","force","spec","swagger","JSON","parse","openapi","stringify","Error","source"],"mappings":";;;;;;;AA0BA;;AACA;;AACA;;AAmBO,IAAMA,WAAW,GAAG,SAAdA,WAAc,CACzBC,YADyB,EAEzBC,eAFyB,EAItB;AAAA,MADHC,KACG,uEADK,KACL;;AACH,MAAI,2BAAWD,eAAX,KAA+B,CAACC,KAApC,EAA2C;AACzC,wCAAOD,eAAP;AACA,WAAOA,eAAP;AACD;;AACD,MAAME,IAAI,GAAG,6BAAaH,YAAb,CAAb;AACA,MAAMI,OAAO,GAAGC,IAAI,CAACC,KAAL,CAAWH,IAAX,CAAhB;;AACA,MAAIC,OAAO,CAACA,OAAZ,EAAqB;AAMnB,wBAAI,sBAAJ,EAA4B,CAC1BJ,YAD0B,EAE1B,IAF0B,EAG1B,IAH0B,EAI1B,IAJ0B,EAK1B,IAL0B,EAM1BC,eAN0B,CAA5B;AAQD,GAdD,MAcO,IAAIG,OAAO,CAACG,OAAZ,EAAqB;AAE1B,kCAAcN,eAAd,EAA+BI,IAAI,CAACG,SAAL,CAAeJ,OAAf,CAA/B;AACD,GAHM,MAGA;AACL,UAAM,IAAIK,KAAJ,kCAAoCT,YAApC,EAAN;AACD;;AACD,MAAI,CAAC,2BAAWC,eAAX,CAAL,EAAkC;AAChC,WAAO,qBAAK,aAAL,qBAAgCA,eAAhC,aAAP;AACD;;AACD,MAAMS,MAAM,GAAG,6BAAY,6BAAaT,eAAb,CAAZ,CAAf;AACA,iCAAeA,eAAf,EAAgCS,MAAhC;AACA,SAAOT,eAAP;AACD,CArCM","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport { log } from '@looker/sdk-codegen-utils'\nimport { upgradeSpec } from '@looker/sdk-codegen'\nimport {\n createJsonFile,\n fail,\n isFileSync,\n readFileSync,\n run,\n writeFileSync,\n} from './nodeUtils'\n\n/**\n * Convert a Swagger specification to OpenAPI\n *\n * If the source spec is already an OpenAPI spec, fixes are still processed\n *\n * @param specFileName source Swagger spec file\n * @param openApiFilename destination OpenAPI spec file\n * @param force use `true` to force a conversion even if the file exists\n * @returns {Promise<string>} name of OpenAPI file\n */\nexport const convertSpec = (\n specFileName: string,\n openApiFilename: string,\n force = false\n) => {\n if (isFileSync(openApiFilename) && !force) {\n log(`${openApiFilename} already exists. Skipping conversion.`)\n return openApiFilename\n }\n const spec = readFileSync(specFileName)\n const swagger = JSON.parse(spec)\n if (swagger.swagger) {\n // Still a swagger spec. Convert it.\n // https://github.com/Mermade/oas-kit/tree/master/packages/swagger2openapi config options:\n // patch to fix up small errors in source definition (not required, just to ensure smooth process)\n // indent no spaces\n // output to openApiFilename\n run('yarn swagger2openapi', [\n specFileName,\n '-p',\n '-i',\n '\"\"',\n '-o',\n openApiFilename,\n ])\n } else if (swagger.openapi) {\n // We've already got an OpenAPI file\n writeFileSync(openApiFilename, JSON.stringify(swagger))\n } else {\n throw new Error(`Bad specification file ${specFileName}`)\n }\n if (!isFileSync(openApiFilename)) {\n return fail('convertSpec', `creating ${openApiFilename} failed`)\n }\n const source = upgradeSpec(readFileSync(openApiFilename))\n createJsonFile(openApiFilename, source)\n return openApiFilename\n}\n"],"file":"convert.js"}
1
+ {"version":3,"file":"convert.js","names":["convertSpec","specFileName","openApiFilename","force","isFileSync","log","spec","readFileSync","swagger","JSON","parse","run","openapi","writeFileSync","stringify","Error","fail","source","upgradeSpec","createJsonFile"],"sources":["../src/convert.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport { log } from '@looker/sdk-codegen-utils'\nimport { upgradeSpec } from '@looker/sdk-codegen'\nimport {\n createJsonFile,\n fail,\n isFileSync,\n readFileSync,\n run,\n writeFileSync,\n} from './nodeUtils'\n\n/**\n * Convert a Swagger specification to OpenAPI\n *\n * If the source spec is already an OpenAPI spec, fixes are still processed\n *\n * @param specFileName source Swagger spec file\n * @param openApiFilename destination OpenAPI spec file\n * @param force use `true` to force a conversion even if the file exists\n * @returns {Promise<string>} name of OpenAPI file\n */\nexport const convertSpec = (\n specFileName: string,\n openApiFilename: string,\n force = false\n) => {\n if (isFileSync(openApiFilename) && !force) {\n log(`${openApiFilename} already exists. Skipping conversion.`)\n return openApiFilename\n }\n const spec = readFileSync(specFileName)\n const swagger = JSON.parse(spec)\n if (swagger.swagger) {\n // Still a swagger spec. Convert it.\n // https://github.com/Mermade/oas-kit/tree/master/packages/swagger2openapi config options:\n // patch to fix up small errors in source definition (not required, just to ensure smooth process)\n // indent no spaces\n // output to openApiFilename\n run('yarn swagger2openapi', [\n specFileName,\n '-p',\n '-i',\n '\"\"',\n '-o',\n openApiFilename,\n ])\n } else if (swagger.openapi) {\n // We've already got an OpenAPI file\n writeFileSync(openApiFilename, JSON.stringify(swagger))\n } else {\n throw new Error(`Bad specification file ${specFileName}`)\n }\n if (!isFileSync(openApiFilename)) {\n return fail('convertSpec', `creating ${openApiFilename} failed`)\n }\n const source = upgradeSpec(readFileSync(openApiFilename))\n createJsonFile(openApiFilename, source)\n return openApiFilename\n}\n"],"mappings":";;;;;;AA0BA;AACA;AACA;AAmBO,IAAMA,WAAW,GAAG,SAAdA,WAAW,CACtBC,YAAoB,EACpBC,eAAuB,EAEpB;EAAA,IADHC,KAAK,uEAAG,KAAK;EAEb,IAAI,IAAAC,qBAAU,EAACF,eAAe,CAAC,IAAI,CAACC,KAAK,EAAE;IACzC,IAAAE,oBAAG,YAAIH,eAAe,2CAAwC;IAC9D,OAAOA,eAAe;EACxB;EACA,IAAMI,IAAI,GAAG,IAAAC,uBAAY,EAACN,YAAY,CAAC;EACvC,IAAMO,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACJ,IAAI,CAAC;EAChC,IAAIE,OAAO,CAACA,OAAO,EAAE;IAMnB,IAAAG,cAAG,EAAC,sBAAsB,EAAE,CAC1BV,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJC,eAAe,CAChB,CAAC;EACJ,CAAC,MAAM,IAAIM,OAAO,CAACI,OAAO,EAAE;IAE1B,IAAAC,wBAAa,EAACX,eAAe,EAAEO,IAAI,CAACK,SAAS,CAACN,OAAO,CAAC,CAAC;EACzD,CAAC,MAAM;IACL,MAAM,IAAIO,KAAK,kCAA2Bd,YAAY,EAAG;EAC3D;EACA,IAAI,CAAC,IAAAG,qBAAU,EAACF,eAAe,CAAC,EAAE;IAChC,OAAO,IAAAc,eAAI,EAAC,aAAa,qBAAcd,eAAe,aAAU;EAClE;EACA,IAAMe,MAAM,GAAG,IAAAC,uBAAW,EAAC,IAAAX,uBAAY,EAACL,eAAe,CAAC,CAAC;EACzD,IAAAiB,yBAAc,EAACjB,eAAe,EAAEe,MAAM,CAAC;EACvC,OAAOf,eAAe;AACxB,CAAC;AAAA"}
@@ -3,34 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DeclarationMiner = exports.rubyTypeProbe = exports.rubyMethodProbe = void 0;
7
-
6
+ exports.rubyTypeProbe = exports.rubyMethodProbe = exports.DeclarationMiner = void 0;
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _exampleMiner = require("./exampleMiner");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
-
18
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
-
20
- function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (typeof args[args.length - 1] !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
21
-
22
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
23
-
24
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
-
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
+ function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++; groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != typeof args[args.length - 1] && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
16
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
17
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
18
  var fileFilter = (endpointFilePattern, typeFilePattern, fileName) => {
27
19
  var fileMatch = endpointFilePattern.test(fileName) || typeFilePattern.test(fileName);
28
20
  return (0, _exampleMiner.filterCodeFiles)(fileName) && fileMatch;
29
21
  };
30
-
31
22
  var rubyMethodProbe = {
32
23
  fileNamePattern: /^(?!test).*_controller.rb$/,
33
- declarationPattern: _wrapRegExp(/(GET|POST|DELETE|PUT|PATCH)[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF](?:"|')\/api\/3\.x([\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uFEFE\uFF00-\uFFFF]+)(?:"|')/i, {
24
+ declarationPattern: _wrapRegExp(/(GET|POST|DELETE|PUT|PATCH)\s(?:"|')\/api\/3\.x(\S+)(?:"|')/i, {
34
25
  verb: 1,
35
26
  path: 2
36
27
  }),
@@ -44,25 +35,21 @@ var rubyMethodProbe = {
44
35
  exports.rubyMethodProbe = rubyMethodProbe;
45
36
  var rubyTypeProbe = {
46
37
  fileNamePattern: /^(?!test).*_mapper.rb$/,
47
- declarationPattern: _wrapRegExp(/class[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]([0-9A-Z_a-z]+)Mapper/i, {
38
+ declarationPattern: _wrapRegExp(/class\s(\w+)Mapper/i, {
48
39
  typeName: 1
49
40
  }),
50
41
  matchToSpecKeyTransform: match => match.groups.typeName
51
42
  };
52
43
  exports.rubyTypeProbe = rubyTypeProbe;
53
-
54
44
  class DeclarationMiner {
55
45
  constructor(sourcePath, methodProbe, typeProbe, originOverride) {
56
46
  this.sourcePath = sourcePath;
57
47
  this.methodProbe = methodProbe;
58
48
  this.typeProbe = typeProbe;
59
49
  this.originOverride = originOverride;
60
-
61
50
  _defineProperty(this, "types", {});
62
-
63
51
  _defineProperty(this, "methods", {});
64
52
  }
65
-
66
53
  execute(sourcePath, methodProbe, typeProbe) {
67
54
  var filePath = sourcePath !== null && sourcePath !== void 0 ? sourcePath : this.sourcePath;
68
55
  var mProbe = methodProbe !== null && methodProbe !== void 0 ? methodProbe : this.methodProbe;
@@ -70,9 +57,7 @@ class DeclarationMiner {
70
57
  var files = (0, _exampleMiner.getCodeFiles)(filePath, undefined, fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern), ['node_modules', 'dist']);
71
58
  files.forEach(f => {
72
59
  var relFile = this.processFile(f);
73
-
74
60
  var fileName = _path.default.basename(relFile);
75
-
76
61
  if (mProbe.fileNamePattern.test(fileName)) {
77
62
  this.methods = _objectSpread(_objectSpread({}, this.methods), this.mineFile(relFile, f, mProbe));
78
63
  } else {
@@ -81,21 +66,17 @@ class DeclarationMiner {
81
66
  });
82
67
  return this.lode;
83
68
  }
84
-
85
69
  get commitHash() {
86
70
  process.chdir(this.sourcePath);
87
71
  return (0, _exampleMiner.getCommitHash)();
88
72
  }
89
-
90
73
  get remoteOrigin() {
91
74
  if (this.originOverride) {
92
75
  return this.originOverride;
93
76
  }
94
-
95
77
  process.chdir(this.sourcePath);
96
78
  return (0, _exampleMiner.getRemoteOrigin)();
97
79
  }
98
-
99
80
  get lode() {
100
81
  return {
101
82
  commitHash: this.commitHash,
@@ -104,23 +85,18 @@ class DeclarationMiner {
104
85
  methods: this.methods
105
86
  };
106
87
  }
107
-
108
88
  processFile(fileName) {
109
89
  var relFile = _exampleMiner.ExampleMiner.relate(this.sourcePath, fileName);
110
-
111
90
  return relFile;
112
91
  }
113
-
114
92
  mineFile(relFile, fileName, probe) {
115
93
  return this.mineCode(relFile, (0, _exampleMiner.readFile)(fileName), probe);
116
94
  }
117
-
118
95
  mineCode(relFile, content, probe) {
119
96
  var lines = content.split('\n');
120
97
  var declarations = {};
121
98
  lines.forEach((line, index) => {
122
99
  var match = probe.declarationPattern.exec(line);
123
-
124
100
  if (match) {
125
101
  var key = probe.matchToSpecKeyTransform(match);
126
102
  declarations[key] = {
@@ -131,8 +107,6 @@ class DeclarationMiner {
131
107
  });
132
108
  return declarations;
133
109
  }
134
-
135
110
  }
136
-
137
111
  exports.DeclarationMiner = DeclarationMiner;
138
112
  //# sourceMappingURL=declarationMiner.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/declarationMiner.ts"],"names":["fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","path","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","originOverride","execute","filePath","mProbe","tProbe","files","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","remoteOrigin","ExampleMiner","relate","probe","mineCode","content","lines","split","declarations","line","index","exec","sourceFile"],"mappings":";;;;;;;AAyBA;;AAGA;;;;;;;;;;;;;;;;AAeA,IAAMA,UAAU,GAAG,CACjBC,mBADiB,EAEjBC,eAFiB,EAGjBC,QAHiB,KAId;AACH,MAAMC,SAAS,GACbH,mBAAmB,CAACI,IAApB,CAAyBF,QAAzB,KAAsCD,eAAe,CAACG,IAAhB,CAAqBF,Q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MAAAA,UAAU,EAAE,KAAKA,UADZ;AAELG,MAAAA,YAAY,EAAE,KAAKA,YAFd;AAGLL,MAAAA,KAAK,EAAE,KAAKA,KAHP;AAILF,MAAAA,OAAO,EAAE,KAAKA;AAJT,KAAP;AAMD;;AAESF,EAAAA,WAAW,CAAChC,QAAD,EAAmB;AACtC,QAAM+B,OAAO,GAAGW,2BAAaC,MAAb,CAAoB,KAAKzB,UAAzB,EAAqClB,QAArC,CAAhB;;AACA,WAAO+B,OAAP;AACD;;AAESI,EAAAA,QAAQ,CAACJ,OAAD,EAAkB/B,QAAlB,EAAoC4C,KAApC,EAAmD;AACnE,WAAO,KAAKC,QAAL,CAAcd,OAAd,EAAuB,4BAAS/B,QAAT,CAAvB,EAA2C4C,KAA3C,CAAP;AACD;;AAESC,EAAAA,QAAQ,CAACd,OAAD,EAAkBe,OAAlB,EAAmCF,KAAnC,EAAkD;AAClE,QAAMG,KAAK,GAAGD,OAAO,CAACE,KAAR,CAAc,IAAd,CAAd;AACA,QAAMC,YAAgC,GAAG,EAAzC;AACAF,IAAAA,KAAK,CAAClB,OAAN,CAAc,CAACqB,IAAD,EAAOC,KAAP,KAAiB;AAC7B,UAAM5C,KAAK,GAAGqC,KAAK,CAACvC,kBAAN,CAAyB+C,IAAzB,CAA8BF,IAA9B,CAAd;;AACA,UAAI3C,KAAJ,EAAW;AACT,YAAMM,GAAG,GAAG+B,KAAK,CAACtC,uBAAN,CAA8BC,KAA9B,CAAZ;AACA0C,QAAAA,YAAY,CAACpC,GAAD,CAAZ,GAAoB;AAClBqC,UAAAA,IAAI,EAAEC,KAAK,GAAG,CADI;AAElBE,UAAAA,UAAU,EAAEtB;AAFM,SAApB;AAID;AACF,KATD;AAUA,WAAOkB,YAAP;AACD;;AAhF2B","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe,\n private readonly originOverride: string\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n if (this.originOverride) {\n return this.originOverride\n }\n process.chdir(this.sourcePath)\n return getRemoteOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"file":"declarationMiner.js"}
1
+ {"version":3,"file":"declarationMiner.js","names":["fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","filterCodeFiles","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","path","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","originOverride","execute","filePath","mProbe","tProbe","files","getCodeFiles","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","getCommitHash","remoteOrigin","getRemoteOrigin","ExampleMiner","relate","probe","mineCode","readFile","content","lines","split","declarations","line","index","exec","sourceFile"],"sources":["../src/declarationMiner.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe,\n private readonly originOverride: string\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n if (this.originOverride) {\n return this.originOverride\n }\n process.chdir(this.sourcePath)\n return getRemoteOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declar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AChD8C,YAAY,CAACxC,GAAG,CAAC,GAAG;UAClByC,IAAI,EAAEC,KAAK,GAAG,CAAC;UACfE,UAAU,EAAEzB;QACd,CAAC;MACH;IACF,CAAC,CAAC;IACF,OAAOqB,YAAY;EACrB;AACF;AAAC"}
@@ -1,31 +1,33 @@
1
- import { log } from '@looker/sdk-codegen-utils';
2
- import { upgradeSpec } from '@looker/sdk-codegen';
3
- import { createJsonFile, fail, isFileSync, readFileSync, run, writeFileSync } from './nodeUtils';
4
- export var convertSpec = function convertSpec(specFileName, openApiFilename) {
5
- var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1
+ "use strict";
6
2
 
7
- if (isFileSync(openApiFilename) && !force) {
8
- log("".concat(openApiFilename, " already exists. Skipping conversion."));
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertSpec = void 0;
7
+ var _sdkCodegenUtils = require("@looker/sdk-codegen-utils");
8
+ var _sdkCodegen = require("@looker/sdk-codegen");
9
+ var _nodeUtils = require("./nodeUtils");
10
+ var convertSpec = function convertSpec(specFileName, openApiFilename) {
11
+ var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
12
+ if ((0, _nodeUtils.isFileSync)(openApiFilename) && !force) {
13
+ (0, _sdkCodegenUtils.log)("".concat(openApiFilename, " already exists. Skipping conversion."));
9
14
  return openApiFilename;
10
15
  }
11
-
12
- var spec = readFileSync(specFileName);
16
+ var spec = (0, _nodeUtils.readFileSync)(specFileName);
13
17
  var swagger = JSON.parse(spec);
14
-
15
18
  if (swagger.swagger) {
16
- run('yarn swagger2openapi', [specFileName, '-p', '-i', '""', '-o', openApiFilename]);
19
+ (0, _nodeUtils.run)('yarn swagger2openapi', [specFileName, '-p', '-i', '""', '-o', openApiFilename]);
17
20
  } else if (swagger.openapi) {
18
- writeFileSync(openApiFilename, JSON.stringify(swagger));
21
+ (0, _nodeUtils.writeFileSync)(openApiFilename, JSON.stringify(swagger));
19
22
  } else {
20
23
  throw new Error("Bad specification file ".concat(specFileName));
21
24
  }
22
-
23
- if (!isFileSync(openApiFilename)) {
24
- return fail('convertSpec', "creating ".concat(openApiFilename, " failed"));
25
+ if (!(0, _nodeUtils.isFileSync)(openApiFilename)) {
26
+ return (0, _nodeUtils.fail)('convertSpec', "creating ".concat(openApiFilename, " failed"));
25
27
  }
26
-
27
- var source = upgradeSpec(readFileSync(openApiFilename));
28
- createJsonFile(openApiFilename, source);
28
+ var source = (0, _sdkCodegen.upgradeSpec)((0, _nodeUtils.readFileSync)(openApiFilename));
29
+ (0, _nodeUtils.createJsonFile)(openApiFilename, source);
29
30
  return openApiFilename;
30
31
  };
32
+ exports.convertSpec = convertSpec;
31
33
  //# sourceMappingURL=convert.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/convert.ts"],"names":["log","upgradeSpec","createJsonFile","fail","isFileSync","readFileSync","run","writeFileSync","convertSpec","specFileName","openApiFilename","force","spec","swagger","JSON","parse","openapi","stringify","Error","source"],"mappings":"AA0BA,SAASA,GAAT,QAAoB,2BAApB;AACA,SAASC,WAAT,QAA4B,qBAA5B;AACA,SACEC,cADF,EAEEC,IAFF,EAGEC,UAHF,EAIEC,YAJF,EAKEC,GALF,EAMEC,aANF,QAOO,aAPP;AAmBA,OAAO,IAAMC,WAAW,GAAG,SAAdA,WAAc,CACzBC,YADyB,EAEzBC,eAFyB,EAItB;AAAA,MADHC,KACG,uEADK,KACL;;AACH,MAAIP,UAAU,CAACM,eAAD,CAAV,IAA+B,CAACC,KAApC,EAA2C;AACzCX,IAAAA,GAAG,WAAIU,eAAJ,2CAAH;AACA,WAAOA,eAAP;AACD;;AACD,MAAME,IAAI,GAAGP,YAAY,CAACI,YAAD,CAAzB;AACA,MAAMI,OAAO,GAAGC,IAAI,CAACC,KAAL,CAAWH,IAAX,CAAhB;;AACA,MAAIC,OAAO,CAACA,OAAZ,EAAqB;AAMnBP,IAAAA,GAAG,CAAC,sBAAD,EAAyB,CAC1BG,YAD0B,EAE1B,IAF0B,EAG1B,IAH0B,EAI1B,IAJ0B,EAK1B,IAL0B,EAM1BC,eAN0B,CAAzB,CAAH;AAQD,GAdD,MAcO,IAAIG,OAAO,CAACG,OAAZ,EAAqB;AAE1BT,IAAAA,aAAa,CAACG,eAAD,EAAkBI,IAAI,CAACG,SAAL,CAAeJ,OAAf,CAAlB,CAAb;AACD,GAHM,MAGA;AACL,UAAM,IAAIK,KAAJ,kCAAoCT,YAApC,EAAN;AACD;;AACD,MAAI,CAACL,UAAU,CAACM,eAAD,CAAf,EAAkC;AAChC,WAAOP,IAAI,CAAC,aAAD,qBAA4BO,eAA5B,aAAX;AACD;;AACD,MAAMS,MAAM,GAAGlB,WAAW,CAACI,YAAY,CAACK,eAAD,CAAb,CAA1B;AACAR,EAAAA,cAAc,CAACQ,eAAD,EAAkBS,MAAlB,CAAd;AACA,SAAOT,eAAP;AACD,CArCM","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport { log } from '@looker/sdk-codegen-utils'\nimport { upgradeSpec } from '@looker/sdk-codegen'\nimport {\n createJsonFile,\n fail,\n isFileSync,\n readFileSync,\n run,\n writeFileSync,\n} from './nodeUtils'\n\n/**\n * Convert a Swagger specification to OpenAPI\n *\n * If the source spec is already an OpenAPI spec, fixes are still processed\n *\n * @param specFileName source Swagger spec file\n * @param openApiFilename destination OpenAPI spec file\n * @param force use `true` to force a conversion even if the file exists\n * @returns {Promise<string>} name of OpenAPI file\n */\nexport const convertSpec = (\n specFileName: string,\n openApiFilename: string,\n force = false\n) => {\n if (isFileSync(openApiFilename) && !force) {\n log(`${openApiFilename} already exists. Skipping conversion.`)\n return openApiFilename\n }\n const spec = readFileSync(specFileName)\n const swagger = JSON.parse(spec)\n if (swagger.swagger) {\n // Still a swagger spec. Convert it.\n // https://github.com/Mermade/oas-kit/tree/master/packages/swagger2openapi config options:\n // patch to fix up small errors in source definition (not required, just to ensure smooth process)\n // indent no spaces\n // output to openApiFilename\n run('yarn swagger2openapi', [\n specFileName,\n '-p',\n '-i',\n '\"\"',\n '-o',\n openApiFilename,\n ])\n } else if (swagger.openapi) {\n // We've already got an OpenAPI file\n writeFileSync(openApiFilename, JSON.stringify(swagger))\n } else {\n throw new Error(`Bad specification file ${specFileName}`)\n }\n if (!isFileSync(openApiFilename)) {\n return fail('convertSpec', `creating ${openApiFilename} failed`)\n }\n const source = upgradeSpec(readFileSync(openApiFilename))\n createJsonFile(openApiFilename, source)\n return openApiFilename\n}\n"],"file":"convert.js"}
1
+ {"version":3,"file":"convert.js","names":["convertSpec","specFileName","openApiFilename","force","isFileSync","log","spec","readFileSync","swagger","JSON","parse","run","openapi","writeFileSync","stringify","Error","fail","source","upgradeSpec","createJsonFile"],"sources":["../../src/convert.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport { log } from '@looker/sdk-codegen-utils'\nimport { upgradeSpec } from '@looker/sdk-codegen'\nimport {\n createJsonFile,\n fail,\n isFileSync,\n readFileSync,\n run,\n writeFileSync,\n} from './nodeUtils'\n\n/**\n * Convert a Swagger specification to OpenAPI\n *\n * If the source spec is already an OpenAPI spec, fixes are still processed\n *\n * @param specFileName source Swagger spec file\n * @param openApiFilename destination OpenAPI spec file\n * @param force use `true` to force a conversion even if the file exists\n * @returns {Promise<string>} name of OpenAPI file\n */\nexport const convertSpec = (\n specFileName: string,\n openApiFilename: string,\n force = false\n) => {\n if (isFileSync(openApiFilename) && !force) {\n log(`${openApiFilename} already exists. Skipping conversion.`)\n return openApiFilename\n }\n const spec = readFileSync(specFileName)\n const swagger = JSON.parse(spec)\n if (swagger.swagger) {\n // Still a swagger spec. Convert it.\n // https://github.com/Mermade/oas-kit/tree/master/packages/swagger2openapi config options:\n // patch to fix up small errors in source definition (not required, just to ensure smooth process)\n // indent no spaces\n // output to openApiFilename\n run('yarn swagger2openapi', [\n specFileName,\n '-p',\n '-i',\n '\"\"',\n '-o',\n openApiFilename,\n ])\n } else if (swagger.openapi) {\n // We've already got an OpenAPI file\n writeFileSync(openApiFilename, JSON.stringify(swagger))\n } else {\n throw new Error(`Bad specification file ${specFileName}`)\n }\n if (!isFileSync(openApiFilename)) {\n return fail('convertSpec', `creating ${openApiFilename} failed`)\n }\n const source = upgradeSpec(readFileSync(openApiFilename))\n createJsonFile(openApiFilename, source)\n return openApiFilename\n}\n"],"mappings":";;;;;;AA0BA;AACA;AACA;AAmBO,IAAMA,WAAW,GAAG,SAAdA,WAAW,CACtBC,YAAoB,EACpBC,eAAuB,EAEpB;EAAA,IADHC,KAAK,uEAAG,KAAK;EAEb,IAAI,IAAAC,qBAAU,EAACF,eAAe,CAAC,IAAI,CAACC,KAAK,EAAE;IACzC,IAAAE,oBAAG,YAAIH,eAAe,2CAAwC;IAC9D,OAAOA,eAAe;EACxB;EACA,IAAMI,IAAI,GAAG,IAAAC,uBAAY,EAACN,YAAY,CAAC;EACvC,IAAMO,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACJ,IAAI,CAAC;EAChC,IAAIE,OAAO,CAACA,OAAO,EAAE;IAMnB,IAAAG,cAAG,EAAC,sBAAsB,EAAE,CAC1BV,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJC,eAAe,CAChB,CAAC;EACJ,CAAC,MAAM,IAAIM,OAAO,CAACI,OAAO,EAAE;IAE1B,IAAAC,wBAAa,EAACX,eAAe,EAAEO,IAAI,CAACK,SAAS,CAACN,OAAO,CAAC,CAAC;EACzD,CAAC,MAAM;IACL,MAAM,IAAIO,KAAK,kCAA2Bd,YAAY,EAAG;EAC3D;EACA,IAAI,CAAC,IAAAG,qBAAU,EAACF,eAAe,CAAC,EAAE;IAChC,OAAO,IAAAc,eAAI,EAAC,aAAa,qBAAcd,eAAe,aAAU;EAClE;EACA,IAAMe,MAAM,GAAG,IAAAC,uBAAW,EAAC,IAAAX,uBAAY,EAACL,eAAe,CAAC,CAAC;EACzD,IAAAiB,yBAAc,EAACjB,eAAe,EAAEe,MAAM,CAAC;EACvC,OAAOf,eAAe;AACxB,CAAC;AAAA"}
@@ -1,26 +1,27 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (typeof args[args.length - 1] !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
8
-
9
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
-
11
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
-
13
- import path from 'path';
14
- import { filterCodeFiles, getCodeFiles, ExampleMiner, readFile, getCommitHash, getRemoteOrigin } from './exampleMiner';
15
-
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rubyTypeProbe = exports.rubyMethodProbe = exports.DeclarationMiner = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _exampleMiner = require("./exampleMiner");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
+ function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) k++; groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != typeof args[args.length - 1] && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
16
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
17
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
18
  var fileFilter = (endpointFilePattern, typeFilePattern, fileName) => {
17
19
  var fileMatch = endpointFilePattern.test(fileName) || typeFilePattern.test(fileName);
18
- return filterCodeFiles(fileName) && fileMatch;
20
+ return (0, _exampleMiner.filterCodeFiles)(fileName) && fileMatch;
19
21
  };
20
-
21
- export var rubyMethodProbe = {
22
+ var rubyMethodProbe = {
22
23
  fileNamePattern: /^(?!test).*_controller.rb$/,
23
- declarationPattern: _wrapRegExp(/(GET|POST|DELETE|PUT|PATCH)[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF](?:"|')\/api\/3\.x([\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uFEFE\uFF00-\uFFFF]+)(?:"|')/i, {
24
+ declarationPattern: _wrapRegExp(/(GET|POST|DELETE|PUT|PATCH)\s(?:"|')\/api\/3\.x(\S+)(?:"|')/i, {
24
25
  verb: 1,
25
26
  path: 2
26
27
  }),
@@ -31,34 +32,32 @@ export var rubyMethodProbe = {
31
32
  return key;
32
33
  }
33
34
  };
34
- export var rubyTypeProbe = {
35
+ exports.rubyMethodProbe = rubyMethodProbe;
36
+ var rubyTypeProbe = {
35
37
  fileNamePattern: /^(?!test).*_mapper.rb$/,
36
- declarationPattern: _wrapRegExp(/class[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]([0-9A-Z_a-z]+)Mapper/i, {
38
+ declarationPattern: _wrapRegExp(/class\s(\w+)Mapper/i, {
37
39
  typeName: 1
38
40
  }),
39
41
  matchToSpecKeyTransform: match => match.groups.typeName
40
42
  };
41
- export class DeclarationMiner {
43
+ exports.rubyTypeProbe = rubyTypeProbe;
44
+ class DeclarationMiner {
42
45
  constructor(sourcePath, methodProbe, typeProbe, originOverride) {
43
46
  this.sourcePath = sourcePath;
44
47
  this.methodProbe = methodProbe;
45
48
  this.typeProbe = typeProbe;
46
49
  this.originOverride = originOverride;
47
-
48
50
  _defineProperty(this, "types", {});
49
-
50
51
  _defineProperty(this, "methods", {});
51
52
  }
52
-
53
53
  execute(sourcePath, methodProbe, typeProbe) {
54
54
  var filePath = sourcePath !== null && sourcePath !== void 0 ? sourcePath : this.sourcePath;
55
55
  var mProbe = methodProbe !== null && methodProbe !== void 0 ? methodProbe : this.methodProbe;
56
56
  var tProbe = typeProbe !== null && typeProbe !== void 0 ? typeProbe : this.typeProbe;
57
- var files = getCodeFiles(filePath, undefined, fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern), ['node_modules', 'dist']);
57
+ var files = (0, _exampleMiner.getCodeFiles)(filePath, undefined, fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern), ['node_modules', 'dist']);
58
58
  files.forEach(f => {
59
59
  var relFile = this.processFile(f);
60
- var fileName = path.basename(relFile);
61
-
60
+ var fileName = _path.default.basename(relFile);
62
61
  if (mProbe.fileNamePattern.test(fileName)) {
63
62
  this.methods = _objectSpread(_objectSpread({}, this.methods), this.mineFile(relFile, f, mProbe));
64
63
  } else {
@@ -67,21 +66,17 @@ export class DeclarationMiner {
67
66
  });
68
67
  return this.lode;
69
68
  }
70
-
71
69
  get commitHash() {
72
70
  process.chdir(this.sourcePath);
73
- return getCommitHash();
71
+ return (0, _exampleMiner.getCommitHash)();
74
72
  }
75
-
76
73
  get remoteOrigin() {
77
74
  if (this.originOverride) {
78
75
  return this.originOverride;
79
76
  }
80
-
81
77
  process.chdir(this.sourcePath);
82
- return getRemoteOrigin();
78
+ return (0, _exampleMiner.getRemoteOrigin)();
83
79
  }
84
-
85
80
  get lode() {
86
81
  return {
87
82
  commitHash: this.commitHash,
@@ -90,22 +85,18 @@ export class DeclarationMiner {
90
85
  methods: this.methods
91
86
  };
92
87
  }
93
-
94
88
  processFile(fileName) {
95
- var relFile = ExampleMiner.relate(this.sourcePath, fileName);
89
+ var relFile = _exampleMiner.ExampleMiner.relate(this.sourcePath, fileName);
96
90
  return relFile;
97
91
  }
98
-
99
92
  mineFile(relFile, fileName, probe) {
100
- return this.mineCode(relFile, readFile(fileName), probe);
93
+ return this.mineCode(relFile, (0, _exampleMiner.readFile)(fileName), probe);
101
94
  }
102
-
103
95
  mineCode(relFile, content, probe) {
104
96
  var lines = content.split('\n');
105
97
  var declarations = {};
106
98
  lines.forEach((line, index) => {
107
99
  var match = probe.declarationPattern.exec(line);
108
-
109
100
  if (match) {
110
101
  var key = probe.matchToSpecKeyTransform(match);
111
102
  declarations[key] = {
@@ -116,6 +107,6 @@ export class DeclarationMiner {
116
107
  });
117
108
  return declarations;
118
109
  }
119
-
120
110
  }
111
+ exports.DeclarationMiner = DeclarationMiner;
121
112
  //# sourceMappingURL=declarationMiner.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/declarationMiner.ts"],"names":["path","filterCodeFiles","getCodeFiles","ExampleMiner","readFile","getCommitHash","getRemoteOrigin","fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","originOverride","execute","filePath","mProbe","tProbe","files","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","remoteOrigin","relate","probe","mineCode","content","lines","split","declarations","line","index","exec","sourceFile"],"mappings":";;;;;;;;;;;;AAyBA,OAAOA,IAAP,MAA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,CAACpC,uBAAN,CAA8BC,KAA9B,CAAZ;AACAwC,QAAAA,YAAY,CAACnC,GAAD,CAAZ,GAAoB;AAClBoC,UAAAA,IAAI,EAAEC,KAAK,GAAG,CADI;AAElBE,UAAAA,UAAU,EAAErB;AAFM,SAApB;AAID;AACF,KATD;AAUA,WAAOiB,YAAP;AACD;;AAhF2B","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe,\n private readonly originOverride: string\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n if (this.originOverride) {\n return this.originOverride\n }\n process.chdir(this.sourcePath)\n return getRemoteOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"file":"declarationMiner.js"}
1
+ {"version":3,"file":"declarationMiner.js","names":["fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","filterCodeFiles","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","path","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","originOverride","execute","filePath","mProbe","tProbe","files","getCodeFiles","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","getCommitHash","remoteOrigin","getRemoteOrigin","ExampleMiner","relate","probe","mineCode","readFile","content","lines","split","declarations","line","index","exec","sourceFile"],"sources":["../../src/declarationMiner.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe,\n private readonly originOverride: string\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n if (this.originOverride) {\n return this.originOverride\n }\n process.chdir(this.sourcePath)\n return getRemoteOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"mappings":";;;;;;AA0BA;AAGA;AAOuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQvB,IAAMA,UAAU,GAAG,CACjBC,mBAA2B,EAC3BC,eAAuB,EACvBC,QAAgB,KACb;EACH,IAAMC,SAAS,GACbH,mBAAmB,CAACI,IAAI,CAACF,QAAQ,CAAC,IAAID,eAAe,CAACG,IAAI,CAACF,QAAQ,CAAC;EACtE,OAAO,IAAAG,6BAAe,EAACH,QAAQ,CAAC,IAAIC,SAAS;AAC/C,CAAC;AAKM,IAAMG,eAAe,GAAG;EAC7BC,eAAe,EAAE,4BAA4B;EAC7CC,kBAAkB,cAChB,8DAA4E;IAAA;IAAA;EAAA;EAC9EC,uBAAuB,EAAGC,KAAsB,IAAK;IACnD,IAAMC,IAAI,GAAGD,KAAK,CAACE,MAAM,CAAED,IAAI,CAACE,iBAAiB,EAAE;IACnD,IAAMC,IAAI,GAAGJ,KAAK,CACfE,MAAM,CAAEE,IAAI,CAACC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAC9BA,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAChBA,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;IAC7B,IAAMC,GAAG,aAAML,IAAI,cAAIG,IAAI,CAAE;IAC7B,OAAOE,GAAG;EACZ;AACF,CAAC;AAAA;AAKM,IAAMC,aAAqB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