counterfact 1.4.1 → 1.4.3
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/server/dispatcher.js +2 -0
- package/dist/server/koa-middleware.js +1 -1
- package/dist/server/types.ts +16 -9
- package/package.json +24 -22
|
@@ -112,6 +112,8 @@ export class Dispatcher {
|
|
|
112
112
|
}
|
|
113
113
|
async request({ auth, body, headers = {}, method, path, query, req, }) {
|
|
114
114
|
debug(`request: ${method} ${path}`);
|
|
115
|
+
debug(`headers: ${JSON.stringify(headers)}`);
|
|
116
|
+
debug(`body: ${JSON.stringify(body)}`);
|
|
115
117
|
// If the incoming path includes the base path, remove it
|
|
116
118
|
if (this.openApiDocument?.basePath !== undefined &&
|
|
117
119
|
path.toLowerCase().startsWith(this.openApiDocument.basePath.toLowerCase())) {
|
|
@@ -46,7 +46,7 @@ export function koaMiddleware(dispatcher, config, proxy = koaProxy) {
|
|
|
46
46
|
}
|
|
47
47
|
const response = await dispatcher.request({
|
|
48
48
|
auth,
|
|
49
|
-
body,
|
|
49
|
+
body: method === "HEAD" || method === "GET" ? undefined : body,
|
|
50
50
|
/* @ts-expect-error the value of a header can be an array and we don't have a solution for that yet */
|
|
51
51
|
headers,
|
|
52
52
|
method,
|
package/dist/server/types.ts
CHANGED
|
@@ -22,8 +22,10 @@ type COUNTERFACT_RESPONSE = typeof counterfactResponseObject;
|
|
|
22
22
|
|
|
23
23
|
type MediaType = `${string}/${string}`;
|
|
24
24
|
|
|
25
|
-
type OmitAll<T, K extends
|
|
26
|
-
[P in keyof T as P extends K[number]
|
|
25
|
+
type OmitAll<T, K extends readonly string[]> = {
|
|
26
|
+
[P in keyof T as P extends `${string}${K[number]}${string}`
|
|
27
|
+
? never
|
|
28
|
+
: P]: T[P];
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
type OmitValueWhenNever<Base> = Pick<
|
|
@@ -43,15 +45,18 @@ interface OpenApiResponses {
|
|
|
43
45
|
[key: string]: OpenApiResponse;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
type IfHasKey<
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
type IfHasKey<
|
|
49
|
+
SomeObject,
|
|
50
|
+
Keys extends readonly string[],
|
|
51
|
+
Yes,
|
|
52
|
+
No,
|
|
53
|
+
> = Keys extends [
|
|
54
|
+
infer FirstKey extends string,
|
|
55
|
+
...infer RestKeys extends string[],
|
|
49
56
|
]
|
|
50
|
-
?
|
|
57
|
+
? keyof SomeObject extends `${string}${FirstKey}${string}`
|
|
51
58
|
? Yes
|
|
52
|
-
: RestKeys
|
|
53
|
-
? IfHasKey<SomeObject, RestKeys, Yes, No>
|
|
54
|
-
: No
|
|
59
|
+
: IfHasKey<SomeObject, RestKeys, Yes, No>
|
|
55
60
|
: No;
|
|
56
61
|
|
|
57
62
|
type SchemasOf<T extends { [key: string]: { schema: any } }> = {
|
|
@@ -279,4 +284,6 @@ export type {
|
|
|
279
284
|
ResponseBuilderFactory,
|
|
280
285
|
WideOperationArgument,
|
|
281
286
|
WideResponseBuilder,
|
|
287
|
+
OmitAll,
|
|
288
|
+
IfHasKey,
|
|
282
289
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "counterfact",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "a library for building a fake REST API for testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/app.js",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"test": "yarn node --experimental-vm-modules ./node_modules/jest-cli/bin/jest --testPathIgnorePatterns=black-box",
|
|
32
32
|
"test:black-box": "rimraf dist && rimraf out && yarn build && yarn node --experimental-vm-modules ./node_modules/jest-cli/bin/jest black-box --forceExit --coverage=false",
|
|
33
33
|
"test:mutants": "stryker run stryker.config.json",
|
|
34
|
+
"test:tsd": "tsd --typings ./dist/server/types.ts --files ./test/**/*.test-d.ts",
|
|
34
35
|
"build": "tsc && copyfiles -f \"src/client/**\" dist/client && copyfiles -f \"src/server/types.ts\" dist/server && copyfiles -f \"src/server/*.cjs\" dist/server",
|
|
35
36
|
"prepack": "yarn build",
|
|
36
37
|
"release": "npx changeset publish",
|
|
@@ -44,40 +45,41 @@
|
|
|
44
45
|
"postinstall": "patch-package"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@changesets/cli": "2.29.
|
|
48
|
-
"@stryker-mutator/core": "9.
|
|
49
|
-
"@stryker-mutator/jest-runner": "9.
|
|
50
|
-
"@stryker-mutator/typescript-checker": "9.
|
|
51
|
-
"@swc/core": "1.
|
|
52
|
-
"@swc/jest": "0.2.
|
|
53
|
-
"@testing-library/dom": "10.4.
|
|
48
|
+
"@changesets/cli": "2.29.6",
|
|
49
|
+
"@stryker-mutator/core": "9.1.1",
|
|
50
|
+
"@stryker-mutator/jest-runner": "9.1.1",
|
|
51
|
+
"@stryker-mutator/typescript-checker": "9.1.1",
|
|
52
|
+
"@swc/core": "1.13.5",
|
|
53
|
+
"@swc/jest": "0.2.39",
|
|
54
|
+
"@testing-library/dom": "10.4.1",
|
|
54
55
|
"@types/jest": "30.0.0",
|
|
55
56
|
"@types/js-yaml": "4.0.9",
|
|
56
57
|
"@types/koa": "2.15.0",
|
|
57
58
|
"@types/koa-bodyparser": "4.3.12",
|
|
58
59
|
"@types/koa-proxy": "1.0.7",
|
|
59
60
|
"@types/koa-static": "4.0.4",
|
|
60
|
-
"@types/lodash": "4.17.
|
|
61
|
+
"@types/lodash": "4.17.20",
|
|
61
62
|
"copyfiles": "2.4.1",
|
|
62
63
|
"eslint": "9.28.0",
|
|
63
|
-
"eslint-config-hardcore": "
|
|
64
|
+
"eslint-config-hardcore": "49.0.0",
|
|
64
65
|
"eslint-formatter-github-annotations": "0.1.0",
|
|
65
|
-
"eslint-import-resolver-typescript": "4.4.
|
|
66
|
+
"eslint-import-resolver-typescript": "4.4.4",
|
|
66
67
|
"eslint-plugin-etc": "2.0.3",
|
|
67
68
|
"eslint-plugin-file-progress": "3.0.2",
|
|
68
|
-
"eslint-plugin-import": "2.
|
|
69
|
-
"eslint-plugin-jest": "
|
|
69
|
+
"eslint-plugin-import": "2.32.0",
|
|
70
|
+
"eslint-plugin-jest": "29.0.1",
|
|
70
71
|
"eslint-plugin-jest-dom": "5.5.0",
|
|
71
72
|
"eslint-plugin-no-explicit-type-exports": "0.12.1",
|
|
72
|
-
"eslint-plugin-prettier": "5.4
|
|
73
|
-
"eslint-plugin-unused-imports": "4.
|
|
73
|
+
"eslint-plugin-prettier": "5.5.4",
|
|
74
|
+
"eslint-plugin-unused-imports": "4.2.0",
|
|
74
75
|
"husky": "9.1.7",
|
|
75
|
-
"jest": "30.
|
|
76
|
+
"jest": "30.1.1",
|
|
76
77
|
"jest-retries": "1.0.1",
|
|
77
78
|
"node-mocks-http": "1.17.2",
|
|
78
79
|
"rimraf": "6.0.1",
|
|
79
80
|
"stryker-cli": "1.0.2",
|
|
80
|
-
"supertest": "7.1.
|
|
81
|
+
"supertest": "7.1.4",
|
|
82
|
+
"tsd": "0.33.0",
|
|
81
83
|
"using-temporary-files": "2.2.1"
|
|
82
84
|
},
|
|
83
85
|
"dependencies": {
|
|
@@ -89,24 +91,24 @@
|
|
|
89
91
|
"commander": "14.0.0",
|
|
90
92
|
"debug": "4.4.1",
|
|
91
93
|
"fetch": "1.1.0",
|
|
92
|
-
"fs-extra": "11.3.
|
|
94
|
+
"fs-extra": "11.3.1",
|
|
93
95
|
"handlebars": "4.7.8",
|
|
94
96
|
"http-terminator": "3.2.0",
|
|
95
97
|
"js-yaml": "4.1.0",
|
|
96
98
|
"json-schema-faker": "0.5.9",
|
|
97
99
|
"jsonwebtoken": "9.0.2",
|
|
98
|
-
"koa": "3.0.
|
|
100
|
+
"koa": "3.0.1",
|
|
99
101
|
"koa-bodyparser": "4.4.1",
|
|
100
102
|
"koa-proxies": "0.12.4",
|
|
101
103
|
"koa2-swagger-ui": "5.11.0",
|
|
102
104
|
"lodash": "4.17.21",
|
|
103
105
|
"node-fetch": "3.3.2",
|
|
104
|
-
"open": "10.
|
|
106
|
+
"open": "10.2.0",
|
|
105
107
|
"patch-package": "8.0.0",
|
|
106
108
|
"precinct": "12.2.0",
|
|
107
|
-
"prettier": "3.
|
|
109
|
+
"prettier": "3.6.2",
|
|
108
110
|
"recast": "0.23.11",
|
|
109
|
-
"typescript": "5.
|
|
111
|
+
"typescript": "5.9.2"
|
|
110
112
|
},
|
|
111
113
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
112
114
|
}
|