Comparing version 0.14.1 to 0.14.2
@@ -1,4 +0,4 @@ | ||
import { InterfaceDeclaration } from 'ts-morph'; | ||
declare const _default: (methodsInterface: InterfaceDeclaration, indent: string, importName: string, newUrl: string, trailingSlash: boolean) => string; | ||
import { Method } from './parseInterface'; | ||
declare const _default: (methods: Method[], indent: string, importName: string, newUrl: string, trailingSlash: boolean) => string; | ||
export default _default; | ||
//# sourceMappingURL=createMethodsString.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var typescript_1 = require("typescript"); | ||
exports.default = (function (methodsInterface, indent, importName, newUrl, trailingSlash) { | ||
return methodsInterface | ||
.getProperties() | ||
.map(function (method) { | ||
var methodName = method.getName(); | ||
var typeInfo = {}; | ||
method.getChildrenOfKind(typescript_1.SyntaxKind.TypeLiteral).forEach(function (n) { | ||
return n.getProperties().forEach(function (p) { | ||
typeInfo[p.getName()] = { | ||
value: p.getType() ? p.getType().getText() : '', | ||
hasQuestion: p.hasQuestionToken() | ||
}; | ||
}); | ||
}); | ||
var isOptionRequired = (typeInfo.query && !typeInfo.query.hasQuestion) || | ||
(typeInfo.reqBody && !typeInfo.reqBody.hasQuestion) || | ||
(typeInfo.reqHeaders && !typeInfo.reqHeaders.hasQuestion); | ||
exports.default = (function (methods, indent, importName, newUrl, trailingSlash) { | ||
return methods | ||
.map(function (_a) { | ||
var name = _a.name, props = _a.props; | ||
var isOptionRequired = (props.query && !props.query.hasQuestion) || | ||
(props.reqBody && !props.reqBody.hasQuestion) || | ||
(props.reqHeaders && !props.reqHeaders.hasQuestion); | ||
var reqBody = function (method) { | ||
return typeInfo.reqBody | ||
? " data" + (typeInfo.reqBody.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['reqBody']," | ||
return props.reqBody | ||
? " data" + (props.reqBody.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['reqBody']," | ||
: ''; | ||
}; | ||
var query = function (method) { | ||
return typeInfo.query | ||
? " query" + (typeInfo.query.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['query']," | ||
return props.query | ||
? " query" + (props.query.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['query']," | ||
: ''; | ||
}; | ||
var reqHeaders = function (method) { | ||
return typeInfo.reqHeaders | ||
? " headers" + (typeInfo.reqHeaders.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['reqHeaders']," | ||
return props.reqHeaders | ||
? " headers" + (props.reqHeaders.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['reqHeaders']," | ||
: ''; | ||
}; | ||
var resHeaders = function (method) { | ||
return typeInfo.resHeaders ? ", " + importName + "['" + method + "']['resHeaders']" : ''; | ||
return props.resHeaders ? ", " + importName + "['" + method + "']['resHeaders']" : ''; | ||
}; | ||
@@ -43,24 +32,24 @@ var option = function (method) { | ||
var request = function () { | ||
return ", option" + (!typeInfo.reqBody | ||
return ", option" + (!props.reqBody | ||
? '' | ||
: typeInfo.reqFormat | ||
? ", '" + typeInfo.reqFormat.value + "'" | ||
: typeInfo.reqBody && /^(ArrayBuffer|Blob|string)$/.test(typeInfo.reqBody.value) | ||
? ", '" + typeInfo.reqBody.value + "'" | ||
: props.reqFormat | ||
? ", '" + props.reqFormat.value + "'" | ||
: props.reqBody && /^(ArrayBuffer|Blob|string)$/.test(props.reqBody.value) | ||
? ", '" + props.reqBody.value + "'" | ||
: ''); | ||
}; | ||
var resBody = function (method) { | ||
return "" + (typeInfo.resBody ? importName + "['" + method + "']['resBody']" : 'void'); | ||
return "" + (props.resBody ? importName + "['" + method + "']['resBody']" : 'void'); | ||
}; | ||
var resMethodName = function () { | ||
return !typeInfo.resBody | ||
return !props.resBody | ||
? 'send' | ||
: { ArrayBuffer: 'arrayBuffer', Blob: 'blob', string: 'text', FormData: 'formData' }[typeInfo.resBody.value] || 'json'; | ||
: { ArrayBuffer: 'arrayBuffer', Blob: 'blob', string: 'text', FormData: 'formData' }[props.resBody.value] || 'json'; | ||
}; | ||
var quotation = newUrl.includes('${') ? '`' : "'"; | ||
var tmpChanks = [ | ||
"(" + option(methodName) + ") =>", | ||
"client.fetch<" + resBody(methodName) + resHeaders(methodName) + ">(prefix, " + quotation + newUrl + (trailingSlash ? '/' : '') + quotation + ", '" + methodName.toUpperCase() + "'" + request() + ")." + resMethodName() + "()" | ||
"(" + option(name) + ") =>", | ||
"client.fetch<" + resBody(name) + resHeaders(name) + ">(prefix, " + quotation + newUrl + (trailingSlash ? '/' : '') + quotation + ", '" + name.toUpperCase() + "'" + request() + ")." + resMethodName() + "()" | ||
]; | ||
return indent + " " + methodName + ": " + tmpChanks[0] + "\n" + indent + " " + tmpChanks[1] + ",\n" + indent + " $" + methodName + ": async " + tmpChanks[0] + "\n" + indent + " (await " + tmpChanks[1] + ").data"; | ||
return indent + " " + name + ": " + tmpChanks[0] + "\n" + indent + " " + tmpChanks[1] + ",\n" + indent + " $" + name + ": async " + tmpChanks[0] + "\n" + indent + " (await " + tmpChanks[1] + ").data"; | ||
}) | ||
@@ -67,0 +56,0 @@ .join(',\n'); |
@@ -24,12 +24,8 @@ "use strict"; | ||
var path_1 = __importDefault(require("path")); | ||
var ts_morph_1 = require("ts-morph"); | ||
var createMethodsString_1 = __importDefault(require("./createMethodsString")); | ||
var parseInterface_1 = __importDefault(require("./parseInterface")); | ||
exports.default = (function (input, trailingSlash) { | ||
var project = new ts_morph_1.Project(); | ||
project.addSourceFilesAtPaths(input.replace(/\/$/, '') + "/**/*.ts"); | ||
project.resolveSourceFileDependencies(); | ||
var imports = []; | ||
var getMethodsString = function (file, target, indent, newUrl) { | ||
var _a; | ||
var methodsInterface = (_a = project.getSourceFile(target)) === null || _a === void 0 ? void 0 : _a.getInterface('Methods'); | ||
var methodsInterface = parseInterface_1.default(fs_1.default.readFileSync(target, 'utf8'), 'Methods'); | ||
if (!methodsInterface) | ||
@@ -36,0 +32,0 @@ return ''; |
@@ -71,4 +71,3 @@ "use strict"; | ||
exports.optionToRequest = function (option, type) { | ||
var _a; | ||
if (!((_a = option) === null || _a === void 0 ? void 0 : _a.data)) | ||
if (!(option === null || option === void 0 ? void 0 : option.data)) | ||
return option; | ||
@@ -75,0 +74,0 @@ var body; |
{ | ||
"name": "aspida", | ||
"version": "0.14.1", | ||
"version": "0.14.2", | ||
"description": "TypeScript friendly HTTP client wrapper for the browser and node.js", | ||
@@ -28,5 +28,4 @@ "author": "m-mitsuhide <m.mitsuhide@amatelus.com>", | ||
"chokidar": "^3.3.1", | ||
"minimist": "^1.2.0", | ||
"ts-morph": "^6.0.3" | ||
"minimist": "^1.2.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59145
2
52
656
- Removedts-morph@^6.0.3
- Removed@dsherret/to-absolute-glob@2.0.2(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@ts-morph/common@0.2.2(transitive)
- Removed@types/minimatch@3.0.5(transitive)
- Removedarray-differ@3.0.0(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedarrify@2.0.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcode-block-writer@10.1.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfs-extra@8.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedis-absolute@1.0.0(transitive)
- Removedis-negated-glob@1.0.0(transitive)
- Removedis-relative@1.0.0(transitive)
- Removedis-unc-path@1.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedjsonfile@4.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmultimatch@4.0.0(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedts-morph@6.0.3(transitive)
- Removedtypescript@3.7.7(transitive)
- Removedunc-path-regex@0.1.2(transitive)
- Removeduniversalify@0.1.2(transitive)
Updatedminimist@^1.2.3