From 6f797b3721b76e883bc86aa3f5fee56d505a7d56 Mon Sep 17 00:00:00 2001 From: s0m3on3 Date: Sun, 11 Feb 2018 17:47:51 +0200 Subject: [PATCH] [adone] is, net * [net] add basic http.client * [is] improve type guards --- types/adone/glosses/is.d.ts | 24 +- types/adone/glosses/net/http/client.d.ts | 275 +++++++++++ types/adone/glosses/net/http/index.d.ts | 7 + types/adone/glosses/net/index.d.ts | 7 + types/adone/index.d.ts | 1 + types/adone/test/glosses/is.ts | 92 +++- types/adone/test/glosses/net/http/client.ts | 499 ++++++++++++++++++++ types/adone/tsconfig.json | 4 + 8 files changed, 886 insertions(+), 23 deletions(-) create mode 100644 types/adone/glosses/net/http/client.d.ts create mode 100644 types/adone/glosses/net/http/index.d.ts create mode 100644 types/adone/glosses/net/index.d.ts create mode 100644 types/adone/test/glosses/net/http/client.ts diff --git a/types/adone/glosses/is.d.ts b/types/adone/glosses/is.d.ts index 9065da138b..20d898ca7b 100644 --- a/types/adone/glosses/is.d.ts +++ b/types/adone/glosses/is.d.ts @@ -99,12 +99,12 @@ declare namespace adone { /** * Checks whether the given object is not a primitive, i.e. neither `undefined` nor `null` nor number nor string nor boolean nor symbol) */ - export function object(obj: any): boolean; + export function object(obj: any): obj is object; /** * Checks whether the given object is a plain object, i.e. created by Object */ - export function plainObject(obj: any): boolean; + export function plainObject(obj: any): obj is object; /** * Checks whether the given object is an adone namespace @@ -120,7 +120,7 @@ declare namespace adone { /** * Checks whether the given object is empty, i.e. it is an object(not a primitive), and Object.keys returns an empty array */ - export function emptyObject(obj: any): boolean; + export function emptyObject(obj: any): obj is object; /** * Checks whether the given object has the given owned property @@ -140,7 +140,7 @@ declare namespace adone { /** * Checks whether the given object is like an array, i.e. it is not a primitive, not a function and has length */ - export function arrayLikeObject(obj: any): boolean; + export function arrayLikeObject(obj: any): obj is ArrayLike; /** * Checks whether the given array has the given value @@ -258,7 +258,7 @@ declare namespace adone { /** * Checks whether the given object is a generator function */ - export function generator(obj: any): boolean; + export function generator(obj: any): obj is GeneratorFunction; /** * Checks whether the given object is NaN @@ -320,12 +320,12 @@ declare namespace adone { /** * Checks whether the given object is an adone subsystem */ - export function subsystem(obj: any): boolean; + export function subsystem(obj: any): obj is adone.application.Subsystem; /** * Checks whether the given object is an adone application */ - export function application(obj: any): boolean; + export function application(obj: any): obj is adone.application.Application; /** * Checks whether the given object is an adone logger @@ -335,22 +335,22 @@ declare namespace adone { /** * Checks whether the given object is a core stream */ - export function coreStream(obj: any): boolean; + export function coreStream(obj: any): obj is adone.stream.core.Stream; /** * Checks whether the given object is a fast local map stream */ - export function fastLocalMapStream(obj: any): boolean; + export function fastLocalMapStream(obj: any): obj is adone.fast.I.LocalMapStream; /** * Checks whether the given object is a fast local stream */ - export function fastLocalStream(obj: any): boolean; + export function fastLocalStream(obj: any): obj is adone.fast.I.LocalStream; /** * Checks whether the given object is a fast stream */ - export function fastStream(obj: any): boolean; + export function fastStream(obj: any): obj is adone.fast.I.Stream; /** * Checks whether the given object is a genesis netron @@ -430,7 +430,7 @@ declare namespace adone { /** * Checks whether the given object is iterable, has defined Symbol.iterator property */ - export function iterable(obj: any): boolean; + export function iterable(obj: any): obj is Iterable; /** * true if the OS is Windows diff --git a/types/adone/glosses/net/http/client.d.ts b/types/adone/glosses/net/http/client.d.ts new file mode 100644 index 0000000000..33bccc95ac --- /dev/null +++ b/types/adone/glosses/net/http/client.d.ts @@ -0,0 +1,275 @@ +declare namespace adone.net.http { + namespace client { + namespace I { + interface RequestHeaders { + "Accept"?: string; + "Accept-Charset"?: string; + "Accept-Encoding"?: string; + "Accept-Language"?: string; + "Accept-Datetime"?: string; + "Access-Control-Request-Method"?: string; + "Access-Control-Request-Headers"?: string; + "Authorization"?: string; + "Cache-Control"?: string; + "Connection"?: string; + "Cookie"?: string; + "Content-Length"?: string; + "Content-MD5"?: string; + "Content-Type"?: string; + "Date"?: string; + "Expect"?: string; + "Forwarded"?: string; + "From"?: string; + "Host"?: string; + "If-Match"?: string; + "If-Modified-Since"?: string; + "If-None-Match"?: string; + "If-Range"?: string; + "If-Unmodified-Since"?: string; + "Max-Forwards"?: string; + "Origin"?: string; + "Pragma"?: string; + "Proxy-Authorization"?: string; + "Range"?: string; + "Referer"?: string; + "TE"?: string; + "User-Agent"?: string; + "Upgrade"?: string; + "Via"?: string; + "Warning"?: string; + "X-Requested-With"?: string; + "DNT"?: string; + "X-Forwarded-For"?: string; + "X-Forwarded-Host"?: string; + "X-Forwarded-Proto"?: string; + "Front-End-Https"?: string; + "X-Http-Method-Override"?: string; + "X-ATT-DeviceId"?: string; + "X-Wap-Profile"?: string; + "Proxy-Connection"?: string; + "X-UIDH"?: string; + "X-Csrf-Token"?: string; + "X-Request-ID"?: string; + "X-Correlation-ID"?: string; + + [name: string]: string | undefined; + } + + interface ResponseHeaders { + "accept-patch": string | undefined; + "accept-ranges": string | undefined; + "access-control-allow-credentials": string | undefined; + "access-control-allow-headers": string | undefined; + "access-control-allow-methods": string | undefined; + "access-control-allow-origin": string | undefined; + "access-control-expose-headers": string | undefined; + "access-control-max-age": string | undefined; + "age": string | undefined; + "allow": string | undefined; + "alt-svc": string | undefined; + "cache-control": string | undefined; + "connection": string| undefined; + "content-disposition": string | undefined; + "content-encoding": string| undefined; + "content-language": string | undefined; + "content-length": string| undefined; + "content-location": string| undefined; + "content-md5": string| undefined; + "content-range": string| undefined; + "content-security-policy": string | undefined; + "content-type": string| undefined; + "date": string| undefined; + "etag": string| undefined; + "expires": string| undefined; + "keep-alive": string | undefined; + "last-modified": string | undefined; + "link": string| undefined; + "location": string| undefined; + "p3p": string| undefined; + "pragma": string| undefined; + "proxy-authenticate": string | undefined; + "public-key-pins": string| undefined; + "referer-policy": string | undefined; + "refresh": string | undefined; + "retry-after": string | undefined; + "server": string | undefined; + "set-cookie": string | undefined; + "status": string | undefined; + "strict-transport-security": string| undefined; + "timing-allow-origin": string | undefined; + "tk": string| undefined; + "transfer-encoding": string | undefined; + "upgrade-insecure-requests": string | undefined; + "upgrade": string| undefined; + "vary": string | undefined; + "via": string| undefined; + "warning": string| undefined; + "www-authenticate": string | undefined; + "x-content-duration": string | undefined; + "x-content-security-policy": string | undefined; + "x-content-type-options": string | undefined; + "x-correlation-id": string | undefined; + "x-frame-options": string| undefined; + "x-powered-by": string | undefined; + "x-request-id": string | undefined; + "x-ua-compatible": string | undefined; + "x-webkit-csp": string | undefined; + "x-xss-protection": string | undefined; + + [header: string]: string | undefined; + } + + interface Response { + status: number; + statusText: string; + headers: ResponseHeaders; + data: T; + } + + type Transformer = (data: Data, headers: object, config: I.Options) => Data; + + interface FormValueOptions { + header?: string | { [key: string]: string }; + knownLength?: number; + filename?: string; + filepath?: string; + contentType?: string; + } + + type FormValue = string | Buffer | nodestd.stream.Readable | { + value: string | Buffer | nodestd.stream.Readable; + options: FormValueOptions + }; + + interface UploadProgressEvent { + lengthComputable: boolean; + loaded: number; + total: number; + } + + interface ProxyObject { + protocol?: string; + host?: string; + port?: number; + auth?: { + username?: string; + password?: string; + }; + } + + interface Config { + adapter(config: I.Config): Promise>; + transformRequest: Transformer[]; + transformResponse: Transformer[]; + timeout: number; + xsrfCookieName: string; + xsrfHeaderName: string; + maxContentLength: number; + validateStatus: (status: number) => boolean; + responseType: "buffer" | "string" | "stream" | "json"; + responseEncoding: adone.util.iconv.I.SupportedEncoding; + method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS"; + headers: RequestHeaders; + data: Data; + formData: { + [formKey: string]: FormValue | FormValue[]; + }; + auth: { + username?: string; + password?: string; + }; + httpsAgent: object; + httpAgent: object; + params: object; + rejectUnauthorized: boolean; + proxy: string | ProxyObject | false; + transport: object; + maxRedirects: number; + cancelToken: CancelToken; + onUploadProgress(event: UploadProgressEvent): void; + baseURL: string; + paramsSerializer(params: object): string; + } + + type Options = Partial; + + type Data = string | Buffer | ArrayBuffer | nodestd.stream.Readable | ArrayBufferView | object | undefined; + + interface Request extends Client { + (config: I.Options, ...args: any[]): Promise; + } + } + + class Client { + constructor(options?: I.Options); + + request(config: I.Options & { responseType: "json" }, ...args: any[]): Promise>; + request(config: I.Options & { responseType: "string" }, ...args: any[]): Promise>; + request(config: I.Options & { responseType: "buffer" }, ...args: any[]): Promise>; + request(config: I.Options & { responseType: "stream" }, ...args: any[]): Promise>; + request(config: I.Options, ...args: any[]): Promise>; + + get(url: string, options: I.Options & { responseType: "string" }): Promise>; + get(url: string, options: I.Options & { responseType: "buffer" }): Promise>; + get(url: string, options: I.Options & { responseType: "stream" }): Promise>; + get(url: string, options?: I.Options): Promise>; + + post(url: string, data: I.Data, options: I.Options & { responseType: "string" }): Promise>; + post(url: string, data: I.Data, options: I.Options & { responseType: "buffer" }): Promise>; + post(url: string, data: I.Data, options: I.Options & { responseType: "stream" }): Promise>; + post(url: string, data?: I.Data, options?: I.Options): Promise>; + + put(url: string, data: I.Data, options: I.Options & { responseType: "string" }): Promise>; + put(url: string, data: I.Data, options: I.Options & { responseType: "buffer" }): Promise>; + put(url: string, data: I.Data, options: I.Options & { responseType: "stream" }): Promise>; + put(url: string, data?: I.Data, options?: I.Options): Promise>; + + patch(url: string, data: I.Data, options: I.Options & { responseType: "string" }): Promise>; + patch(url: string, data: I.Data, options: I.Options & { responseType: "buffer" }): Promise>; + patch(url: string, data: I.Data, options: I.Options & { responseType: "stream" }): Promise>; + patch(url: string, data?: I.Data, options?: I.Options): Promise>; + + delete(url: string, options: I.Options & { responseType: "string" }): Promise>; + delete(url: string, options: I.Options & { responseType: "buffer" }): Promise>; + delete(url: string, options: I.Options & { responseType: "stream" }): Promise>; + delete(url: string, options?: I.Options): Promise>; + + options(url: string, options: I.Options & { responseType: "string" }): Promise>; + options(url: string, options: I.Options & { responseType: "buffer" }): Promise>; + options(url: string, options: I.Options & { responseType: "stream" }): Promise>; + options(url: string, options?: I.Options): Promise>; + } + + class Cancel { + message: string; + + constructor(message: string); + } + + namespace I { + type Canceller = (message?: string) => void; + + interface CancelTokenSource { + token: CancelToken; + cancel: Canceller; + } + } + + class CancelToken { + promise: Promise; + reason?: Cancel; + + constructor(executor: I.Canceller); + + throwIfRequested(): void; + + static source(): I.CancelTokenSource; + } + + const request: I.Request; + + function create(options?: I.Options): I.Request; + + function isCancel(obj: any): obj is Cancel; + } +} diff --git a/types/adone/glosses/net/http/index.d.ts b/types/adone/glosses/net/http/index.d.ts new file mode 100644 index 0000000000..a4fbe478d8 --- /dev/null +++ b/types/adone/glosses/net/http/index.d.ts @@ -0,0 +1,7 @@ +/// + +declare namespace adone.net { + namespace http { + // + } +} diff --git a/types/adone/glosses/net/index.d.ts b/types/adone/glosses/net/index.d.ts new file mode 100644 index 0000000000..5e773e4601 --- /dev/null +++ b/types/adone/glosses/net/index.d.ts @@ -0,0 +1,7 @@ +/// + +declare namespace adone { + namespace net { + // + } +} diff --git a/types/adone/index.d.ts b/types/adone/index.d.ts index 4b1620cc15..abcf5165c2 100644 --- a/types/adone/index.d.ts +++ b/types/adone/index.d.ts @@ -21,6 +21,7 @@ /// /// /// +/// /// /// /// diff --git a/types/adone/test/glosses/is.ts b/types/adone/test/glosses/is.ts index 2065dfe01b..045818f0ec 100644 --- a/types/adone/test/glosses/is.ts +++ b/types/adone/test/glosses/is.ts @@ -99,15 +99,34 @@ namespace isTests { } } { const a: boolean = is.json({}); } - { const a: boolean = is.object({}); } - { const a: boolean = is.plainObject({}); } + { + const a: boolean = is.object({}); + const b: any = 2; + if (is.object(b)) { + const c: object = b; + } + } + { + const a: boolean = is.plainObject({}); + const b: any = 2; + if (is.plainObject(b)) { + const c: object = b; + } + } { const a: boolean = is.class({}); } { const a: boolean = is.emptyObject({}); } { const a: boolean = is.propertyOwned({}, "a"); } { const a: boolean = is.propertyDefined({}, "a"); } { const a: boolean = is.conforms({}, {}); } { const a: boolean = is.conforms({}, {}, true); } - { const a: boolean = is.arrayLikeObject({}); } + { + const a: boolean = is.arrayLikeObject({}); + const b: any = {}; + if (is.arrayLikeObject(b)) { + const c: number = b.length; + b[0]; + } + } { const a: boolean = is.inArray(1, [1, 2, 3]); } { const a: boolean = is.inArray(1, [1, 2, 3], 0); } { const a: boolean = is.inArray(1, [1, 2, 3], 0, (a, b) => a === b); } @@ -167,7 +186,13 @@ namespace isTests { } } { const a: boolean = is.callback({}); } - { const a: boolean = is.generator({}); } + { + const a: boolean = is.generator({}); + const b: any = 2; + if (is.generator(b)) { + b().next(); + } + } { const a: boolean = is.nan({}); } { const a: boolean = is.finite({}); @@ -238,13 +263,51 @@ namespace isTests { } } { const a: boolean = is.transform({}); } - { const a: boolean = is.subsystem({}); } - { const a: boolean = is.application({}); } + { + const a: boolean = is.subsystem({}); + const b: any = 2; + if (is.subsystem(b)) { + b.configureSubsystems().then(() => {}); + } + } + { + const a: boolean = is.application({}); + const b: any = 2; + if (is.application(b)) { + b.exitOnSignal("SIGINT"); + } + } { const a: boolean = is.logger({}); } - { const a: boolean = is.coreStream({}); } - { const a: boolean = is.fastStream({}); } - { const a: boolean = is.fastLocalStream({}); } - { const a: boolean = is.fastLocalMapStream({}); } + { + const a: boolean = is.coreStream({}); + const b: any = 2; + if (is.coreStream(b)) { + b.map((x) => 2).forEach((t: number) => { + // + }); + } + } + { + const a: boolean = is.fastStream({}); + const b: any = 2; + if (is.fastStream(b)) { + b.compress("deflate"); + } + } + { + const a: boolean = is.fastLocalStream({}); + const b: any = 2; + if (is.fastLocalStream(b)) { + b.compress("gz"); + } + } + { + const a: boolean = is.fastLocalMapStream({}); + const b: any = 2; + if (is.fastLocalMapStream(b)) { + b.decompress("gz"); + } + } { const a: boolean = is.genesisNetron({}); } { const a: boolean = is.genesisPeer({}); } { const a: boolean = is.netronAdapter({}); } @@ -260,7 +323,14 @@ namespace isTests { { const a: boolean = is.netronStub({}); } { const a: boolean = is.netronRemoteStub({}); } { const a: boolean = is.netronStream({}); } - { const a: boolean = is.iterable({}); } + { + const a: boolean = is.iterable({}); + const b: any = 2; + if (is.iterable(b)) { + const it = b[Symbol.iterator](); + it.next(); + } + } { const a: boolean = is.windows; } { const a: boolean = is.linux; } { const a: boolean = is.freebsd; } diff --git a/types/adone/test/glosses/net/http/client.ts b/types/adone/test/glosses/net/http/client.ts new file mode 100644 index 0000000000..0992c1576c --- /dev/null +++ b/types/adone/test/glosses/net/http/client.ts @@ -0,0 +1,499 @@ +namespace adoneTests.net.http.client { + const { + net: { + http: { + client + } + } + } = adone; + + let bool: boolean; + let num: number; + let str: string; + let buf: Buffer; + let stream: nodestd.stream.Readable; + + namespace Client { + const { + Client + } = client; + + new Client(); + new Client({}); + new Client({ + auth: { + username: "a" + } + }); + new Client({ + auth: { + password: "a" + } + }); + new Client({ + cancelToken: new client.CancelToken(() => {}) + }); + new Client({ + data: Buffer.from("hello") + }); + new Client({ + data: "hello" + }); + new Client({ + data: adone.fs.createReadStream(__filename) + }); + new Client({ + data: new ArrayBuffer(10) + }); + new Client({ + formData: { + a: "string" + } + }); + new Client({ + formData: { + a: ["string"] + } + }); + new Client({ + formData: { + a: [adone.fs.createReadStream(__filename)] + } + }); + new Client({ + formData: { + a: { + value: "string", + options: {} + } + } + }); + new Client({ + formData: { + a: { + value: "string", + options: { + contentType: "a" + } + } + } + }); + new Client({ + formData: { + a: { + value: "string", + options: { + filename: "a" + } + } + } + }); + new Client({ + formData: { + a: { + value: "string", + options: { + header: "a" + } + } + } + }); + new Client({ + formData: { + a: { + value: "string", + options: { + header: { + a: "a" + } + } + } + } + }); + new Client({ + formData: { + a: { + value: "string", + options: { + knownLength: 100500 + } + } + } + }); + new Client({ + formData: { + a: [{ + value: "string", + options: { + knownLength: 100500 + } + }] + } + }); + new Client({ + headers: { + "User-Agent": "true" + } + }); + new Client({ + httpAgent: {} + }); + new Client({ + httpsAgent: {} + }); + new Client({ + maxContentLength: 100500 + }); + new Client({ + maxRedirects: 100500 + }); + new Client({ + method: "GET" + }); + new Client({ + onUploadProgress(event) { + bool = event.lengthComputable; + num = event.loaded; + num = event.total; + } + }); + new Client({ + params: { + a: 1 + } + }); + new Client({ + paramsSerializer(params: object) { + return "asd"; + } + }); + new Client({ + proxy: "socks5://localhost" + }); + new Client({ + proxy: { + protocol: "socks5", + host: "127.0.0.1", + port: 9000, + auth: { + username: "hello", + password: "world" + } + } + }); + + new Client({ + rejectUnauthorized: true + }); + new Client({ + responseEncoding: "CP1251" + }); + new Client({ + responseType: "stream" + }); + new Client({ + timeout: 100 + }); + new Client({ + transformRequest: [(data, headers, config) => { + return data; + }] + }); + new Client({ + transformResponse: [(data, headers, config) => { + return data; + }] + }); + new Client({ + transport: adone.std.http + }); + new Client({ + validateStatus(status) { + return status > 100; + } + }); + new Client({ + xsrfCookieName: "a" + }); + new Client({ + xsrfHeaderName: "a" + }); + + const req = new Client(); + + namespace request { + req.request({ + method: "GET" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + const len = resp.headers["content-length"]; + if (!adone.is.undefined(len)) { + str = len; + } + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.request({ + method: "GET", + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.request({ + method: "GET", + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.request({ + method: "GET", + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + + namespace get { + req.get("url").then((resp) => { + num = resp.status; + str = resp.statusText; + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.get("url", { + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.get("url", { + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.get("url", { + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + + namespace post { + req.post("url", {}).then((resp) => { + num = resp.status; + str = resp.statusText; + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.post("url", {}, { + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.post("url", {}, { + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.post("url", {}, { + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + + namespace put { + req.put("url", {}).then((resp) => { + num = resp.status; + str = resp.statusText; + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.put("url", {}, { + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.put("url", {}, { + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.put("url", {}, { + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + + namespace patch { + req.patch("url", {}).then((resp) => { + num = resp.status; + str = resp.statusText; + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.patch("url", {}, { + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.patch("url", {}, { + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.patch("url", {}, { + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + + namespace _delete { + req.delete("url").then((resp) => { + num = resp.status; + str = resp.statusText; + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.delete("url", { + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.delete("url", { + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.delete("url", { + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + + namespace options { + req.options("url").then((resp) => { + num = resp.status; + str = resp.statusText; + const data = resp.data; + if (!adone.is.object(data)) { + str = data; + } + }); + req.options("url", { + responseType: "string" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + str = resp.data; + }); + req.options("url", { + responseType: "buffer" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + buf = resp.data; + }); + req.options("url", { + responseType: "stream" + }).then((resp) => { + num = resp.status; + str = resp.statusText; + stream = resp.data; + }); + } + } + + namespace request { + client.request.get("htllo").then((x) => { + num = x.status; + }); + } + + namespace create { + client.create(); + client.create({}); + const req = client.create({ + headers: { + "User-Agent": "Hello" + } + }); + req.get("hello world").then((x) => { + num = x.status; + }); + } + + namespace cancel { + const { + Cancel, + CancelToken, + isCancel + } = client; + + new CancelToken((s: string) => 123).promise.then((x) => { + str = x.message; + }); + new CancelToken((s: string) => 123).reason; + CancelToken.source().token.promise; + CancelToken.source().cancel("hello"); + + new Cancel("hello").message; + + const a: any = 2; + + if (isCancel(a)) { + str = a.message; + } + } +} diff --git a/types/adone/tsconfig.json b/types/adone/tsconfig.json index 63a1c88ea8..5764b2d24b 100644 --- a/types/adone/tsconfig.json +++ b/types/adone/tsconfig.json @@ -61,6 +61,9 @@ "glosses/math/matrix.d.ts", "glosses/math/simd.d.ts", "glosses/meta.d.ts", + "glosses/net/http/client.d.ts", + "glosses/net/http/index.d.ts", + "glosses/net/index.d.ts", "glosses/promise.d.ts", "glosses/regex.d.ts", "glosses/semver.d.ts", @@ -120,6 +123,7 @@ "test/glosses/math/matrix.ts", "test/glosses/math/simd.ts", "test/glosses/meta.ts", + "test/glosses/net/http/client.ts", "test/glosses/promise.ts", "test/glosses/regex.ts", "test/glosses/semver.ts",