@autometa/http 1.4.19 → 2.0.0-rc.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.
Files changed (55) hide show
  1. package/README.md +107 -2
  2. package/dist/assertions/http-adapters.d.ts +35 -0
  3. package/dist/assertions/http-assertions-plugin.d.ts +16 -0
  4. package/dist/assertions/http-ensure.d.ts +42 -0
  5. package/dist/axios-transport.d.ts +22 -0
  6. package/dist/default-schema.d.ts +8 -0
  7. package/dist/fetch-transport.d.ts +21 -0
  8. package/dist/http-request.d.ts +109 -0
  9. package/dist/http-response.d.ts +77 -0
  10. package/dist/http.d.ts +300 -0
  11. package/dist/index.cjs +2076 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.ts +15 -1116
  14. package/dist/index.js +1727 -845
  15. package/dist/index.js.map +1 -1
  16. package/dist/plugins.d.ts +43 -0
  17. package/dist/request-meta.config.d.ts +56 -0
  18. package/dist/schema.map.d.ts +11 -0
  19. package/dist/transform-response.d.ts +1 -0
  20. package/dist/transport.d.ts +11 -0
  21. package/dist/types.d.ts +39 -0
  22. package/package.json +31 -31
  23. package/.eslintignore +0 -3
  24. package/.eslintrc.cjs +0 -4
  25. package/.turbo/turbo-lint$colon$fix.log +0 -4
  26. package/.turbo/turbo-prettify.log +0 -5
  27. package/.turbo/turbo-test.log +0 -120
  28. package/CHANGELOG.md +0 -326
  29. package/dist/esm/index.js +0 -1117
  30. package/dist/esm/index.js.map +0 -1
  31. package/dist/index.d.cts +0 -1116
  32. package/src/axios-client.ts +0 -35
  33. package/src/default-client-factory.axios.spec.ts +0 -9
  34. package/src/default-client-factory.other.spec.ts +0 -13
  35. package/src/default-client-factory.ts +0 -7
  36. package/src/default-schema.spec.ts +0 -74
  37. package/src/default-schema.ts +0 -127
  38. package/src/http-client.ts +0 -20
  39. package/src/http-request.spec.ts +0 -172
  40. package/src/http-request.ts +0 -201
  41. package/src/http-response.ts +0 -107
  42. package/src/http.spec.ts +0 -189
  43. package/src/http.ts +0 -907
  44. package/src/index.ts +0 -13
  45. package/src/node_modules/.vitest/deps/_metadata.json +0 -8
  46. package/src/node_modules/.vitest/deps/package.json +0 -3
  47. package/src/node_modules/.vitest/results.json +0 -1
  48. package/src/request-meta.config.spec.ts +0 -81
  49. package/src/request-meta.config.ts +0 -134
  50. package/src/request.config.ts +0 -34
  51. package/src/schema.map.spec.ts +0 -50
  52. package/src/schema.map.ts +0 -68
  53. package/src/transform-response.ts +0 -43
  54. package/src/types.ts +0 -37
  55. package/tsup.config.ts +0 -14
@@ -0,0 +1,39 @@
1
+ import type { HTTPRequest } from "./http-request";
2
+ import type { HTTPResponse } from "./http-response";
3
+ type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
4
+ type IntRange<From extends number, To extends number> = Exclude<Enumerate<To>, Enumerate<From>> | From;
5
+ export type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT";
6
+ export type HTTPAdditionalOptions<T = Record<string, unknown>> = Partial<T> & Record<string, unknown>;
7
+ export type SchemaParser = {
8
+ parse: (data: unknown) => unknown;
9
+ } | {
10
+ validate: (data: unknown) => unknown;
11
+ } | ((data: unknown) => unknown);
12
+ export type StatusCode = IntRange<100, 600>;
13
+ export type RequestHook = <T = unknown>(state: HTTPRequest<T>) => unknown;
14
+ export type ResponseHook<T> = (state: HTTPResponse<T>) => unknown;
15
+ export interface HTTPRetryContext {
16
+ error: unknown;
17
+ attempt: number;
18
+ request: HTTPRequest<unknown>;
19
+ response?: HTTPResponse<unknown>;
20
+ }
21
+ export type HTTPRetryPredicate = (context: HTTPRetryContext) => boolean | Promise<boolean>;
22
+ export interface HTTPRetryOptions {
23
+ attempts: number;
24
+ delay?: number | ((attempt: number) => number | Promise<number>);
25
+ retryOn?: HTTPRetryPredicate;
26
+ }
27
+ export type QueryParamPrimitive = string | number | boolean | null | undefined;
28
+ export type QueryParamValue = QueryParamPrimitive | QueryParamValue[] | {
29
+ [key: string]: QueryParamValue;
30
+ };
31
+ export type QueryParamSerializer = (params: Record<string, QueryParamValue>) => string;
32
+ export type QueryParamArrayFormat = "repeat" | "brackets" | "indices" | "comma" | "json";
33
+ export type QueryParamObjectFormat = "brackets" | "dot" | "json";
34
+ export interface QueryParamSerializationOptions {
35
+ arrayFormat?: QueryParamArrayFormat;
36
+ objectFormat?: QueryParamObjectFormat;
37
+ serializer?: QueryParamSerializer | null;
38
+ }
39
+ export {};
package/package.json CHANGED
@@ -1,57 +1,57 @@
1
1
  {
2
2
  "name": "@autometa/http",
3
- "version": "1.4.19",
4
- "description": "An Axios Based HTTP Client for Autometa",
3
+ "version": "2.0.0-rc.0",
4
+ "description": "",
5
5
  "type": "module",
6
- "main": "dist/index.js",
7
- "module": "dist/esm/index.js",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
9
12
  "exports": {
10
- "import": "./dist/esm/index.js",
11
- "require": "./dist/index.js",
12
- "default": "./dist/esm/index.js",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js",
13
16
  "types": "./dist/index.d.ts"
14
17
  },
15
18
  "license": "MIT",
19
+ "dependencies": {
20
+ "cli-highlight": "^2.1.11",
21
+ "url-join-ts": "^1.0.5",
22
+ "@autometa/assertions": "1.0.0-rc.0",
23
+ "@autometa/errors": "1.0.0-rc.0",
24
+ "@autometa/status-codes": "1.0.0-rc.0"
25
+ },
16
26
  "devDependencies": {
17
27
  "@types/node": "^18.11.18",
18
- "@types/uuid": "^9.0.1",
19
28
  "@typescript-eslint/eslint-plugin": "^5.54.1",
20
29
  "@typescript-eslint/parser": "^5.54.1",
21
- "@vitest/coverage-v8": "^1.4.0",
22
30
  "eslint": "^8.37.0",
23
31
  "eslint-config-prettier": "^8.3.0",
24
- "myzod": "^1.10.2",
25
32
  "rimraf": "^4.1.2",
26
33
  "tsup": "^7.2.0",
27
34
  "typescript": "^4.9.5",
28
35
  "vitest": "1.4.0",
29
36
  "eslint-config-custom": "0.6.0",
30
- "@autometa/types": "^0.4.1",
31
- "tsconfig": "0.7.0"
32
- },
33
- "dependencies": {
34
- "@stdlib/assert-is-json": "^0.1.1",
35
- "@types/qs": "^6.9.11",
36
- "axios": "^1.5.1",
37
- "class-transformer": "^0.5.1",
38
- "cli-highlight": "^2.1.11",
39
- "reflect-metadata": "^0.1.13",
40
- "ts-retry": "^4.2.3",
41
- "url-join-ts": "^1.0.5",
42
- "@autometa/app": "^0.4.1",
43
- "@autometa/dto-builder": "^0.13.10",
44
- "@autometa/injection": "^0.1.4",
45
- "@autometa/status-codes": "^0.4.1",
46
- "@autometa/errors": "^0.2.2"
37
+ "tsconfig": "0.7.0",
38
+ "tsup-config": "0.1.0"
47
39
  },
48
40
  "scripts": {
41
+ "type-check": "tsc --noEmit -p tsconfig.dev.json",
42
+ "type-check:watch": "tsc --noEmit --watch -p tsconfig.dev.json",
43
+ "build": "tsup && pnpm run build:types",
44
+ "build:types": "rimraf tsconfig.types.tsbuildinfo && tsc --build tsconfig.types.json",
45
+ "build:watch": "tsup --watch",
46
+ "dev": "tsup --watch",
49
47
  "test": "vitest run --passWithNoTests",
50
- "prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
48
+ "test:watch": "vitest --passWithNoTests",
49
+ "test:ui": "vitest --ui --passWithNoTests",
50
+ "test:integration": "vitest run --config vitest.integration.config.ts --passWithNoTests",
51
+ "coverage": "vitest run --coverage --passWithNoTests",
51
52
  "lint": "eslint . --max-warnings 0",
52
53
  "lint:fix": "eslint . --fix",
53
- "clean": "rimraf dist",
54
- "build": "tsup",
55
- "build:watch": "tsup --watch"
54
+ "prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
55
+ "clean": "rimraf dist"
56
56
  }
57
57
  }
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- /dist
2
- /out
3
- node_modules
package/.eslintrc.cjs DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ["custom"],
4
- };
@@ -1,4 +0,0 @@
1
-
2
- > @autometa/http@1.4.15 lint:fix /Users/ben.aherne/Documents/GitHub/autometa/packages/http
3
- > eslint . --fix "--max-warnings=0"
4
-
@@ -1,5 +0,0 @@
1
-
2
- > @autometa/http@1.4.13 prettify /Users/ben.aherne/Documents/GitHub/autometa/packages/http
3
- > prettier --config .prettierrc 'src/**/*.ts' --write
4
-
5
-  ELIFECYCLE  Command failed.
@@ -1,120 +0,0 @@
1
-
2
- > @autometa/http@1.4.17 test /Users/ben.aherne/Documents/GitHub/autometa/packages/http
3
- > vitest run --passWithNoTests
4
-
5
-
6
- RUN v1.4.0 /Users/ben.aherne/Documents/GitHub/autometa/packages/http
7
-
8
- ✓ src/schema.map.spec.ts (5 tests) 3ms
9
- ✓ src/default-client-factory.other.spec.ts (1 test) 2ms
10
- ✓ src/request-meta.config.spec.ts (8 tests) 5ms
11
- ✓ src/http-request.spec.ts (11 tests) 4ms
12
- ✓ src/default-schema.spec.ts (13 tests) 4ms
13
- ✓ src/default-client-factory.axios.spec.ts (1 test) 2ms
14
- stdout | src/http.spec.ts > HTTP > resolving dynamic headers > should resolve dynamic headers
15
- HTTPRequest {
16
- headers: { foo: 'bar' },
17
- params: {},
18
- route: [],
19
- baseUrl: undefined,
20
- method: 'GET',
21
- data: undefined
22
- }
23
-
24
- stdout | src/http.spec.ts > HTTP > allowPlainText > should throw an error when allowPlainText is false
25
- HTTPRequest {
26
- headers: {},
27
- params: {},
28
- route: [],
29
- baseUrl: undefined,
30
- method: 'GET',
31
- data: undefined
32
- }
33
-
34
- stdout | src/http.spec.ts > HTTP > allowPlainText > should return the response when allowPlainText is true
35
- HTTPRequest {
36
- headers: {},
37
- params: {},
38
- route: [],
39
- baseUrl: undefined,
40
- method: 'GET',
41
- data: undefined
42
- }
43
-
44
- stdout | src/http.spec.ts > HTTP > hooks > onSend > should call the hook when the request is sent
45
- HTTPRequest {
46
- headers: {},
47
- params: {},
48
- route: [],
49
- baseUrl: undefined,
50
- method: 'GET',
51
- data: undefined
52
- }
53
-
54
- stdout | src/http.spec.ts > HTTP > hooks > onReceive > should call the hook when the response is received
55
- HTTPRequest {
56
- headers: {},
57
- params: {},
58
- route: [],
59
- baseUrl: undefined,
60
- method: 'GET',
61
- data: undefined
62
- }
63
-
64
- stdout | src/http.spec.ts > HTTP > hooks > onReceive > should propagate errors from the hook
65
- HTTPRequest {
66
- headers: {},
67
- params: {},
68
- route: [],
69
- baseUrl: undefined,
70
- method: 'GET',
71
- data: undefined
72
- }
73
-
74
- stdout | src/http.spec.ts > HTTP > schemas > should throw an error if there is no schema and requireSchema is true
75
- HTTPRequest {
76
- headers: {},
77
- params: {},
78
- route: [],
79
- baseUrl: undefined,
80
- method: 'GET',
81
- data: undefined
82
- }
83
-
84
- stdout | src/http.spec.ts > HTTP > schemas > should throw an error if the response status does not match a schema
85
- HTTPRequest {
86
- headers: {},
87
- params: {},
88
- route: [],
89
- baseUrl: undefined,
90
- method: 'GET',
91
- data: undefined
92
- }
93
-
94
- stdout | src/http.spec.ts > HTTP > schemas > should return the response if the status matches a schema
95
- HTTPRequest {
96
- headers: {},
97
- params: {},
98
- route: [],
99
- baseUrl: undefined,
100
- method: 'GET',
101
- data: undefined
102
- }
103
-
104
- stdout | src/http.spec.ts > HTTP > schemas > should return the validated response if the status matches a schema
105
- HTTPRequest {
106
- headers: {},
107
- params: {},
108
- route: [],
109
- baseUrl: undefined,
110
- method: 'GET',
111
- data: undefined
112
- }
113
-
114
- ✓ src/http.spec.ts (13 tests) 35ms
115
-
116
- Test Files 7 passed (7)
117
- Tests 52 passed (52)
118
- Start at 13:56:48
119
- Duration 5.28s (transform 2.17s, setup 169ms, collect 5.60s, tests 55ms, environment 7ms, prepare 4.76s)
120
-
package/CHANGELOG.md DELETED
@@ -1,326 +0,0 @@
1
- # @autometa/http
2
-
3
- ## 1.4.19
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [da669a3]
8
- - @autometa/injection@0.1.4
9
- - @autometa/app@0.4.1
10
- - @autometa/dto-builder@0.13.10
11
-
12
- ## 1.4.18
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies [7440e9f]
17
- - @autometa/app@0.4.0
18
-
19
- ## 1.4.17
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies [1d3f84e]
24
- - @autometa/app@0.3.5
25
-
26
- ## 1.4.16
27
-
28
- ### Patch Changes
29
-
30
- - f60af5c: fix(http): dynamic headers could not be replaced with static headers
31
-
32
- ## 1.4.15
33
-
34
- ### Patch Changes
35
-
36
- - fdc17af: fix: params setter only accept string values
37
-
38
- ## 1.4.14
39
-
40
- ### Patch Changes
41
-
42
- - d759d5c: fix: value.replace is not a function when allowPlainText is false
43
-
44
- ## 1.4.13
45
-
46
- ### Patch Changes
47
-
48
- - Updated dependencies [603d0d0]
49
- - @autometa/dto-builder@0.13.9
50
-
51
- ## 1.4.12
52
-
53
- ### Patch Changes
54
-
55
- - 0a250f4: regression
56
-
57
- ## 1.4.11
58
-
59
- ### Patch Changes
60
-
61
- - b579743: fix(http): options not derived
62
-
63
- ## 1.4.10
64
-
65
- ### Patch Changes
66
-
67
- - dbc0eda: feat(http): allow client options to be created with `sharedOptions`
68
-
69
- ## 1.4.9
70
-
71
- ### Patch Changes
72
-
73
- - 2aee2a4: fix(http): spread and array parameters not passed correctly
74
- - 2aee2a4: fix(http): spread and array parameters not passed correctly
75
- - Updated dependencies [2aee2a4]
76
- - @autometa/injection@0.1.3
77
- - @autometa/dto-builder@0.13.8
78
- - @autometa/app@0.3.4
79
-
80
- ## 1.4.8
81
-
82
- ### Patch Changes
83
-
84
- - 536004e: fix: injection errors and http client hooks
85
-
86
- - The new dependency injection library sometimes returned class prototypes instead of class instances due to inconsistent caching of decorated types.
87
- - HTTP client hooks were not executing when certain builder methods were called.
88
-
89
- - Updated dependencies [536004e]
90
- - Updated dependencies [bac2661]
91
- - @autometa/dto-builder@0.13.7
92
- - @autometa/injection@0.1.2
93
- - @autometa/app@0.3.3
94
-
95
- ## 1.4.7
96
-
97
- ### Patch Changes
98
-
99
- - cccedea: fix(http): dynamic headers not deriving and resolving correctly
100
- - Updated dependencies [cccedea]
101
- - @autometa/dto-builder@0.13.6
102
-
103
- ## 1.4.6
104
-
105
- ### Patch Changes
106
-
107
- - Updated dependencies [db87a56]
108
- - @autometa/dto-builder@0.13.5
109
-
110
- ## 1.4.5
111
-
112
- ### Patch Changes
113
-
114
- - Updated dependencies [ae7e34f]
115
- - @autometa/dto-builder@0.13.4
116
-
117
- ## 1.4.4
118
-
119
- ### Patch Changes
120
-
121
- - Updated dependencies
122
- - @autometa/dto-builder@0.13.3
123
-
124
- ## 1.4.3
125
-
126
- ### Patch Changes
127
-
128
- - Updated dependencies
129
- - @autometa/dto-builder@0.13.2
130
-
131
- ## 1.4.2
132
-
133
- ### Patch Changes
134
-
135
- - Updated dependencies [95512a3]
136
- - @autometa/dto-builder@0.13.1
137
-
138
- ## 1.4.1
139
-
140
- ### Patch Changes
141
-
142
- - 16634f7: fix(HTTP): dynamic headers not passable nor resolving
143
-
144
- ## 1.4.0
145
-
146
- ### Minor Changes
147
-
148
- - 7e9d2bc: feat: Table Documents
149
-
150
- Introduces a new way of handling tables which are horizontal (HTable) or vertical (VTable) which maps
151
- the headers of a table to an object properties, defined using a class.
152
-
153
- [docs](https://bendat.github.io/autometa/docs/cucumber/test_runner/datatables#table-documents)
154
-
155
- ### Patch Changes
156
-
157
- - Updated dependencies [7e9d2bc]
158
- - @autometa/dto-builder@0.13.0
159
-
160
- ## 1.3.0
161
-
162
- ### Minor Changes
163
-
164
- - 82168a2: fix: `onRecievedResponse` hook not running when response failed schema validation
165
-
166
- - Renamed hooks to `onSend` and `onRecieve`
167
- - Rewrote HTTP fixture logic to be constructable and derivable.
168
- - `new HTTP().sharedRoute('v1')` constructs a single instance of HTTP with route `v1`
169
- - `new HTTP().sharedRoute('v1').route('user') derives a new HTTP fixture which inherits 'v1' and adds 'user' locally.
170
- - Support for list based params with `paramList` and `sharedParamList`
171
- - Added default schemas for use with simple response types like null, boolean, number etc
172
-
173
- ### Patch Changes
174
-
175
- - Updated dependencies [d563916]
176
- - @autometa/dto-builder@0.12.0
177
- - @autometa/injection@0.1.1
178
- - @autometa/app@0.3.2
179
-
180
- ## 1.2.1
181
-
182
- ### Patch Changes
183
-
184
- - Updated dependencies [6c4bb8d]
185
- - @autometa/app@0.3.1
186
-
187
- ## 1.2.0
188
-
189
- ### Minor Changes
190
-
191
- - 98d911f: feat: replace tsyringe with custom DI solution
192
-
193
- ### Patch Changes
194
-
195
- - Updated dependencies [98d911f]
196
- - @autometa/injection@0.1.0
197
- - @autometa/app@0.3.0
198
-
199
- ## 1.1.0
200
-
201
- ### Minor Changes
202
-
203
- - 4bbe6fc: feat: support factory function for shared headers
204
-
205
- ## 1.0.14
206
-
207
- ### Patch Changes
208
-
209
- - Updated dependencies [3fe2ad4]
210
- - @autometa/errors@0.2.2
211
- - @autometa/app@0.2.4
212
-
213
- ## 1.0.13
214
-
215
- ### Patch Changes
216
-
217
- - Updated dependencies [3493bb6]
218
- - @autometa/errors@0.2.1
219
- - @autometa/app@0.2.3
220
-
221
- ## 1.0.12
222
-
223
- ### Patch Changes
224
-
225
- - Updated dependencies [8ec0cdc]
226
- - @autometa/app@0.2.2
227
-
228
- ## 1.0.11
229
-
230
- ### Patch Changes
231
-
232
- - @autometa/app@0.2.1
233
-
234
- ## 1.0.10
235
-
236
- ### Patch Changes
237
-
238
- - Updated dependencies [b5ce008]
239
- - Updated dependencies [8f116d9]
240
- - @autometa/errors@0.2.0
241
- - @autometa/app@0.2.0
242
-
243
- ## 1.0.9
244
-
245
- ### Patch Changes
246
-
247
- - a7b715a: fix: return empty string bodies without allowPlainText
248
-
249
- ## 1.0.8
250
-
251
- ### Patch Changes
252
-
253
- - 3390c77: fix: RequestState uses objects instead of maps
254
-
255
- ## 1.0.7
256
-
257
- ### Patch Changes
258
-
259
- - b992a2b: fix: HTTPResponse should be exported
260
-
261
- ## 1.0.6
262
-
263
- ### Patch Changes
264
-
265
- - 469f0cb: refactor: http client refactor
266
-
267
- ## 1.0.5
268
-
269
- ### Patch Changes
270
-
271
- - 3a8b32f: fix: improper handling of strings when parsing
272
-
273
- ## 1.0.4
274
-
275
- ### Patch Changes
276
-
277
- - 79a672d: fix: JSON.parse responses
278
-
279
- ## 1.0.3
280
-
281
- ### Patch Changes
282
-
283
- - ef91448: fix: http client return undefined
284
-
285
- ## 1.0.2
286
-
287
- ### Patch Changes
288
-
289
- - 9870641: fix: allow empty plaintext response without flagging it
290
-
291
- ## 1.0.1
292
-
293
- ### Patch Changes
294
-
295
- - e9a8dc8: fix: parsing numbers from raw response string
296
-
297
- ## 1.0.0
298
-
299
- ### Major Changes
300
-
301
- - c7b973f: fix: onRecieve hooks not executing if schema validation fails
302
-
303
- ## 0.1.2
304
-
305
- ### Patch Changes
306
-
307
- - 815b324: Fix: incorrectly imported cli-highlight package
308
-
309
- ## 0.1.1
310
-
311
- ### Patch Changes
312
-
313
- - 2ec3670: fix: http client accepts any input and converts it to a string
314
-
315
- ## 0.1.0
316
-
317
- ### Minor Changes
318
-
319
- - 04ed85d: feat: added HTP client based on axios
320
-
321
- ### Patch Changes
322
-
323
- - Updated dependencies [04ed85d]
324
- - @autometa/status-codes@0.4.1
325
- - @autometa/errors@0.1.4
326
- - @autometa/app@0.1.13