api 5.0.6 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,7 +43,18 @@ const petstore = require('api')(
43
43
  'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json'
44
44
  );
45
45
 
46
- petstore.listPets().then(({ data })) => {
46
+ petstore.listPets().then(({ data }) => {
47
+ console.log(`My pets name is ${data[0].name}!`);
48
+ });
49
+ ```
50
+
51
+ The ESM syntax is supported as well:
52
+
53
+ ```js
54
+ import api from 'api';
55
+ const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8');
56
+
57
+ petstore.listPets().then(({ data }) => {
47
58
  console.log(`My pets name is ${data[0].name}!`);
48
59
  });
49
60
  ```
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  exports.__esModule = true;
42
- var promises_1 = __importDefault(require("fs/promises"));
42
+ var fs_1 = __importDefault(require("fs"));
43
43
  var path_1 = __importDefault(require("path"));
44
44
  var stream_1 = __importDefault(require("stream"));
45
45
  var caseless_1 = __importDefault(require("caseless"));
@@ -100,32 +100,42 @@ function merge(src, target) {
100
100
  *
101
101
  */
102
102
  function processFile(paramName, file) {
103
+ var _this = this;
103
104
  if (typeof file === 'string') {
104
105
  // In order to support relative pathed files, we need to attempt to resolve them.
105
106
  var resolvedFile_1 = path_1["default"].resolve(file);
106
- return promises_1["default"]
107
- .stat(resolvedFile_1)
108
- .then(function () { return (0, sync_1["default"])(resolvedFile_1); })
109
- .then(function (fileMetadata) {
110
- var payloadFilename = encodeURIComponent(path_1["default"].basename(resolvedFile_1));
111
- return {
112
- paramName: paramName,
113
- base64: fileMetadata.content.replace(';base64', ";name=".concat(payloadFilename, ";base64")),
114
- filename: payloadFilename,
115
- buffer: fileMetadata.buffer
116
- };
117
- })["catch"](function (err) {
118
- if (err.code === 'ENOENT') {
119
- // It's less than ideal for us to handle files that don't exist like this but because
120
- // `file` is a string it might actually be the full text contents of the file and not
121
- // actually a path.
122
- //
123
- // We also can't really regex to see if `file` *looks*` like a path because one should be
124
- // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
125
- // doesn't *look* like a path, it is one that should still work.
126
- return undefined;
127
- }
128
- throw err;
107
+ return new Promise(function (resolve, reject) {
108
+ fs_1["default"].stat(resolvedFile_1, function (err) { return __awaiter(_this, void 0, void 0, function () {
109
+ var fileMetadata, payloadFilename;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ if (err) {
114
+ if (err.code === 'ENOENT') {
115
+ // It's less than ideal for us to handle files that don't exist like this but because
116
+ // `file` is a string it might actually be the full text contents of the file and not
117
+ // actually a path.
118
+ //
119
+ // We also can't really regex to see if `file` *looks*` like a path because one should be
120
+ // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
121
+ // doesn't *look* like a path, it is one that should still work.
122
+ return [2 /*return*/, resolve(undefined)];
123
+ }
124
+ return [2 /*return*/, reject(err)];
125
+ }
126
+ return [4 /*yield*/, (0, sync_1["default"])(resolvedFile_1)];
127
+ case 1:
128
+ fileMetadata = _a.sent();
129
+ payloadFilename = encodeURIComponent(path_1["default"].basename(resolvedFile_1));
130
+ return [2 /*return*/, resolve({
131
+ paramName: paramName,
132
+ base64: fileMetadata.content.replace(';base64', ";name=".concat(payloadFilename, ";base64")),
133
+ filename: payloadFilename,
134
+ buffer: fileMetadata.buffer
135
+ })];
136
+ }
137
+ });
138
+ }); });
129
139
  });
130
140
  }
131
141
  else if (file instanceof stream_1["default"].Readable) {
package/dist/index.js CHANGED
@@ -149,7 +149,7 @@ var Sdk = /** @class */ (function () {
149
149
  // returning a Promise. When that happens, chaining `sdk.auth().operationId()` will fail.
150
150
  if (['auth', 'config'].includes(method)) {
151
151
  // @todo split this up so we have better types for `auth` and `config`
152
- return function () {
152
+ return function authAndConfigHandler() {
153
153
  var args = [];
154
154
  for (var _i = 0; _i < arguments.length; _i++) {
155
155
  args[_i] = arguments[_i];
@@ -157,7 +157,7 @@ var Sdk = /** @class */ (function () {
157
157
  return target[method].apply(this, args);
158
158
  };
159
159
  }
160
- return function () {
160
+ return function accessorHandler() {
161
161
  var args = [];
162
162
  for (var _i = 0; _i < arguments.length; _i++) {
163
163
  args[_i] = arguments[_i];
@@ -1,2 +1,2 @@
1
1
  export declare const PACKAGE_NAME = "api";
2
- export declare const PACKAGE_VERSION = "5.0.6";
2
+ export declare const PACKAGE_VERSION = "5.0.7";
@@ -3,4 +3,4 @@ exports.__esModule = true;
3
3
  exports.PACKAGE_VERSION = exports.PACKAGE_NAME = void 0;
4
4
  // This file is automatically updated by the build script.
5
5
  exports.PACKAGE_NAME = 'api';
6
- exports.PACKAGE_VERSION = '5.0.6';
6
+ exports.PACKAGE_VERSION = '5.0.7';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api",
3
- "version": "5.0.6",
3
+ "version": "5.0.7",
4
4
  "description": "Magical SDK generation from an OpenAPI definition 🪄",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,10 +41,10 @@
41
41
  "@readme/openapi-parser": "^2.4.0",
42
42
  "caseless": "^0.12.0",
43
43
  "chalk": "^4.1.2",
44
- "commander": "^9.5.0",
44
+ "commander": "^10.0.0",
45
45
  "datauri": "^4.1.0",
46
46
  "execa": "^5.1.1",
47
- "fetch-har": "^8.1.4",
47
+ "fetch-har": "^8.1.5",
48
48
  "figures": "^3.2.0",
49
49
  "find-cache-dir": "^3.3.1",
50
50
  "form-data-encoder": "^1.7.2",
@@ -61,9 +61,9 @@
61
61
  "lodash.startcase": "^4.4.0",
62
62
  "make-dir": "^3.1.0",
63
63
  "node-abort-controller": "^3.0.1",
64
- "oas": "^20.3.0",
64
+ "oas": "^20.4.0",
65
65
  "ora": "^5.4.1",
66
- "prettier": "^2.8.2",
66
+ "prettier": "^2.8.3",
67
67
  "prompts": "^2.4.2",
68
68
  "remove-undefined-objects": "^2.0.2",
69
69
  "semver": "^7.3.8",
@@ -97,7 +97,7 @@
97
97
  "oas-normalize": "^8.3.1",
98
98
  "sinon": "^15.0.0",
99
99
  "sinon-chai": "^3.7.0",
100
- "type-fest": "^3.5.1",
100
+ "type-fest": "^3.5.3",
101
101
  "typescript": "^4.9.4",
102
102
  "unique-temp-dir": "^1.0.0"
103
103
  },
@@ -108,5 +108,5 @@
108
108
  "test/"
109
109
  ]
110
110
  },
111
- "gitHead": "33d0a4e279fd30aa7673b8fdf7bb00399a7c8c4e"
111
+ "gitHead": "b003a05707215a4145a54fe28b98032b78742082"
112
112
  }
@@ -2,7 +2,7 @@ import type { ReadStream } from 'fs';
2
2
  import type { Operation } from 'oas';
3
3
  import type { ParameterObject, SchemaObject } from 'oas/dist/rmoas.types';
4
4
 
5
- import fs from 'fs/promises';
5
+ import fs from 'fs';
6
6
  import path from 'path';
7
7
  import stream from 'stream';
8
8
 
@@ -81,33 +81,34 @@ function processFile(
81
81
  // In order to support relative pathed files, we need to attempt to resolve them.
82
82
  const resolvedFile = path.resolve(file);
83
83
 
84
- return fs
85
- .stat(resolvedFile)
86
- .then(() => datauri(resolvedFile))
87
- .then(fileMetadata => {
84
+ return new Promise((resolve, reject) => {
85
+ fs.stat(resolvedFile, async err => {
86
+ if (err) {
87
+ if (err.code === 'ENOENT') {
88
+ // It's less than ideal for us to handle files that don't exist like this but because
89
+ // `file` is a string it might actually be the full text contents of the file and not
90
+ // actually a path.
91
+ //
92
+ // We also can't really regex to see if `file` *looks*` like a path because one should be
93
+ // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
94
+ // doesn't *look* like a path, it is one that should still work.
95
+ return resolve(undefined);
96
+ }
97
+
98
+ return reject(err);
99
+ }
100
+
101
+ const fileMetadata = await datauri(resolvedFile);
88
102
  const payloadFilename = encodeURIComponent(path.basename(resolvedFile));
89
103
 
90
- return {
104
+ return resolve({
91
105
  paramName,
92
106
  base64: fileMetadata.content.replace(';base64', `;name=${payloadFilename};base64`),
93
107
  filename: payloadFilename,
94
108
  buffer: fileMetadata.buffer,
95
- };
96
- })
97
- .catch(err => {
98
- if (err.code === 'ENOENT') {
99
- // It's less than ideal for us to handle files that don't exist like this but because
100
- // `file` is a string it might actually be the full text contents of the file and not
101
- // actually a path.
102
- //
103
- // We also can't really regex to see if `file` *looks*` like a path because one should be
104
- // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
105
- // doesn't *look* like a path, it is one that should still work.
106
- return undefined;
107
- }
108
-
109
- throw err;
109
+ });
110
110
  });
111
+ });
111
112
  } else if (file instanceof stream.Readable) {
112
113
  return getStream.buffer(file).then(buffer => {
113
114
  const filePath = file.path as string;
package/src/index.ts CHANGED
@@ -103,12 +103,12 @@ class Sdk {
103
103
  // returning a Promise. When that happens, chaining `sdk.auth().operationId()` will fail.
104
104
  if (['auth', 'config'].includes(method)) {
105
105
  // @todo split this up so we have better types for `auth` and `config`
106
- return function (...args: any) {
106
+ return function authAndConfigHandler(...args: any) {
107
107
  return target[method].apply(this, args);
108
108
  };
109
109
  }
110
110
 
111
- return async function (...args: unknown[]) {
111
+ return async function accessorHandler(...args: unknown[]) {
112
112
  if (!(method in target)) {
113
113
  // If this method doesn't exist on the proxy, have we loaded the SDK? If we have, then
114
114
  // this method isn't valid.
@@ -1,3 +1,3 @@
1
1
  // This file is automatically updated by the build script.
2
2
  export const PACKAGE_NAME = 'api';
3
- export const PACKAGE_VERSION = '5.0.6';
3
+ export const PACKAGE_VERSION = '5.0.7';