Socket
Socket
Sign inDemoInstall

aspida

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aspida - npm Package Compare versions

Comparing version 0.14.1 to 0.14.2

dist/parseInterface.d.ts

4

dist/createMethodsString.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc