@flink-app/test-utils 0.4.4 → 0.4.5

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/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare type HttpOpts = {
12
12
  * Should be invoked prior to using test methods.
13
13
  */
14
14
  export declare function init(_app: FlinkApp<any>, host?: string): void;
15
- export declare function get<T = any>(path: string, opts?: HttpOpts): Promise<FlinkResponse<T>>;
16
- export declare function post<T = any>(path: string, body: any, opts?: HttpOpts): Promise<FlinkResponse<T>>;
17
- export declare function put<T = any>(path: string, body: any, opts?: HttpOpts): Promise<FlinkResponse<T>>;
18
- export declare function del<T = any>(path: string, opts?: HttpOpts): Promise<FlinkResponse<T>>;
15
+ export declare function get<Res = any>(path: string, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
16
+ export declare function post<Req = any, Res = any>(path: string, body: Req, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
17
+ export declare function put<Req = any, Res = any>(path: string, body: Req, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
18
+ export declare function del<Res = any>(path: string, opts?: HttpOpts): Promise<FlinkResponse<Res>>;
package/dist/index.js CHANGED
@@ -140,7 +140,7 @@ function del(path, opts) {
140
140
  exports.del = del;
141
141
  function validateApp() {
142
142
  if (!app) {
143
- throw new Error("App not initialized, run `init(app)` prior to invoking get/post/put/del");
143
+ throw new Error("App not initialized, run `init(app)` prior to invoking get/post/put/del");
144
144
  }
145
145
  }
146
146
  function getUrl(path, queryString) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/test-utils",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Test utils for Flink",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -19,7 +19,7 @@
19
19
  "qs": "^6.7.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@flink-app/flink": "^0.4.4",
22
+ "@flink-app/flink": "^0.4.5",
23
23
  "@types/express": "^4.17.12",
24
24
  "@types/got": "^9.6.12",
25
25
  "@types/node": "^15.6.2",
@@ -29,5 +29,5 @@
29
29
  "tsc-watch": "^4.2.9",
30
30
  "typescript": "^4.2.4"
31
31
  },
32
- "gitHead": "f7b39bc69a69b51311352b1368093bc4c5d05a39"
32
+ "gitHead": "38a0ca4c987f280accc5f4c7f408e51f7b076587"
33
33
  }
package/src/index.ts CHANGED
@@ -6,14 +6,14 @@ let app: FlinkApp<any>;
6
6
  let baseUrl: string;
7
7
 
8
8
  const gotOpts: GotJSONOptions = {
9
- throwHttpErrors: false,
10
- json: true,
11
- retry: 0,
9
+ throwHttpErrors: false,
10
+ json: true,
11
+ retry: 0,
12
12
  };
13
13
 
14
14
  export type HttpOpts = {
15
- qs?: { [x: string]: string | string[] };
16
- headers?: { [x: string]: string };
15
+ qs?: { [x: string]: string | string[] };
16
+ headers?: { [x: string]: string };
17
17
  };
18
18
 
19
19
  /**
@@ -21,86 +21,70 @@ export type HttpOpts = {
21
21
  * Should be invoked prior to using test methods.
22
22
  */
23
23
  export function init(_app: FlinkApp<any>, host = "localhost") {
24
- app = _app;
25
- baseUrl = `http://${host}:${app.port}`;
24
+ app = _app;
25
+ baseUrl = `http://${host}:${app.port}`;
26
26
  }
27
27
 
28
- export async function get<T = any>(
29
- path: string,
30
- opts: HttpOpts = {}
31
- ): Promise<FlinkResponse<T>> {
32
- validateApp();
33
- const res = await got.get(getUrl(path, opts.qs), {
34
- ...gotOpts,
35
- headers: opts.headers,
36
- });
37
- return {
38
- status: res.statusCode,
39
- ...res.body,
40
- };
28
+ export async function get<Res = any>(path: string, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
29
+ validateApp();
30
+ const res = await got.get(getUrl(path, opts.qs), {
31
+ ...gotOpts,
32
+ headers: opts.headers,
33
+ });
34
+ return {
35
+ status: res.statusCode,
36
+ ...res.body,
37
+ };
41
38
  }
42
39
 
43
- export async function post<T = any>(
44
- path: string,
45
- body: any,
46
- opts: HttpOpts = {}
47
- ): Promise<FlinkResponse<T>> {
48
- validateApp();
49
- const res = await got.post(getUrl(path, opts.qs), {
50
- ...gotOpts,
51
- body,
52
- headers: opts.headers,
53
- });
40
+ export async function post<Req = any, Res = any>(path: string, body: Req, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
41
+ validateApp();
42
+ const res = await got.post(getUrl(path, opts.qs), {
43
+ ...gotOpts,
44
+ body: body as any,
45
+ headers: opts.headers,
46
+ });
54
47
 
55
- return {
56
- status: res.statusCode,
57
- ...res.body,
58
- };
48
+ return {
49
+ status: res.statusCode,
50
+ ...res.body,
51
+ };
59
52
  }
60
53
 
61
- export async function put<T = any>(
62
- path: string,
63
- body: any,
64
- opts: HttpOpts = {}
65
- ): Promise<FlinkResponse<T>> {
66
- validateApp();
67
- const res = await got.put(getUrl(path, opts.qs), {
68
- ...gotOpts,
69
- body,
70
- headers: opts.headers,
71
- });
72
- return {
73
- status: res.statusCode,
74
- ...res.body,
75
- };
54
+ export async function put<Req = any, Res = any>(path: string, body: Req, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
55
+ validateApp();
56
+ const res = await got.put(getUrl(path, opts.qs), {
57
+ ...gotOpts,
58
+ body: body as any,
59
+ headers: opts.headers,
60
+ });
61
+ return {
62
+ status: res.statusCode,
63
+ ...res.body,
64
+ };
76
65
  }
77
66
 
78
- export async function del<T = any>(
79
- path: string,
80
- opts: HttpOpts = {}
81
- ): Promise<FlinkResponse<T>> {
82
- validateApp();
83
- const res = await got.delete(getUrl(path, opts.qs), {
84
- ...gotOpts,
85
- headers: opts.headers,
86
- });
87
- return {
88
- status: res.statusCode,
89
- ...res.body,
90
- };
67
+ export async function del<Res = any>(path: string, opts: HttpOpts = {}): Promise<FlinkResponse<Res>> {
68
+ validateApp();
69
+ const res = await got.delete(getUrl(path, opts.qs), {
70
+ ...gotOpts,
71
+ headers: opts.headers,
72
+ });
73
+ return {
74
+ status: res.statusCode,
75
+ ...res.body,
76
+ };
91
77
  }
92
78
 
93
79
  function validateApp() {
94
- if (!app) {
95
- throw new Error(
96
- "App not initialized, run `init(app)` prior to invoking get/post/put/del"
97
- );
98
- }
80
+ if (!app) {
81
+ throw new Error("App not initialized, run `init(app)` prior to invoking get/post/put/del");
82
+ }
99
83
  }
100
84
 
101
85
  function getUrl(path: string, queryString?: HttpOpts["qs"]) {
102
- if (queryString) {
103
- return baseUrl + path + "?" + qs.stringify(queryString);
104
- }
105
- return baseUrl + path;
86
+ if (queryString) {
87
+ return baseUrl + path + "?" + qs.stringify(queryString);
88
+ }
89
+ return baseUrl + path;
106
90
  }