api-def 0.7.0-alpha.1 → 0.7.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 James Waterhouse
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2019 James Waterhouse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,34 +1,34 @@
1
- # [api-def](https://github.com/Censkh/api-def/) · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Censkh/api-def/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/api-def.svg?style=flat)](https://www.npmjs.com/package/api-def) [![build status](https://img.shields.io/github/workflow/status/censkh/api-def/Node.js%20CI)](https://github.com/Censkh/api-def/actions)
2
-
3
- Typed APIs with middleware support
4
-
5
- API def provides a unified way to type your endpoints allowing for compile time checking of query, body, response and even url parameters
6
-
7
- ``` npm i api-def ```
8
-
9
- - [Documentation](https://censkh.github.io/api-def/)
10
-
11
- ```typescript
12
- import {Api} from "api-def";
13
-
14
- const api = new Api({
15
- baseUrl: "https://my-api/",
16
- name: "My API",
17
- });
18
-
19
- const fetchData = api.endpoint()
20
- .queryOf<{ includeAwesome: boolean; }>()
21
- .responseOf<{ data: {awesome: boolean; } }>()
22
- .build({
23
- id: "fetch_data",
24
- method: "get",
25
- path: "/data"
26
- });
27
-
28
- // calls GET https://my-api/data?includeAwesome=true
29
- const res = await fetchData.submit({
30
- query: {includeAwesome: true}
31
- });
32
-
33
- console.log(res.data); // { data: { awesome: true } }
34
- ```
1
+ # [api-def](https://github.com/Censkh/api-def/) &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Censkh/api-def/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/api-def.svg?style=flat)](https://www.npmjs.com/package/api-def) [![build status](https://img.shields.io/github/workflow/status/censkh/api-def/Node.js%20CI)](https://github.com/Censkh/api-def/actions)
2
+
3
+ Typed APIs with middleware support
4
+
5
+ API def provides a unified way to type your endpoints allowing for compile time checking of query, body, response and even url parameters
6
+
7
+ ``` npm i api-def ```
8
+
9
+ - [Documentation](https://censkh.github.io/api-def/)
10
+
11
+ ```typescript
12
+ import {Api} from "api-def";
13
+
14
+ const api = new Api({
15
+ baseUrl: "https://my-api/",
16
+ name: "My API",
17
+ });
18
+
19
+ const fetchData = api.endpoint()
20
+ .queryOf<{ includeAwesome: boolean; }>()
21
+ .responseOf<{ data: {awesome: boolean; } }>()
22
+ .build({
23
+ id: "fetch_data",
24
+ method: "get",
25
+ path: "/data"
26
+ });
27
+
28
+ // calls GET https://my-api/data?includeAwesome=true
29
+ const res = await fetchData.submit({
30
+ query: {includeAwesome: true}
31
+ });
32
+
33
+ console.log(res.data); // { data: { awesome: true } }
34
+ ```
@@ -7,6 +7,7 @@ export interface MockRequest<R = any, P extends Params | undefined = Params | un
7
7
  body: B;
8
8
  query: Q;
9
9
  headers: Readonly<Headers>;
10
+ url: string;
10
11
  }
11
12
  export interface MockResponse<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
12
13
  statusCode: number;
@@ -37,7 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var Utils = require("./Utils");
40
- var url_1 = require("url");
41
40
  var contextIdCounter = 0;
42
41
  var RequestContext = /** @class */ (function () {
43
42
  function RequestContext(backend, host, config, computedPath, mocking) {
@@ -132,7 +131,7 @@ var RequestContext = /** @class */ (function () {
132
131
  var contentTypeKey = Object.keys(this.computedConfig.headers).find(function (key) { return key.toLowerCase() === "content-type"; });
133
132
  var contentType = contentTypeKey && ((_a = this.computedConfig.headers[contentTypeKey]) === null || _a === void 0 ? void 0 : _a.toString());
134
133
  if (contentType === "application/x-www-form-urlencoded") {
135
- var searchParams = new url_1.URLSearchParams();
134
+ var searchParams = new URLSearchParams();
136
135
  for (var _i = 0, _b = Object.keys(this.computedConfig.body); _i < _b.length; _i++) {
137
136
  var key = _b[_i];
138
137
  var value = this.computedConfig.body[key];
@@ -82,6 +82,7 @@ var MockRequestBackend = /** @class */ (function () {
82
82
  params: (_b = context.computedConfig.params) !== null && _b !== void 0 ? _b : {},
83
83
  query: context.computedConfig.query,
84
84
  headers: (_c = context.computedConfig.headers) !== null && _c !== void 0 ? _c : {},
85
+ url: context.getRequestUrl().toString(),
85
86
  };
86
87
  res = {
87
88
  statusCode: -1,
@@ -7,6 +7,7 @@ export interface MockRequest<R = any, P extends Params | undefined = Params | un
7
7
  body: B;
8
8
  query: Q;
9
9
  headers: Readonly<Headers>;
10
+ url: string;
10
11
  }
11
12
  export interface MockResponse<R = any, P extends Params | undefined = Params | undefined, Q extends Query | undefined = Query | undefined, B extends Body | undefined = Body | undefined> {
12
13
  statusCode: number;
@@ -35,7 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import * as Utils from "./Utils";
38
- import { URLSearchParams } from "url";
39
38
  var contextIdCounter = 0;
40
39
  var RequestContext = /** @class */ (function () {
41
40
  function RequestContext(backend, host, config, computedPath, mocking) {
@@ -80,6 +80,7 @@ var MockRequestBackend = /** @class */ (function () {
80
80
  params: (_b = context.computedConfig.params) !== null && _b !== void 0 ? _b : {},
81
81
  query: context.computedConfig.query,
82
82
  headers: (_c = context.computedConfig.headers) !== null && _c !== void 0 ? _c : {},
83
+ url: context.getRequestUrl().toString(),
83
84
  };
84
85
  res = {
85
86
  statusCode: -1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.7.0-alpha.1",
3
+ "version": "0.7.0",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -66,6 +66,7 @@
66
66
  "@typescript-eslint/eslint-plugin": "4.28.5",
67
67
  "@typescript-eslint/parser": "4.28.5",
68
68
  "ava": "5.0.1",
69
+ "axios": "1.1.3",
69
70
  "cross-env": "7.0.3",
70
71
  "eslint": "7.31.0",
71
72
  "eslint-watch": "7.0.0",