@ama-sdk/core 11.0.0-next.2 → 11.0.0-prerelease.10

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 (57) hide show
  1. package/README.md +13 -0
  2. package/cjs/fwk/core/base-api-constructor.js +5 -1
  3. package/cjs/fwk/index.js +1 -0
  4. package/cjs/fwk/open-api-tools-configuration.js +4 -0
  5. package/cjs/plugins/abort/abort.fetch.js +84 -0
  6. package/cjs/plugins/abort/abort.spec.js +204 -0
  7. package/cjs/plugins/abort/index.js +18 -0
  8. package/cjs/plugins/index.js +3 -2
  9. package/cjs/utils/generators.js +25 -0
  10. package/cjs/utils/index.js +1 -0
  11. package/cli/clear-index.cjs +9 -0
  12. package/cli/files-pack.cjs +14 -3
  13. package/cli/update-spec-from-npm.cjs +75 -0
  14. package/cli/update-spec-from-npm.d.cts +3 -0
  15. package/cli/update-spec-from-npm.d.cts.map +1 -0
  16. package/esm2015/fwk/core/base-api-constructor.js +5 -1
  17. package/esm2015/fwk/index.js +1 -0
  18. package/esm2015/fwk/open-api-tools-configuration.js +1 -0
  19. package/esm2015/plugins/abort/abort.fetch.js +74 -0
  20. package/esm2015/plugins/abort/abort.spec.js +200 -0
  21. package/esm2015/plugins/abort/index.js +1 -0
  22. package/esm2015/plugins/index.js +3 -2
  23. package/esm2015/utils/generators.js +5 -0
  24. package/esm2015/utils/index.js +1 -0
  25. package/package.json +11 -10
  26. package/src/fwk/index.d.ts +1 -0
  27. package/src/fwk/index.d.ts.map +1 -1
  28. package/src/fwk/index.js +1 -0
  29. package/src/fwk/index.js.map +1 -1
  30. package/src/fwk/open-api-tools-configuration.d.ts +28 -0
  31. package/src/fwk/open-api-tools-configuration.d.ts.map +1 -0
  32. package/src/fwk/open-api-tools-configuration.js +2 -0
  33. package/src/fwk/open-api-tools-configuration.js.map +1 -0
  34. package/src/plugins/abort/abort.fetch.d.ts +66 -0
  35. package/src/plugins/abort/abort.fetch.d.ts.map +1 -0
  36. package/src/plugins/abort/abort.fetch.js +32 -0
  37. package/src/plugins/abort/abort.fetch.js.map +1 -0
  38. package/src/plugins/abort/index.d.ts +2 -0
  39. package/src/plugins/abort/index.d.ts.map +1 -0
  40. package/src/plugins/abort/index.js +2 -0
  41. package/src/plugins/abort/index.js.map +1 -0
  42. package/src/plugins/index.d.ts +3 -2
  43. package/src/plugins/index.d.ts.map +1 -1
  44. package/src/plugins/index.js +3 -2
  45. package/src/plugins/index.js.map +1 -1
  46. package/src/utils/generators.d.ts +7 -0
  47. package/src/utils/generators.d.ts.map +1 -0
  48. package/src/utils/generators.js +9 -0
  49. package/src/utils/generators.js.map +1 -0
  50. package/src/utils/index.d.ts +1 -0
  51. package/src/utils/index.d.ts.map +1 -1
  52. package/src/utils/index.js +1 -0
  53. package/src/utils/index.js.map +1 -1
  54. package/cli/clear-index.cjs.map +0 -1
  55. package/cli/files-pack.cjs.map +0 -1
  56. package/schematics/ng-add/index.js.map +0 -1
  57. package/schematics/ng-add/schema.js.map +0 -1
package/README.md CHANGED
@@ -9,6 +9,7 @@ Please refer to the [ama-sdk-schematics](../schematics/README.md) package for ge
9
9
 
10
10
  ## Available plugins
11
11
 
12
+ - [abort](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/abort)
12
13
  - [additional-params](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/additional-params)
13
14
  - [api-configuration-override](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/api-configuration-override)
14
15
  - [api-key](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core/src/plugins/api-key)
@@ -69,3 +70,15 @@ function petApiFactory() {
69
70
  ```
70
71
 
71
72
  > *Note*: Adding a third-party logging service is optional. If undefined, the fallback is the console logger.
73
+
74
+ ### CLI
75
+
76
+ This package also comes with CLI scripts that can facilitate the upgrade and publication of an SDK.
77
+ Use --help on each command for more information
78
+
79
+ | Script | Description |
80
+ |-----------------------------|------------------------------------------------------------------------------------------------|
81
+ | amasdk-clear-index | Remove the index files that are no longer necessary after the deletion of the associated model |
82
+ | amasdk-files-pack | Prepare the dist folder for publication |
83
+ | amasdk-update-spec-from-npm | Update the OpenAPI spec from an NPM package |
84
+
@@ -8,6 +8,10 @@ Object.defineProperty(exports, "isConstructorObject", {
8
8
  return isConstructorObject;
9
9
  }
10
10
  });
11
+ function _type_of(obj) {
12
+ "@swc/helpers - typeof";
13
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
14
+ }
11
15
  function isConstructorObject(args) {
12
- return !!args && args.length === 1 && !!args[0] && typeof args[0] === 'object';
16
+ return !!args && args.length === 1 && !!args[0] && _type_of(args[0]) === 'object';
13
17
  }
package/cjs/fwk/index.js CHANGED
@@ -11,6 +11,7 @@ _export_star(require("./errors"), exports);
11
11
  _export_star(require("./ignore-enum.type"), exports);
12
12
  _export_star(require("./logger"), exports);
13
13
  _export_star(require("./mocks/index"), exports);
14
+ _export_star(require("./open-api-tools-configuration"), exports);
14
15
  _export_star(require("./Reviver"), exports);
15
16
  function _export_star(from, to) {
16
17
  Object.keys(from).forEach(function(k) {
@@ -0,0 +1,4 @@
1
+ /** Configuration of an Open API generator */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "AbortFetch", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return AbortFetch;
9
+ }
10
+ });
11
+ function _class_call_check(instance, Constructor) {
12
+ if (!(instance instanceof Constructor)) {
13
+ throw new TypeError("Cannot call a class as a function");
14
+ }
15
+ }
16
+ function _defineProperties(target, props) {
17
+ for(var i = 0; i < props.length; i++){
18
+ var descriptor = props[i];
19
+ descriptor.enumerable = descriptor.enumerable || false;
20
+ descriptor.configurable = true;
21
+ if ("value" in descriptor) descriptor.writable = true;
22
+ Object.defineProperty(target, descriptor.key, descriptor);
23
+ }
24
+ }
25
+ function _create_class(Constructor, protoProps, staticProps) {
26
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
27
+ if (staticProps) _defineProperties(Constructor, staticProps);
28
+ return Constructor;
29
+ }
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _type_of(obj) {
44
+ "@swc/helpers - typeof";
45
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
46
+ }
47
+ var isPromise = function(result) {
48
+ if ((typeof result === "undefined" ? "undefined" : _type_of(result)) !== 'object') {
49
+ return false;
50
+ }
51
+ return true;
52
+ };
53
+ var AbortFetch = /*#__PURE__*/ function() {
54
+ "use strict";
55
+ function AbortFetch(abortCallback) {
56
+ _class_call_check(this, AbortFetch);
57
+ _define_property(this, "abortCallback", void 0);
58
+ this.abortCallback = abortCallback;
59
+ }
60
+ _create_class(AbortFetch, [
61
+ {
62
+ key: "load",
63
+ value: /** @inheritDoc */ function load(context) {
64
+ var _this = this;
65
+ return {
66
+ transform: function(fetchCall) {
67
+ var abortCallbackResult = _this.abortCallback();
68
+ if (isPromise(abortCallbackResult)) {
69
+ void abortCallbackResult.then(function(res) {
70
+ var _context_controller;
71
+ return res && ((_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort());
72
+ });
73
+ } else if (abortCallbackResult) {
74
+ var _context_controller;
75
+ (_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort();
76
+ }
77
+ return fetchCall;
78
+ }
79
+ };
80
+ }
81
+ }
82
+ ]);
83
+ return AbortFetch;
84
+ }();
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _abortfetch = require("./abort.fetch");
6
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
7
+ try {
8
+ var info = gen[key](arg);
9
+ var value = info.value;
10
+ } catch (error) {
11
+ reject(error);
12
+ return;
13
+ }
14
+ if (info.done) {
15
+ resolve(value);
16
+ } else {
17
+ Promise.resolve(value).then(_next, _throw);
18
+ }
19
+ }
20
+ function _async_to_generator(fn) {
21
+ return function() {
22
+ var self = this, args = arguments;
23
+ return new Promise(function(resolve, reject) {
24
+ var gen = fn.apply(self, args);
25
+ function _next(value) {
26
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
27
+ }
28
+ function _throw(err) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
30
+ }
31
+ _next(undefined);
32
+ });
33
+ };
34
+ }
35
+ function _ts_generator(thisArg, body) {
36
+ var f, y, t, g, _ = {
37
+ label: 0,
38
+ sent: function() {
39
+ if (t[0] & 1) throw t[1];
40
+ return t[1];
41
+ },
42
+ trys: [],
43
+ ops: []
44
+ };
45
+ return g = {
46
+ next: verb(0),
47
+ "throw": verb(1),
48
+ "return": verb(2)
49
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
50
+ return this;
51
+ }), g;
52
+ function verb(n) {
53
+ return function(v) {
54
+ return step([
55
+ n,
56
+ v
57
+ ]);
58
+ };
59
+ }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while(_)try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [
65
+ op[0] & 2,
66
+ t.value
67
+ ];
68
+ switch(op[0]){
69
+ case 0:
70
+ case 1:
71
+ t = op;
72
+ break;
73
+ case 4:
74
+ _.label++;
75
+ return {
76
+ value: op[1],
77
+ done: false
78
+ };
79
+ case 5:
80
+ _.label++;
81
+ y = op[1];
82
+ op = [
83
+ 0
84
+ ];
85
+ continue;
86
+ case 7:
87
+ op = _.ops.pop();
88
+ _.trys.pop();
89
+ continue;
90
+ default:
91
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
+ _ = 0;
93
+ continue;
94
+ }
95
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
+ _.label = op[1];
97
+ break;
98
+ }
99
+ if (op[0] === 6 && _.label < t[1]) {
100
+ _.label = t[1];
101
+ t = op;
102
+ break;
103
+ }
104
+ if (t && _.label < t[2]) {
105
+ _.label = t[2];
106
+ _.ops.push(op);
107
+ break;
108
+ }
109
+ if (t[2]) _.ops.pop();
110
+ _.trys.pop();
111
+ continue;
112
+ }
113
+ op = body.call(thisArg, _);
114
+ } catch (e) {
115
+ op = [
116
+ 6,
117
+ e
118
+ ];
119
+ y = 0;
120
+ } finally{
121
+ f = t = 0;
122
+ }
123
+ if (op[0] & 5) throw op[1];
124
+ return {
125
+ value: op[0] ? op[1] : void 0,
126
+ done: true
127
+ };
128
+ }
129
+ }
130
+ describe('Abort Plugin', function() {
131
+ it('should trigger the callback', /*#__PURE__*/ _async_to_generator(function() {
132
+ var fn, plugin, runner;
133
+ return _ts_generator(this, function(_state) {
134
+ switch(_state.label){
135
+ case 0:
136
+ fn = jest.fn();
137
+ plugin = new _abortfetch.AbortFetch(fn);
138
+ runner = plugin.load({});
139
+ return [
140
+ 4,
141
+ runner.transform(Promise.resolve())
142
+ ];
143
+ case 1:
144
+ _state.sent();
145
+ expect(fn).toHaveBeenCalled();
146
+ return [
147
+ 2
148
+ ];
149
+ }
150
+ });
151
+ }));
152
+ it('should trigger abort signal if true', /*#__PURE__*/ _async_to_generator(function() {
153
+ var defaultContext, fn, plugin, runner;
154
+ return _ts_generator(this, function(_state) {
155
+ switch(_state.label){
156
+ case 0:
157
+ defaultContext = {
158
+ controller: {
159
+ abort: jest.fn()
160
+ }
161
+ };
162
+ fn = jest.fn().mockResolvedValue(true);
163
+ plugin = new _abortfetch.AbortFetch(fn);
164
+ runner = plugin.load(defaultContext);
165
+ return [
166
+ 4,
167
+ runner.transform(Promise.resolve())
168
+ ];
169
+ case 1:
170
+ _state.sent();
171
+ expect(defaultContext.controller.abort).toHaveBeenCalled();
172
+ return [
173
+ 2
174
+ ];
175
+ }
176
+ });
177
+ }));
178
+ it('should not trigger abort signal if false', /*#__PURE__*/ _async_to_generator(function() {
179
+ var defaultContext, fn, plugin, runner;
180
+ return _ts_generator(this, function(_state) {
181
+ switch(_state.label){
182
+ case 0:
183
+ defaultContext = {
184
+ controller: {
185
+ abort: jest.fn()
186
+ }
187
+ };
188
+ fn = jest.fn().mockResolvedValue(false);
189
+ plugin = new _abortfetch.AbortFetch(fn);
190
+ runner = plugin.load(defaultContext);
191
+ return [
192
+ 4,
193
+ runner.transform(Promise.resolve())
194
+ ];
195
+ case 1:
196
+ _state.sent();
197
+ expect(defaultContext.controller.abort).not.toHaveBeenCalled();
198
+ return [
199
+ 2
200
+ ];
201
+ }
202
+ });
203
+ }));
204
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./abort.fetch"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ _export_star(require("./abort/index"), exports);
5
6
  _export_star(require("./additional-params/index"), exports);
6
7
  _export_star(require("./api-configuration-override/index"), exports);
7
8
  _export_star(require("./api-key/index"), exports);
8
9
  _export_star(require("./bot-protection-fingerprint/index"), exports);
10
+ _export_star(require("./client-facts/index"), exports);
9
11
  _export_star(require("./concurrent/index"), exports);
10
12
  _export_star(require("./core/index"), exports);
11
- _export_star(require("./client-facts/index"), exports);
12
13
  _export_star(require("./custom-info/index"), exports);
13
14
  _export_star(require("./exception/index"), exports);
14
15
  _export_star(require("./fetch-cache/index"), exports);
@@ -24,9 +25,9 @@ _export_star(require("./reviver/index"), exports);
24
25
  _export_star(require("./session-id/index"), exports);
25
26
  _export_star(require("./si-token/index"), exports);
26
27
  _export_star(require("./simple-api-key-authentication/index"), exports);
28
+ _export_star(require("./timeout/index"), exports);
27
29
  _export_star(require("./url-rewrite/index"), exports);
28
30
  _export_star(require("./wait-for/index"), exports);
29
- _export_star(require("./timeout/index"), exports);
30
31
  function _export_star(from, to) {
31
32
  Object.keys(from).forEach(function(k) {
32
33
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,25 @@
1
+ // TODO: Change to `openapi` in v11 (ref: #1745)
2
+ /** Name of the specification file copied locally (without extension) */ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ LOCAL_SPEC_FILENAME: function() {
14
+ return LOCAL_SPEC_FILENAME;
15
+ },
16
+ SPEC_JSON_EXTENSION: function() {
17
+ return SPEC_JSON_EXTENSION;
18
+ },
19
+ SPEC_YAML_EXTENSION: function() {
20
+ return SPEC_YAML_EXTENSION;
21
+ }
22
+ });
23
+ var LOCAL_SPEC_FILENAME = 'swagger-spec';
24
+ var SPEC_YAML_EXTENSION = 'yaml';
25
+ var SPEC_JSON_EXTENSION = 'yaml';
@@ -8,6 +8,7 @@ _export_star(require("./ie11"), exports);
8
8
  _export_star(require("./json-token"), exports);
9
9
  _export_star(require("./mime-types"), exports);
10
10
  _export_star(require("./generic-api"), exports);
11
+ _export_star(require("./generators"), exports);
11
12
  function _export_star(from, to) {
12
13
  Object.keys(from).forEach(function(k) {
13
14
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -4,9 +4,18 @@
4
4
  * Remove deleted models' exports
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ const minimist = require("minimist");
7
8
  const node_fs_1 = require("node:fs");
8
9
  const node_path_1 = require("node:path");
10
+ const argv = minimist(process.argv.slice(2));
11
+ const { help } = argv;
9
12
  const baseDir = (0, node_path_1.resolve)(process.cwd(), 'src', 'models', 'base');
13
+ if (help) {
14
+ console.log(`Remove the index files that are no longer necessary after the deletion of the associated model.
15
+ Usage: amasdk-clear-index
16
+ `);
17
+ process.exit(0);
18
+ }
10
19
  void (async () => {
11
20
  const models = await node_fs_1.promises.readdir(baseDir);
12
21
  const shouldRemoveModels = (await Promise.all(models
@@ -12,7 +12,16 @@ const globby = require("globby");
12
12
  const argv = minimist(process.argv.slice(2));
13
13
  const distFolder = argv.dist || 'dist';
14
14
  const baseDir = argv.cwd && path.resolve(process.cwd(), argv.cwd) || process.cwd();
15
- const { watch, noExports } = argv;
15
+ const { help, watch, noExports } = argv;
16
+ if (help) {
17
+ console.log(`Prepare the dist folder for publication. This will copy necessary files from src and update the exports in package.json.
18
+ Usage: amasdk-files-pack [--exports] [--watch]
19
+
20
+ --exports Update the exports in package.json. (Default: true)
21
+ --watch Watch for files changes and run the updates
22
+ `);
23
+ process.exit(0);
24
+ }
16
25
  const files = [
17
26
  { glob: 'README.md', cwdForCopy: baseDir },
18
27
  { glob: 'LICENSE', cwdForCopy: baseDir },
@@ -66,10 +75,12 @@ void (async () => {
66
75
  const copies = files.map(async ({ glob, cwdForCopy }) => {
67
76
  return watch ?
68
77
  Promise.resolve().then(() => require('chokidar')).then((chokidar) => chokidar.watch(glob, { cwd: baseDir }))
69
- .then((watcher) => watcher.on('all', (event, file) => {
78
+ .then((watcher) => watcher.on('all', async (event, file) => {
70
79
  if (event !== 'unlink' && event !== 'unlinkDir') {
71
80
  copyToDist(file, cwdForCopy);
72
- return updateExports();
81
+ if (!noExports) {
82
+ await updateExports();
83
+ }
73
84
  }
74
85
  })) :
75
86
  globby.sync(glob)
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /*
4
+ * Update the OpenAPI spec from an NPM package
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const minimist = require("minimist");
8
+ const node_fs_1 = require("node:fs");
9
+ const node_module_1 = require("node:module");
10
+ const node_path_1 = require("node:path");
11
+ const promises_1 = require("node:fs/promises");
12
+ const core_1 = require("@ama-sdk/core");
13
+ const argv = minimist(process.argv.slice(2));
14
+ const packageName = argv._[0];
15
+ const { help, output, 'package-path': packagePath, quiet } = argv;
16
+ const openApiConfigDefaultPath = './openapitools.json';
17
+ const noop = () => undefined;
18
+ const logger = quiet ? { error: noop, warn: noop, log: noop, info: noop, debug: noop } : console;
19
+ const SPEC_YML_EXTENSION = 'yml';
20
+ const DEFAULT_SPEC_EXPORT_PATH_IN_NPM_MODULE = 'openapi';
21
+ const supportedExtensions = [core_1.SPEC_JSON_EXTENSION, core_1.SPEC_YAML_EXTENSION, SPEC_YML_EXTENSION];
22
+ if (help) {
23
+ // eslint-disable-next-line no-console
24
+ console.log(`This script can be used to update your local spec file from a given locally installed npm package.
25
+ Usage: amasdk-update-spec-from-npm <package-name> [--package-path] [--output] [--quiet]
26
+
27
+ package-name The full identifier of the npm package (e.g. @my-scope/my-package)
28
+ --package-path The relative path inside the npm package where to find the spec file (default: './openapi.yml')
29
+ --output The path where the spec file should be copied (default: './${core_1.LOCAL_SPEC_FILENAME}.${core_1.SPEC_YAML_EXTENSION}')
30
+ --quiet Don't log anything
31
+ `);
32
+ process.exit(0);
33
+ }
34
+ if (!packageName) {
35
+ logger.error('Need to provide packageName, use `amasdk-update-spec-from-npm --help` for more information');
36
+ process.exit(-1);
37
+ }
38
+ void (async () => {
39
+ let specSourcePath;
40
+ const appRequire = (0, node_module_1.createRequire)(node_path_1.posix.join(process.cwd(), 'package.json'));
41
+ const packageJsonPath = appRequire.resolve(`${packageName}/package.json`);
42
+ if (!packagePath) {
43
+ const packageJson = JSON.parse(await (0, promises_1.readFile)(packageJsonPath, { encoding: 'utf8' }));
44
+ const exportMatcher = new RegExp(`^\\./${DEFAULT_SPEC_EXPORT_PATH_IN_NPM_MODULE}\\.(?:${supportedExtensions.join('|')})$`);
45
+ const matchingExport = packageJson.exports && Object.keys(packageJson.exports).find((exportPath) => exportMatcher.test(exportPath));
46
+ if (matchingExport) {
47
+ specSourcePath = appRequire.resolve(node_path_1.posix.join(packageName, matchingExport));
48
+ }
49
+ }
50
+ else {
51
+ specSourcePath = packageJsonPath.replace(/package.json$/, packagePath);
52
+ }
53
+ if (!specSourcePath || !(0, node_fs_1.existsSync)(specSourcePath)) {
54
+ logger.error(`Unable to find source spec from ${packageName}, please make sure it is correctly exported in package.json`);
55
+ process.exit(-2);
56
+ }
57
+ let specDestinationPath = output;
58
+ if (!specDestinationPath) {
59
+ let specSourceExtension = (0, node_path_1.extname)(specSourcePath);
60
+ if (specSourceExtension === `.${SPEC_YML_EXTENSION}`) {
61
+ specSourceExtension = `.${core_1.SPEC_YAML_EXTENSION}`;
62
+ }
63
+ specDestinationPath = `./${core_1.LOCAL_SPEC_FILENAME}${specSourceExtension}`;
64
+ if ((0, node_fs_1.existsSync)(openApiConfigDefaultPath)) {
65
+ const openApiConfig = JSON.parse(await (0, promises_1.readFile)(openApiConfigDefaultPath, { encoding: 'utf8' }));
66
+ const generators = Object.values(openApiConfig['generator-cli']?.generators ?? {});
67
+ if (generators.length === 1 && generators[0].inputSpec && (0, node_path_1.extname)(generators[0].inputSpec) === specSourceExtension) {
68
+ specDestinationPath = generators[0].inputSpec;
69
+ }
70
+ }
71
+ }
72
+ logger.info(`Updating spec file from "${specSourcePath}" to "${specDestinationPath}" (CWD: "${process.cwd()}")`);
73
+ await (0, promises_1.copyFile)(specSourcePath, specDestinationPath);
74
+ })();
75
+ //# sourceMappingURL=update-spec-from-npm.cjs.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=update-spec-from-npm.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-spec-from-npm.d.cts","sourceRoot":"","sources":["../../cli/update-spec-from-npm.cts"],"names":[],"mappings":""}
@@ -1,6 +1,10 @@
1
+ function _type_of(obj) {
2
+ "@swc/helpers - typeof";
3
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
+ }
1
5
  /**
2
6
  * Determine if object passed to the constructor is valid
3
7
  * @param args
4
8
  */ export function isConstructorObject(args) {
5
- return !!args && args.length === 1 && !!args[0] && typeof args[0] === 'object';
9
+ return !!args && args.length === 1 && !!args[0] && _type_of(args[0]) === 'object';
6
10
  }
@@ -7,4 +7,5 @@ export * from './errors';
7
7
  export * from './ignore-enum.type';
8
8
  export * from './logger';
9
9
  export * from './mocks/index';
10
+ export * from './open-api-tools-configuration';
10
11
  export * from './Reviver';
@@ -0,0 +1 @@
1
+ /** Configuration of an Open API generator */ /** Global configuration of Open API Tools */ export { };
@@ -0,0 +1,74 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ function _type_of(obj) {
34
+ "@swc/helpers - typeof";
35
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
36
+ }
37
+ var isPromise = function(result) {
38
+ if ((typeof result === "undefined" ? "undefined" : _type_of(result)) !== 'object') {
39
+ return false;
40
+ }
41
+ return true;
42
+ };
43
+ /** Plugin to abort a Fetch request */ export var AbortFetch = /*#__PURE__*/ function() {
44
+ "use strict";
45
+ function AbortFetch(abortCallback) {
46
+ _class_call_check(this, AbortFetch);
47
+ _define_property(this, "abortCallback", void 0);
48
+ this.abortCallback = abortCallback;
49
+ }
50
+ _create_class(AbortFetch, [
51
+ {
52
+ key: "load",
53
+ value: /** @inheritDoc */ function load(context) {
54
+ var _this = this;
55
+ return {
56
+ transform: function(fetchCall) {
57
+ var abortCallbackResult = _this.abortCallback();
58
+ if (isPromise(abortCallbackResult)) {
59
+ void abortCallbackResult.then(function(res) {
60
+ var _context_controller;
61
+ return res && ((_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort());
62
+ });
63
+ } else if (abortCallbackResult) {
64
+ var _context_controller;
65
+ (_context_controller = context.controller) === null || _context_controller === void 0 ? void 0 : _context_controller.abort();
66
+ }
67
+ return fetchCall;
68
+ }
69
+ };
70
+ }
71
+ }
72
+ ]);
73
+ return AbortFetch;
74
+ }();