New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

axios-interface

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-interface - npm Package Compare versions

Comparing version 1.4.7 to 2.0.0-alpha.0

3

es/createFactory.d.ts
import { Options, Method, UrlTemplate } from './types';
declare type OptionFunc = (options: Options) => Options;
declare const createFactory: (defaultOptions?: Options) => {
request: (method: Method, url: string, params?: any, options?: Options) => Promise<any>;
createInterface: <TParams = void, T = unknown>(method: Method, urlTemplate: UrlTemplate, optionsOrEnhance?: Options, exOptions?: never) => (params: TParams, requestOptions?: Options) => Promise<T>;
createInterface: <TParams = void, T = unknown>(method: Method, urlTemplate: UrlTemplate, options?: Options | OptionFunc) => (params: TParams, options?: Options | OptionFunc) => Promise<T>;
};
export default createFactory;

@@ -14,16 +14,7 @@ /**

};
const getInterfaceOptions = (optionsOrEnhance, exOptions, defaultOptions) => {
let options = {};
// istanbul ignore next
if (typeof optionsOrEnhance === 'function') {
console.warn('use function as options is deprecated, use {enhance: func} instead');
options = exOptions;
options.enhance = optionsOrEnhance;
const getMergedOptions = (options, defaultOptions) => {
if (typeof options === 'function') {
return Object.assign(Object.assign({}, defaultOptions), options(defaultOptions));
}
else {
// istanbul ignore next
options = optionsOrEnhance !== null && optionsOrEnhance !== void 0 ? optionsOrEnhance : {};
}
options = Object.assign(Object.assign({}, defaultOptions), options);
return options;
return Object.assign(Object.assign({}, defaultOptions), options);
};

@@ -52,6 +43,6 @@ const createFactory = (defaultOptions = {}) => {

// 使用URL的模板快速创建一个API接口
const createInterface = (method, urlTemplate, optionsOrEnhance = {}, exOptions = {}) => {
const options = getInterfaceOptions(optionsOrEnhance, exOptions, defaultOptions);
options.urlTemplate = urlTemplate;
const { enhance, encodePathVariable } = options;
const createInterface = (method, urlTemplate, options = {}) => {
const interfaceOptions = getMergedOptions(options, defaultOptions);
interfaceOptions.urlTemplate = urlTemplate;
const { enhance, encodePathVariable } = interfaceOptions;
let toRequestData = (value) => value;

@@ -70,14 +61,11 @@ let toRequestUrl = () => urlTemplate;

}
const templateRequest = (params, requestOptions) => {
const templateRequest = (params, options = {}) => {
const requestUrl = toRequestUrl(params);
const requestData = toRequestData(params);
let combinedOptions = options;
if (requestOptions) {
combinedOptions = Object.assign(Object.assign({}, options), requestOptions);
}
return request(method, requestUrl, requestData, combinedOptions);
const requestOptions = getMergedOptions(options, interfaceOptions);
return request(method, requestUrl, requestData, requestOptions);
};
if (enhance) {
// 如果是 factory 时期的 enhance,应该被强制使用 any 这样更 general 的类型定义
return enhance(templateRequest, options);
return enhance(templateRequest, interfaceOptions);
}

@@ -84,0 +72,0 @@ return templateRequest;

@@ -1,5 +0,7 @@

import axios from 'axios';
import axios, { AxiosError } from 'axios';
import createFactory from './createFactory';
// 提供 axios 以测试
export { axios, createFactory };
// 提供 axios 的部分 ts 类型,在调整 createFactory 时可能会被使用
export { AxiosError };
export * from './types';
{
"name": "axios-interface",
"version": "1.4.7",
"version": "2.0.0-alpha.0",
"description": "create interface from axios",
"main": "lib/index.js",
"main": "es/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"files": ["es"],
"sideEffects": false,
"files": [
"lib",
"es"
],
"scripts": {
"build": "rm -rf lib/ && tsc",
"build-es": "rm -rf es/ && tsc --project tsconfig.es.json",
"build": "rm -rf es/ && tsc",
"lint": "skr lint",
"test": "skr test -- --coverage",
"prepublishOnly": "yarn build && yarn build-es"
"prepublishOnly": "yarn build"
},

@@ -27,3 +23,3 @@ "repository": {

"dependencies": {
"axios": "^0.26.1"
"axios": "^1.1.2"
},

@@ -30,0 +26,0 @@ "devDependencies": {

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