@rest-vir/define-service 1.3.4 → 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.
@@ -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
  *
@@ -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, 'options' | 'fetch' | 'bypassResponseValidation'> : Pick<GenericFetchEndpointParams, 'options' | 'bypassResponseValidation'>)> : 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 the browser will
111
- * set it automatically _and_ include a boundary in the content type, which is needed
112
- * for reading the form data properly.
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 = 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.4",
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.51.1",
44
- "@augment-vir/common": "^31.51.1",
45
- "date-vir": "^8.0.0",
46
- "type-fest": "^5.2.0",
47
- "url-vir": "^2.1.6"
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.51.1",
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.9.3",
59
- "typedoc": "^0.28.14",
58
+ "object-shape-tester": "^6.10.1",
59
+ "typedoc": "^0.28.15",
60
60
  "ws": "^8.18.3"
61
61
  },
62
62
  "peerDependencies": {