xjs-node 3.0.0-alpha.3 → 3.0.0-alpha.4
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/build/func/u-file.d.ts +4 -0
- package/build/func/u-file.js +4 -0
- package/build/obj/http-client.d.ts +25 -0
- package/build/prcs/http-resolver-context.d.ts +14 -1
- package/build/prcs/http-resolver-context.js +10 -3
- package/build/prcs/http-resolver.d.ts +13 -0
- package/build/prcs/http-resolver.js +3 -0
- package/package.json +1 -1
package/build/func/u-file.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import { MaybeArray } from "xjs-common";
|
|
3
3
|
export declare namespace UFile {
|
|
4
|
+
/**
|
|
5
|
+
* make directory. this raise no error if the directory to be made exists.
|
|
6
|
+
* this returns boolean whether mkdir was executed or not.
|
|
7
|
+
*/
|
|
4
8
|
function mkdir(p: MaybeArray<string>): boolean;
|
|
5
9
|
function write(p: MaybeArray<string>, c: string): Promise<void>;
|
|
6
10
|
/**
|
package/build/func/u-file.js
CHANGED
|
@@ -41,6 +41,10 @@ const u_1 = require("./u");
|
|
|
41
41
|
const s_errCode = 1040;
|
|
42
42
|
var UFile;
|
|
43
43
|
(function (UFile) {
|
|
44
|
+
/**
|
|
45
|
+
* make directory. this raise no error if the directory to be made exists.
|
|
46
|
+
* this returns boolean whether mkdir was executed or not.
|
|
47
|
+
*/
|
|
44
48
|
function mkdir(p) {
|
|
45
49
|
const dirPath = (0, u_1.joinPath)(p);
|
|
46
50
|
const e = fs.existsSync(dirPath);
|
|
@@ -107,4 +107,29 @@ export interface HttpClient {
|
|
|
107
107
|
responseType: "buffer";
|
|
108
108
|
}): Promise<HttpResponse<Buffer>>;
|
|
109
109
|
post(url: string, payload: any, op?: RequestOption & ClientOption): Promise<HttpResponse<string>>;
|
|
110
|
+
/**
|
|
111
|
+
* request PUT to the url with new context.
|
|
112
|
+
* @param url target url. (currently https only)
|
|
113
|
+
* @param payload request payload. if this is a Stream, pipe will be used, otherwise if an object, this is treated as json.
|
|
114
|
+
* @param op.headers http headers.
|
|
115
|
+
* @param op.mode {@link s_clientMode} that is imitated. default is random between chrome or firefox.
|
|
116
|
+
* @param op.proxy proxy configuration.
|
|
117
|
+
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
118
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
119
|
+
* @param op.responseType {@link RequestOption.responseType}
|
|
120
|
+
* @returns http response. {@link HttpResponse}
|
|
121
|
+
*/
|
|
122
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
123
|
+
downloadPath: never;
|
|
124
|
+
} & ClientOption & {
|
|
125
|
+
responseType: "string";
|
|
126
|
+
}): Promise<HttpResponse<string>>;
|
|
127
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
128
|
+
downloadPath: never;
|
|
129
|
+
} & ClientOption & {
|
|
130
|
+
responseType: "buffer";
|
|
131
|
+
}): Promise<HttpResponse<Buffer>>;
|
|
132
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
133
|
+
downloadPath: never;
|
|
134
|
+
} & ClientOption): Promise<HttpResponse<string>>;
|
|
110
135
|
}
|
|
@@ -43,9 +43,22 @@ export declare class HttpResolverContext implements HttpClient {
|
|
|
43
43
|
responseType: "buffer";
|
|
44
44
|
}): Promise<HttpResponse<Buffer>>;
|
|
45
45
|
post(url: string, payload: any, op?: RequestOption): Promise<HttpResponse<string>>;
|
|
46
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
47
|
+
downloadPath: never;
|
|
48
|
+
} & {
|
|
49
|
+
responseType: "string";
|
|
50
|
+
}): Promise<HttpResponse<string>>;
|
|
51
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
52
|
+
downloadPath: never;
|
|
53
|
+
} & {
|
|
54
|
+
responseType: "buffer";
|
|
55
|
+
}): Promise<HttpResponse<Buffer>>;
|
|
56
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
57
|
+
downloadPath: never;
|
|
58
|
+
}): Promise<HttpResponse<string>>;
|
|
46
59
|
private createProxyAgent;
|
|
47
60
|
private getIn;
|
|
48
|
-
private
|
|
61
|
+
private postputIn;
|
|
49
62
|
private reqHttps;
|
|
50
63
|
private processResponse;
|
|
51
64
|
private resolveDownloadPath;
|
|
@@ -123,7 +123,14 @@ class HttpResolverContext {
|
|
|
123
123
|
const proxyAgent = this._proxyConfig && await this.createProxyAgent(u);
|
|
124
124
|
const rc = { redirectCount: 0, proxyAgent };
|
|
125
125
|
Object.assign(rc, op);
|
|
126
|
-
return await this._als.run(rc, this.
|
|
126
|
+
return await this._als.run(rc, this.postputIn, u, xjs_common_1.HttpMethod.Post, payload).finally(() => proxyAgent?.destroy());
|
|
127
|
+
}
|
|
128
|
+
async put(url, payload, op) {
|
|
129
|
+
const u = new url_1.URL(url);
|
|
130
|
+
const proxyAgent = this._proxyConfig && await this.createProxyAgent(u);
|
|
131
|
+
const rc = { redirectCount: 0, proxyAgent };
|
|
132
|
+
Object.assign(rc, op);
|
|
133
|
+
return await this._als.run(rc, this.postputIn, u, xjs_common_1.HttpMethod.Put, payload).finally(() => proxyAgent?.destroy());
|
|
127
134
|
}
|
|
128
135
|
createProxyAgent(u) {
|
|
129
136
|
const conf = this._proxyConfig;
|
|
@@ -158,10 +165,10 @@ class HttpResolverContext {
|
|
|
158
165
|
params.headers = xjs_common_1.UHttp.normalizeHeaders(rc.headers);
|
|
159
166
|
return await this.reqHttps(u, params);
|
|
160
167
|
};
|
|
161
|
-
|
|
168
|
+
postputIn = async (u, method, payload) => {
|
|
162
169
|
const params = {};
|
|
163
170
|
const rc = this._als.getStore();
|
|
164
|
-
params.method =
|
|
171
|
+
params.method = method;
|
|
165
172
|
params.headers = xjs_common_1.UHttp.normalizeHeaders(rc.headers);
|
|
166
173
|
let p = payload;
|
|
167
174
|
if (p instanceof stream_1.Stream) {
|
|
@@ -43,4 +43,17 @@ export declare class HttpResolver implements HttpClient {
|
|
|
43
43
|
responseType: "buffer";
|
|
44
44
|
}): Promise<HttpResponse<Buffer>>;
|
|
45
45
|
post(url: string, payload: any, op?: RequestOption & ClientOption): Promise<HttpResponse<string>>;
|
|
46
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
47
|
+
downloadPath: never;
|
|
48
|
+
} & ClientOption & {
|
|
49
|
+
responseType: "string";
|
|
50
|
+
}): Promise<HttpResponse<string>>;
|
|
51
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
52
|
+
downloadPath: never;
|
|
53
|
+
} & ClientOption & {
|
|
54
|
+
responseType: "buffer";
|
|
55
|
+
}): Promise<HttpResponse<Buffer>>;
|
|
56
|
+
put(url: string, payload: any, op?: RequestOption & {
|
|
57
|
+
downloadPath: never;
|
|
58
|
+
} & ClientOption): Promise<HttpResponse<string>>;
|
|
46
59
|
}
|
|
@@ -48,5 +48,8 @@ class HttpResolver {
|
|
|
48
48
|
async post(url, payload, op) {
|
|
49
49
|
return await this.newContext(op).post(url, payload, op);
|
|
50
50
|
}
|
|
51
|
+
async put(url, payload, op) {
|
|
52
|
+
return await this.newContext(op).put(url, payload, op);
|
|
53
|
+
}
|
|
51
54
|
}
|
|
52
55
|
exports.HttpResolver = HttpResolver;
|