@rest-vir/define-service 1.3.3 → 1.4.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type RequiredKeysOf, type SelectFrom } from '@augment-vir/common';
|
|
2
|
+
import { type BaseSearchParams } from '@rest-vir/define-service';
|
|
2
3
|
import { type ConstructPathParams } from '../endpoint/endpoint-path.js';
|
|
3
4
|
import { type NoParam } from '../util/no-param.js';
|
|
4
5
|
import { type CommonWebSocket } from '../web-socket/common-web-socket.js';
|
|
@@ -55,9 +56,9 @@ export type ConnectWebSocketParams<WebSocketToConnect extends Readonly<SelectFro
|
|
|
55
56
|
} : {
|
|
56
57
|
protocols: WebSocketToConnect['ProtocolsType'];
|
|
57
58
|
}) & (WebSocketToConnect['searchParamsShape'] extends undefined ? {
|
|
58
|
-
searchParams?:
|
|
59
|
+
searchParams?: BaseSearchParams | undefined;
|
|
59
60
|
} : {
|
|
60
|
-
searchParams: WebSocketToConnect['SearchParamsType'] &
|
|
61
|
+
searchParams: WebSocketToConnect['SearchParamsType'] & BaseSearchParams;
|
|
61
62
|
});
|
|
62
63
|
/**
|
|
63
64
|
* Collapsed version of {@link ConnectWebSocketParams} for {@link connectWebSocket} that only
|
|
@@ -18,6 +18,8 @@ export type GenericFetchEndpointParams = PartialWithUndefined<GenericPathParams>
|
|
|
18
18
|
bypassResponseValidation?: undefined | boolean;
|
|
19
19
|
method?: HttpMethod | undefined;
|
|
20
20
|
options?: Omit<RequestInit, 'body' | 'method'> | undefined;
|
|
21
|
+
/** If `true`, Skip automatic request data `'Content-Type'` header assignment. */
|
|
22
|
+
skipAutomaticContentType?: boolean | undefined;
|
|
21
23
|
/**
|
|
22
24
|
* A custom fetch implementation. Useful for debugging or unit testing. This can safely be
|
|
23
25
|
* omitted to use the default JavaScript built-in global `fetch` function.
|
|
@@ -32,6 +34,15 @@ export type GenericFetchEndpointParams = PartialWithUndefined<GenericPathParams>
|
|
|
32
34
|
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
33
35
|
*/
|
|
34
36
|
export type FetchMethod<EndpointToFetch extends Pick<EndpointDefinition, 'methods'>> = IsEqual<KeyCount<Record<ExtractKeysWithMatchingValues<EndpointToFetch['methods'], true>, boolean>>, 1> extends true ? never : Extract<HttpMethod, ExtractKeysWithMatchingValues<EndpointToFetch['methods'], true>> | `${Extract<HttpMethod, ExtractKeysWithMatchingValues<EndpointToFetch['methods'], true>>}`;
|
|
37
|
+
/**
|
|
38
|
+
* Properties from {@link GenericFetchEndpointParams} that are also used in
|
|
39
|
+
* {@link FetchEndpointParams}.
|
|
40
|
+
*
|
|
41
|
+
* @category Internal
|
|
42
|
+
* @category Package : @rest-vir/define-service
|
|
43
|
+
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
44
|
+
*/
|
|
45
|
+
export type GenericFetchEndpointKeysAllowedInSpecificParams = 'options' | 'bypassResponseValidation' | 'skipAutomaticContentType';
|
|
35
46
|
/**
|
|
36
47
|
* All type safe parameters for sending a request to an endpoint using {@link fetchEndpoint}.
|
|
37
48
|
*
|
|
@@ -45,9 +56,9 @@ export type FetchEndpointParams<EndpointToFetch extends SelectFrom<EndpointDefin
|
|
|
45
56
|
responseDataShape: true;
|
|
46
57
|
methods: true;
|
|
47
58
|
}>, AllowFetchMock extends boolean = true> = EndpointToFetch extends EndpointDefinition ? Readonly<ConstructPathParams<EndpointToFetch['path']> & (EndpointToFetch['SearchParamsType'] extends undefined ? {
|
|
48
|
-
searchParams?:
|
|
59
|
+
searchParams?: BaseSearchParams | undefined;
|
|
49
60
|
} : {
|
|
50
|
-
searchParams: EndpointToFetch['SearchParamsType'] &
|
|
61
|
+
searchParams: EndpointToFetch['SearchParamsType'] & BaseSearchParams;
|
|
51
62
|
}) & (EndpointExecutorData<EndpointToFetch>['request'] extends undefined ? {
|
|
52
63
|
/**
|
|
53
64
|
* This endpoint does not accept any request data, so there is none to be
|
|
@@ -64,7 +75,7 @@ export type FetchEndpointParams<EndpointToFetch extends SelectFrom<EndpointDefin
|
|
|
64
75
|
method?: never;
|
|
65
76
|
} : {
|
|
66
77
|
method: FetchMethod<EndpointToFetch>;
|
|
67
|
-
}) & (AllowFetchMock extends true ? Pick<GenericFetchEndpointParams, '
|
|
78
|
+
}) & (AllowFetchMock extends true ? Pick<GenericFetchEndpointParams, 'fetch' | GenericFetchEndpointKeysAllowedInSpecificParams> : Pick<GenericFetchEndpointParams, GenericFetchEndpointKeysAllowedInSpecificParams>)> : GenericFetchEndpointParams;
|
|
68
79
|
/**
|
|
69
80
|
* Type safe output from sending a request to an endpoint definition. Used by {@link fetchEndpoint}.
|
|
70
81
|
*
|
|
@@ -172,7 +183,7 @@ export declare function buildEndpointRequestInit<const EndpointToFetch extends R
|
|
|
172
183
|
serviceOrigin: true;
|
|
173
184
|
serviceName: true;
|
|
174
185
|
};
|
|
175
|
-
}>, ...[{ method, options, pathParams, requestData, searchParams, wildcard },]: CollapsedFetchEndpointParams<EndpointToFetch, false>): {
|
|
186
|
+
}>, ...[{ method, options, pathParams, requestData, searchParams, wildcard, skipAutomaticContentType, },]: CollapsedFetchEndpointParams<EndpointToFetch, false>): {
|
|
176
187
|
url: string;
|
|
177
188
|
requestInit: RequestInit;
|
|
178
189
|
};
|
|
@@ -93,7 +93,7 @@ export async function fetchEndpoint(endpoint, ...params) {
|
|
|
93
93
|
* @category Package : @rest-vir/define-service
|
|
94
94
|
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
95
95
|
*/
|
|
96
|
-
export function buildEndpointRequestInit(endpoint, ...[{ method, options = {}, pathParams, requestData, searchParams, wildcard } = {},]) {
|
|
96
|
+
export function buildEndpointRequestInit(endpoint, ...[{ method, options = {}, pathParams, requestData, searchParams, wildcard, skipAutomaticContentType, } = {},]) {
|
|
97
97
|
const headers = mapObject(options.headers instanceof Headers
|
|
98
98
|
? Object.fromEntries(options.headers.entries())
|
|
99
99
|
: check.isArray(options.headers)
|
|
@@ -105,11 +105,11 @@ export function buildEndpointRequestInit(endpoint, ...[{ method, options = {}, p
|
|
|
105
105
|
};
|
|
106
106
|
});
|
|
107
107
|
if (!headers['content-type']) {
|
|
108
|
-
if (requestData instanceof FormData) {
|
|
108
|
+
if (requestData instanceof FormData || skipAutomaticContentType) {
|
|
109
109
|
/**
|
|
110
|
-
* Do not set `content-type` manually when submitting form data because
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* Do not set `content-type` manually when submitting form data because `fetch` will set
|
|
111
|
+
* it automatically _and_ include a boundary in the content type, which is needed for
|
|
112
|
+
* reading the form data properly.
|
|
113
113
|
*/
|
|
114
114
|
}
|
|
115
115
|
else if (requestData) {
|
|
@@ -9,7 +9,7 @@ import { type OriginRequirement } from '../util/origin.js';
|
|
|
9
9
|
* @category Package : @rest-vir/define-service
|
|
10
10
|
* @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
|
|
11
11
|
*/
|
|
12
|
-
export type MinimalService<ServiceName extends string =
|
|
12
|
+
export type MinimalService<ServiceName extends string = any> = {
|
|
13
13
|
serviceName: IsEqual<ServiceName, ''> extends true ? never : ServiceName;
|
|
14
14
|
/**
|
|
15
15
|
* The origin at which the service will be hosted. Fetch requests and WebSocket connections will
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rest-vir/define-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Define an connect to a declarative and type safe REST and WebSocket service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"test:update": "npm test update"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/common": "^31.
|
|
45
|
-
"date-vir": "^8.
|
|
46
|
-
"type-fest": "^5.
|
|
47
|
-
"url-vir": "^2.1.
|
|
43
|
+
"@augment-vir/assert": "^31.55.0",
|
|
44
|
+
"@augment-vir/common": "^31.55.0",
|
|
45
|
+
"date-vir": "^8.1.0",
|
|
46
|
+
"type-fest": "^5.3.1",
|
|
47
|
+
"url-vir": "^2.1.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@augment-vir/test": "^31.
|
|
50
|
+
"@augment-vir/test": "^31.55.0",
|
|
51
51
|
"@web/dev-server-esbuild": "^1.0.4",
|
|
52
52
|
"@web/test-runner": "^0.20.2",
|
|
53
53
|
"@web/test-runner-commands": "^0.9.0",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@web/test-runner-visual-regression": "^0.10.0",
|
|
56
56
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
57
57
|
"markdown-code-example-inserter": "^3.0.3",
|
|
58
|
-
"object-shape-tester": "^6.
|
|
59
|
-
"typedoc": "^0.28.
|
|
58
|
+
"object-shape-tester": "^6.10.1",
|
|
59
|
+
"typedoc": "^0.28.15",
|
|
60
60
|
"ws": "^8.18.3"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|