Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asuka/http

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asuka/http - npm Package Compare versions

Comparing version 0.1.0 to 0.1.6

esm/http-response.d.ts

25

esm/bundle.esm.js

@@ -1,16 +0,6 @@

import { __assign, __read } from 'tslib';
import { __assign } from 'tslib';
import { Subject } from 'rxjs';
import { stringify } from 'qs';
import { mergeMap } from 'rxjs/operators';
import { omit } from '@asuka/utils';
var DefaultInterceptor = (function () {
function DefaultInterceptor() {
}
DefaultInterceptor.prototype.intercept = function (req, next) {
return next.handle(req).pipe(mergeMap(function (res) { return res.json(); }));
};
return DefaultInterceptor;
}());
var HttpHandle = (function () {

@@ -20,4 +10,3 @@ function HttpHandle(response$) {

}
HttpHandle.prototype.handle = function (req) {
this.req = req;
HttpHandle.prototype.handle = function () {
return this.response$;

@@ -58,3 +47,3 @@ };

this.defaultHeaders = defaultHeaders;
this.interceptors = [new DefaultInterceptor()];
this.interceptors = [];
}

@@ -110,8 +99,6 @@ HttpClient.prototype.setEndPoint = function (endpoint) {

});
var _a = __read(this.interceptors.reduce(function (_a, cur) {
var _b = __read(_a, 2), req = _b[0], res$ = _b[1];
var res$ = this.interceptors.reduce(function (res$, cur) {
var handler = new HttpHandle(res$);
var _res$ = cur.intercept(req, handler);
return [handler.req, _res$];
}, [httpRequest, _source$]), 2), res$ = _a[1];
return cur.intercept(httpRequest, handler);
}, _source$);
return res$;

@@ -118,0 +105,0 @@ };

@@ -19,5 +19,5 @@ import { Observable } from 'rxjs';

addInterceptors(...interceptors: ConstructorOf<Interceptor>[]): void;
query<T, V>(options: QueryOptions<V>): Observable<T>;
mutate<T, V>(options: QueryOptions<V>): Observable<T>;
query<T, V = {}>(options: QueryOptions<V>): Observable<T>;
mutate<T, V = {}>(options: QueryOptions<V>): Observable<T>;
private request;
}
import * as tslib_1 from "tslib";
import { Subject } from 'rxjs';
import { stringify } from 'qs';
import { DefaultInterceptor } from './interceptor';
import { HttpHandle } from './http-handle';

@@ -12,3 +11,3 @@ import { HttpRequest } from './http-request';

this.defaultHeaders = defaultHeaders;
this.interceptors = [new DefaultInterceptor()];
this.interceptors = [];
}

@@ -64,8 +63,6 @@ HttpClient.prototype.setEndPoint = function (endpoint) {

});
var _a = tslib_1.__read(this.interceptors.reduce(function (_a, cur) {
var _b = tslib_1.__read(_a, 2), req = _b[0], res$ = _b[1];
var res$ = this.interceptors.reduce(function (res$, cur) {
var handler = new HttpHandle(res$);
var _res$ = cur.intercept(req, handler);
return [handler.req, _res$];
}, [httpRequest, _source$]), 2), res$ = _a[1];
return cur.intercept(httpRequest, handler);
}, _source$);
return res$;

@@ -72,0 +69,0 @@ };

import { Observable } from 'rxjs';
import { HttpRequest } from './http-request';
export declare class HttpHandle<T> {
private response$;
req: HttpRequest;
private readonly response$;
constructor(response$: Observable<T>);
handle(req: HttpRequest): Observable<T>;
handle(): Observable<T>;
}

@@ -5,4 +5,3 @@ var HttpHandle = (function () {

}
HttpHandle.prototype.handle = function (req) {
this.req = req;
HttpHandle.prototype.handle = function () {
return this.response$;

@@ -9,0 +8,0 @@ };

@@ -7,4 +7,1 @@ import { Observable } from 'rxjs';

}
export declare class DefaultInterceptor implements Interceptor {
intercept<T, U>(req: HttpRequest, next: HttpHandle<T>): Observable<U>;
}

@@ -1,11 +0,1 @@

import { mergeMap } from 'rxjs/operators';
var DefaultInterceptor = (function () {
function DefaultInterceptor() {
}
DefaultInterceptor.prototype.intercept = function (req, next) {
return next.handle(req).pipe(mergeMap(function (res) { return res.json(); }));
};
return DefaultInterceptor;
}());
export { DefaultInterceptor };
//# sourceMappingURL=interceptor.js.map

@@ -8,14 +8,4 @@ 'use strict';

var qs = require('qs');
var operators = require('rxjs/operators');
var utils = require('@asuka/utils');
var DefaultInterceptor = (function () {
function DefaultInterceptor() {
}
DefaultInterceptor.prototype.intercept = function (req, next) {
return next.handle(req).pipe(operators.mergeMap(function (res) { return res.json(); }));
};
return DefaultInterceptor;
}());
var HttpHandle = (function () {

@@ -25,4 +15,3 @@ function HttpHandle(response$) {

}
HttpHandle.prototype.handle = function (req) {
this.req = req;
HttpHandle.prototype.handle = function () {
return this.response$;

@@ -63,3 +52,3 @@ };

this.defaultHeaders = defaultHeaders;
this.interceptors = [new DefaultInterceptor()];
this.interceptors = [];
}

@@ -115,8 +104,6 @@ HttpClient.prototype.setEndPoint = function (endpoint) {

});
var _a = tslib_1.__read(this.interceptors.reduce(function (_a, cur) {
var _b = tslib_1.__read(_a, 2), req = _b[0], res$ = _b[1];
var res$ = this.interceptors.reduce(function (res$, cur) {
var handler = new HttpHandle(res$);
var _res$ = cur.intercept(req, handler);
return [handler.req, _res$];
}, [httpRequest, _source$]), 2), res$ = _a[1];
return cur.intercept(httpRequest, handler);
}, _source$);
return res$;

@@ -123,0 +110,0 @@ };

{
"name": "@asuka/http",
"version": "0.1.0",
"version": "0.1.6",
"description": "A request library",

@@ -33,4 +33,6 @@ "keywords": [

"@asuka/types": "^0.1.0",
"@asuka/utils": "^0.1.0",
"qs": "^6.7.0"
"@asuka/utils": "^0.1.6",
"qs": "^6.7.0",
"rxjs": "^6.5.2",
"tslib": "^1.10.0"
},

@@ -40,3 +42,3 @@ "devDependencies": {

},
"gitHead": "d387ea9c6f8ef47cb255a3f20d9ed6fc16c31bb3"
"gitHead": "3c063c4c7f016ab6edaf53cc8de5ea754cb289be"
}

@@ -5,3 +5,3 @@ import { Observable, Subject } from 'rxjs'

import { Interceptor, DefaultInterceptor } from './interceptor'
import { Interceptor } from './interceptor'
import { HttpHandle } from './http-handle'

@@ -20,3 +20,3 @@ import { HttpRequest } from './http-request'

export class HttpClient {
private interceptors: Interceptor[] = [new DefaultInterceptor()]
private interceptors: Interceptor[] = []

@@ -35,3 +35,3 @@ constructor(private endpoint: string, private defaultHeaders: HeadersInit = {}) {}

query<T, V>(options: QueryOptions<V>): Observable<T> {
query<T, V = {}>(options: QueryOptions<V>): Observable<T> {
const body = {

@@ -48,3 +48,3 @@ variables: options.variables,

mutate<T, V>(options: QueryOptions<V>): Observable<T> {
mutate<T, V = {}>(options: QueryOptions<V>): Observable<T> {
const body = {

@@ -87,10 +87,8 @@ variables: options.variables,

})
const [, res$] = this.interceptors.reduce(
([req, res$], cur) => {
const res$ = this.interceptors.reduce(
(res$, cur) => {
const handler = new HttpHandle(res$)
const _res$ = cur.intercept(req, handler)
return [handler.req, _res$] as [HttpRequest, Observable<Response>]
return cur.intercept(httpRequest, handler)
},
// tslint:disable-next-line no-useless-cast
[httpRequest, _source$ as Observable<Response>] as [HttpRequest, Observable<Response>],
_source$ as Observable<Response>,
)

@@ -97,0 +95,0 @@ return (res$ as Observable<any>) as Observable<T>

import { Observable } from 'rxjs'
import { HttpRequest } from './http-request'
export class HttpHandle<T> {
public req!: HttpRequest
constructor(private readonly response$: Observable<T>) {}
constructor(private response$: Observable<T>) {}
handle(req: HttpRequest): Observable<T> {
this.req = req
handle(): Observable<T> {
return this.response$
}
}
import { Observable } from 'rxjs'
import { mergeMap } from 'rxjs/operators'
import { HttpRequest } from './http-request'

@@ -9,7 +8,1 @@ import { HttpHandle } from './http-handle'

}
export class DefaultInterceptor implements Interceptor {
intercept<T, U>(req: HttpRequest, next: HttpHandle<T>): Observable<U> {
return next.handle(req).pipe(mergeMap((res: any) => res.json() as Promise<U>))
}
}

@@ -12,3 +12,11 @@ {

{ "path": "../utils" }
],
"include": [
"./src/**/*.ts"
],
"exclude": [
"esm",
"lib",
"node_modules"
]
}

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