@faasjs/request 0.0.2-beta.394 → 0.0.2-beta.395

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,7 @@ FaasJS's request module.
12
12
 
13
13
  ## Modules
14
14
 
15
- ### Type aliases
15
+ ### Type Aliases
16
16
 
17
17
  - [Request](#request)
18
18
  - [RequestOptions](#requestoptions)
@@ -24,7 +24,7 @@ FaasJS's request module.
24
24
  - [request](#request-1)
25
25
  - [setMock](#setmock)
26
26
 
27
- ## Type aliases
27
+ ## Type Aliases
28
28
 
29
29
  ### Request
30
30
 
@@ -52,17 +52,17 @@ ___
52
52
  | Name | Type | Description |
53
53
  | :------ | :------ | :------ |
54
54
  | `agent?` | `boolean` | - |
55
- | `auth?` | `string` | HTTP 认证头,格式为 user:password |
56
- | `body?` | { `[key: string]`: `any`; } \| `string` | 请求体 |
57
- | `downloadStream?` | `NodeJS.WritableStream` | 下载流,用于直接将响应内容保存到本地文件,通过 fs.createWriteStream 创建 |
58
- | `file?` | `string` | 上传文件的完整路径 |
59
- | `headers?` | `http.OutgoingHttpHeaders` | 请求头 |
60
- | `method?` | `string` | 请求方法,默认为 GET |
55
+ | `auth?` | `string` | The authentication credentials to use for the request. Format: `username:password` |
56
+ | `body?` | { `[key: string]`: `any`; } \| `string` | - |
57
+ | `downloadStream?` | `NodeJS.WritableStream` | Create a write stream to download a file. |
58
+ | `file?` | `string` | Path of uploading a file to the server. |
59
+ | `headers?` | `http.OutgoingHttpHeaders` | - |
60
+ | `method?` | `string` | The HTTP method to use when making the request. Defaults to GET. |
61
+ | `parse?` | (`body`: `string`) => `any` | Body parser. Defaults to `JSON.parse`. |
61
62
  | `passphrase?` | `string` | - |
62
63
  | `pfx?` | `Buffer` | - |
63
- | `query?` | { `[key: string]`: `any`; } | 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数 |
64
- | `timeout?` | `number` | 最长耗时,单位为毫秒 |
65
- | `parse?` | (`body`: `string`) => `any` | body 解析器,默认为 JSON.parse |
64
+ | `query?` | { `[key: string]`: `any`; } | - |
65
+ | `timeout?` | `number` | - |
66
66
 
67
67
  ___
68
68
 
@@ -106,11 +106,13 @@ ___
106
106
 
107
107
  ### request
108
108
 
109
- ▸ **request**<`T`\>(`url`, `[options={}]?`): `Promise`<[`Response`](#response)<`T`\>\>
109
+ ▸ **request**<`T`\>(`url`, `options?`): `Promise`<[`Response`](#response)<`T`\>\>
110
110
 
111
- 发起网络请求
111
+ Request
112
112
 
113
- **`url`** https://faasjs.com/doc/request.html
113
+ **`Url`**
114
+
115
+ https://faasjs.com/doc/request.html
114
116
 
115
117
  #### Type parameters
116
118
 
@@ -122,8 +124,8 @@ ___
122
124
 
123
125
  | Name | Type | Description |
124
126
  | :------ | :------ | :------ |
125
- | `url` | `string` | 请求路径或完整网址 |
126
- | `[options={}]` | [`RequestOptions`](#requestoptions) | 参数和配置 |
127
+ | `url` | `string` | Url |
128
+ | `options?` | [`RequestOptions`](#requestoptions) | Options |
127
129
 
128
130
  #### Returns
129
131
 
@@ -135,15 +137,19 @@ ___
135
137
 
136
138
  ▸ **setMock**(`handler`): `void`
137
139
 
138
- 设置模拟请求
140
+ Mock requests
141
+
142
+ **`Example`**
139
143
 
140
- **`example`** setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
144
+ ```ts
145
+ setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
146
+ ```
141
147
 
142
148
  #### Parameters
143
149
 
144
150
  | Name | Type | Description |
145
151
  | :------ | :------ | :------ |
146
- | `handler` | `Mock` | 模拟函数,若设置为 null 则表示清除模拟函数 |
152
+ | `handler` | `Mock` | {function \| null} null to disable mock |
147
153
 
148
154
  #### Returns
149
155
 
package/dist/index.d.ts CHANGED
@@ -18,56 +18,64 @@ declare type Response<T = any> = {
18
18
  body: T;
19
19
  };
20
20
  declare type RequestOptions = {
21
- /** 请求头 */
22
21
  headers?: http.OutgoingHttpHeaders;
23
- /** 请求方法,默认为 GET */
22
+ /**
23
+ * The HTTP method to use when making the request. Defaults to GET.
24
+ */
24
25
  method?: string;
25
- /** 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数 */
26
26
  query?: {
27
27
  [key: string]: any;
28
28
  };
29
- /** 请求体 */
30
29
  body?: {
31
30
  [key: string]: any;
32
31
  } | string;
33
- /** 最长耗时,单位为毫秒 */
34
32
  timeout?: number;
35
- /** HTTP 认证头,格式为 user:password */
33
+ /**
34
+ * The authentication credentials to use for the request.
35
+ *
36
+ * Format: `username:password`
37
+ */
36
38
  auth?: string;
37
- /** 上传文件的完整路径 */
39
+ /**
40
+ * Path of uploading a file to the server.
41
+ */
38
42
  file?: string;
39
- /** 下载流,用于直接将响应内容保存到本地文件,通过 fs.createWriteStream 创建 */
43
+ /**
44
+ * Create a write stream to download a file.
45
+ */
40
46
  downloadStream?: NodeJS.WritableStream;
41
47
  pfx?: Buffer;
42
48
  passphrase?: string;
43
49
  agent?: boolean;
44
- /** body 解析器,默认为 JSON.parse */
50
+ /**
51
+ * Body parser. Defaults to `JSON.parse`.
52
+ */
45
53
  parse?: (body: string) => any;
46
54
  };
47
55
  declare type Mock = (url: string, options: RequestOptions) => Promise<Response>;
48
56
  /**
49
- * 设置模拟请求
50
- * @param handler {function | null} 模拟函数,若设置为 null 则表示清除模拟函数
57
+ * Mock requests
58
+ * @param handler {function | null} null to disable mock
51
59
  * @example setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
52
60
  */
53
61
  declare function setMock(handler: Mock | null): void;
54
62
  declare function querystringify(obj: any): string;
55
63
  /**
56
- * 发起网络请求
57
- * @param {string} url 请求路径或完整网址
58
- * @param {object=} [options={}] 参数和配置
59
- * @param {string} [options.method=GET] 请求方法
60
- * @param {object} [options.query={}] 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数
61
- * @param {object} [options.headers={}] 请求头
62
- * @param {object=} options.body 请求体
63
- * @param {number=} options.timeout 最长耗时,单位为毫秒
64
- * @param {string=} options.auth HTTP 认证头,格式为 user:password
65
- * @param {string=} options.file 上传文件的完整路径
66
- * @param {WritableStream=} options.downloadStream 下载流,用于直接将响应内容保存到本地文件
64
+ * Request
65
+ * @param {string} url Url
66
+ * @param {object=} [options={}] Options
67
+ * @param {string} [options.method=GET] Method
68
+ * @param {object} [options.query={}] Query
69
+ * @param {object} [options.headers={}] Headers
70
+ * @param {object=} options.body Body
71
+ * @param {number=} options.timeout Timeout
72
+ * @param {string=} options.auth Auth, format: user:password
73
+ * @param {string=} options.file Upload file path
74
+ * @param {WritableStream=} options.downloadStream Download stream
67
75
  * @param {Buffer=} options.pfx pfx
68
76
  * @param {string=} options.passphrase passphrase
69
77
  * @param {boolean=} options.agent agent
70
- * @param {parse=} options.parse body 解析器,默认为 JSON.parse
78
+ * @param {parse=} options.parse body parser, default is JSON.parse
71
79
  *
72
80
  * @returns {promise}
73
81
  * @url https://faasjs.com/doc/request.html
package/dist/index.js CHANGED
@@ -1,26 +1,10 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
6
  var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
8
  var __export = (target, all) => {
25
9
  for (var name in all)
26
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -133,9 +117,10 @@ async function request(url, {
133
117
  if (body && !options.headers["Content-Length"])
134
118
  options.headers["Content-Length"] = Buffer.byteLength(body);
135
119
  return await new Promise(function(resolve, reject) {
136
- log.debug("request %j", __spreadProps(__spreadValues({}, options), {
120
+ log.debug("request %j", {
121
+ ...options,
137
122
  body
138
- }));
123
+ });
139
124
  const req = protocol.request(options, function(res) {
140
125
  if (downloadStream) {
141
126
  res.pipe(downloadStream);
package/dist/index.mjs CHANGED
@@ -1,22 +1,4 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1
+ "use strict";
20
2
 
21
3
  // src/index.ts
22
4
  import * as http from "http";
@@ -108,9 +90,10 @@ async function request(url, {
108
90
  if (body && !options.headers["Content-Length"])
109
91
  options.headers["Content-Length"] = Buffer.byteLength(body);
110
92
  return await new Promise(function(resolve, reject) {
111
- log.debug("request %j", __spreadProps(__spreadValues({}, options), {
93
+ log.debug("request %j", {
94
+ ...options,
112
95
  body
113
- }));
96
+ });
114
97
  const req = protocol.request(options, function(res) {
115
98
  if (downloadStream) {
116
99
  res.pipe(downloadStream);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/request",
3
- "version": "0.0.2-beta.394",
3
+ "version": "0.0.2-beta.395",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@faasjs/logger": "^0.0.2-beta.394"
25
+ "@faasjs/logger": "^0.0.2-beta.395"
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsup": "*",