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

@graywolfai/rest-ts-axios

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graywolfai/rest-ts-axios - npm Package Compare versions

Comparing version 0.2.4 to 0.3.0-alpha.0

66

dist/index.cjs.js

@@ -5,3 +5,6 @@ 'use strict';

var t = require('io-ts');
var axios = _interopDefault(require('axios'));
var PathReporter = require('io-ts/lib/PathReporter');
var Either = require('fp-ts/lib/Either');

@@ -61,3 +64,3 @@ /*! *****************************************************************************

var wrap = function (f) {
var wrap = function (api, f) {
return function () {

@@ -69,16 +72,34 @@ var args = [];

return __awaiter(void 0, void 0, void 0, function () {
var e_1;
var res, route, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, f.apply(void 0, args)];
case 1: return [2 /*return*/, _a.sent()];
case 2:
e_1 = _a.sent();
if (e_1.response) {
return [2 /*return*/, e_1.response];
case 0: return [4 /*yield*/, f.apply(void 0, args)];
case 1:
res = _a.sent();
// This is a kinda messy if/else blocks
// Basically if the url and method are defined (I'm not sure when this would not occur)
// and if the route and route.response are defined, decode the incoming data and raise
// and error if the data is not the expected format!
// We also warn if res.config.url or res.config.method are undefined
// Or if we can't find the route object to help us validate the response data
if (res.config.url && res.config.method) {
route = api[res.config.url]
? api[res.config.url][res.config.method.toUpperCase()]
: undefined;
if (route && route.response) {
result = t.type(route.response).decode(res.data);
if (Either.isLeft(result)) {
throw Error("Data validation failed for \"" + res.config.url + "\": " + PathReporter.PathReporter.report(result).join("\n"));
}
}
else if (!route) {
process.env.NODE_ENV !== "production" &&
console.warn("[rest-ts-axios] Unable to verify response for \"" + res.config.url + "\": Missing route definition!");
}
}
throw e_1;
case 3: return [2 /*return*/];
else {
process.env.NODE_ENV !== "production" &&
console.warn("[rest-ts-axios] Unable to verify response for " + res.config.url);
}
return [2 /*return*/, res];
}

@@ -89,15 +110,16 @@ });

};
var createWrapped = function (config) {
var client = axios.create(config);
client.request = wrap(client.request);
client.get = wrap(client.get);
client.post = wrap(client.post);
client["delete"] = wrap(client["delete"]);
client.patch = wrap(client.patch);
client.put = wrap(client.put);
client.head = wrap(client.head);
var axiosCreate = axios.create.bind(axios);
var create = function (api, config) {
var client = axiosCreate(config);
client.request = wrap(api, client.request);
client.get = wrap(api, client.get);
client.post = wrap(api, client.post);
client["delete"] = wrap(api, client["delete"]);
client.patch = wrap(api, client.patch);
client.put = wrap(api, client.put);
client.head = wrap(api, client.head);
return client;
};
var TypedAxios = Object.assign(axios, { createWrapped: createWrapped });
var TypedAxios = Object.assign(axios, { create: create });
module.exports = TypedAxios;

@@ -0,3 +1,4 @@

import * as t from "io-ts";
import { AxiosRequestConfig, AxiosResponse, CancelStatic, CancelTokenStatic, Method, AxiosInterceptorManager } from "axios";
import { RestTSBase, RestTSRoute, NeverOr, NeverIfUnknown } from "@graywolfai/rest-ts";
import { RestTSBase, RestTSRoute, NeverOr } from "@graywolfai/rest-ts";
export interface TypedAxiosRequestConfig<API extends RestTSBase, Path extends Extract<keyof API, string>, Type extends Extract<keyof API[Path], Method>, RouteDef extends RestTSRoute = API[Path][Type]> extends AxiosRequestConfig {

@@ -10,7 +11,7 @@ url?: Type;

*/
params?: NeverIfUnknown<RouteDef["query"]>;
data?: NeverIfUnknown<RouteDef["body"]>;
params?: t.TypeOf<t.TypeC<Exclude<RouteDef["query"], undefined>>>;
data?: t.TypeOf<t.TypeC<Exclude<RouteDef["body"], undefined>>>;
}
export interface TypedAxiosResponse<API extends RestTSBase, Path extends Extract<keyof API, string>, Type extends Extract<keyof API[Path], Method>, RouteDef extends RestTSRoute = API[Path][Type]> extends AxiosResponse {
data: RouteDef["response"];
data: t.TypeOf<t.TypeC<Exclude<RouteDef["response"], undefined>>>;
config: TypedAxiosRequestConfig<API, Path, Type>;

@@ -32,3 +33,3 @@ }

export interface TypedAxiosStatic extends TypedAxiosInstance<any> {
create<T extends RestTSBase>(config?: AxiosRequestConfig): TypedAxiosInstance<T>;
create<T extends RestTSBase>(api: T, config?: AxiosRequestConfig): TypedAxiosInstance<T>;
/**

@@ -40,3 +41,2 @@ * This is a special function which wraps get, post, path, etc to always return a response even

*/
createWrapped<T extends RestTSBase>(config?: AxiosRequestConfig): TypedAxiosInstance<T>;
Cancel: CancelStatic;

@@ -43,0 +43,0 @@ CancelToken: CancelTokenStatic;

@@ -0,2 +1,5 @@

import { type } from 'io-ts';
import axios from 'axios';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { isLeft } from 'fp-ts/lib/Either';

@@ -56,3 +59,3 @@ /*! *****************************************************************************

var wrap = function (f) {
var wrap = function (api, f) {
return function () {

@@ -64,16 +67,34 @@ var args = [];

return __awaiter(void 0, void 0, void 0, function () {
var e_1;
var res, route, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, f.apply(void 0, args)];
case 1: return [2 /*return*/, _a.sent()];
case 2:
e_1 = _a.sent();
if (e_1.response) {
return [2 /*return*/, e_1.response];
case 0: return [4 /*yield*/, f.apply(void 0, args)];
case 1:
res = _a.sent();
// This is a kinda messy if/else blocks
// Basically if the url and method are defined (I'm not sure when this would not occur)
// and if the route and route.response are defined, decode the incoming data and raise
// and error if the data is not the expected format!
// We also warn if res.config.url or res.config.method are undefined
// Or if we can't find the route object to help us validate the response data
if (res.config.url && res.config.method) {
route = api[res.config.url]
? api[res.config.url][res.config.method.toUpperCase()]
: undefined;
if (route && route.response) {
result = type(route.response).decode(res.data);
if (isLeft(result)) {
throw Error("Data validation failed for \"" + res.config.url + "\": " + PathReporter.report(result).join("\n"));
}
}
else if (!route) {
process.env.NODE_ENV !== "production" &&
console.warn("[rest-ts-axios] Unable to verify response for \"" + res.config.url + "\": Missing route definition!");
}
}
throw e_1;
case 3: return [2 /*return*/];
else {
process.env.NODE_ENV !== "production" &&
console.warn("[rest-ts-axios] Unable to verify response for " + res.config.url);
}
return [2 /*return*/, res];
}

@@ -84,15 +105,16 @@ });

};
var createWrapped = function (config) {
var client = axios.create(config);
client.request = wrap(client.request);
client.get = wrap(client.get);
client.post = wrap(client.post);
client["delete"] = wrap(client["delete"]);
client.patch = wrap(client.patch);
client.put = wrap(client.put);
client.head = wrap(client.head);
var axiosCreate = axios.create.bind(axios);
var create = function (api, config) {
var client = axiosCreate(config);
client.request = wrap(api, client.request);
client.get = wrap(api, client.get);
client.post = wrap(api, client.post);
client["delete"] = wrap(api, client["delete"]);
client.patch = wrap(api, client.patch);
client.put = wrap(api, client.put);
client.head = wrap(api, client.head);
return client;
};
var TypedAxios = Object.assign(axios, { createWrapped: createWrapped });
var TypedAxios = Object.assign(axios, { create: create });
export default TypedAxios;
{
"name": "@graywolfai/rest-ts-axios",
"version": "0.2.4",
"version": "0.3.0-alpha.0",
"description": "",

@@ -10,3 +10,3 @@ "main": "dist/index.cjs.js",

"build": "rollup --config && tsc && rm dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},

@@ -37,16 +37,24 @@ "repository": {

"dependencies": {
"@graywolfai/rest-ts": "^0.2.4",
"rollup": "^2.9.1"
"@graywolfai/rest-ts": "^0.3.0-alpha.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^3.1.1",
"@types/jest": "^22.2.3",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"fp-ts": "^2.6.1",
"io-ts": "^2.2.2",
"jest": "^26.0.1",
"rollup": "^2.9.1",
"ts-jest": "^26.0.0",
"tslib": "^1.11.2",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"peerDependencies": {
"axios": "^0.19.2"
"axios": "^0.19.2",
"fp-ts": "^2.6.1",
"io-ts": "^2.2.2"
},
"gitHead": "d23903235bfbc0ad2697c3ee75a550aef05b120e"
"gitHead": "23ca3a26331378fcefc1e101170b7cf1214e5bef"
}
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