@hyper-fetch/orpc 0.0.0-stage → 1.0.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/README.md +100 -2
- package/__tests__/e2e/e2e.conformance.spec.ts +187 -0
- package/__tests__/e2e/e2e.orpc-server.ts +163 -0
- package/__tests__/e2e/e2e.orpc.spec.ts +338 -0
- package/__tests__/e2e/e2e.react.spec.tsx +219 -0
- package/__tests__/features/adapter/adapter.fetch.spec.ts +388 -0
- package/__tests__/features/adapter/adapter.lifecycle.spec.ts +529 -0
- package/__tests__/features/adapter/adapter.schema.spec.ts +271 -0
- package/__tests__/features/adapter/adapter.transport.spec.ts +346 -0
- package/__tests__/features/adapter/adapter.utils.spec.ts +329 -0
- package/__tests__/tsconfig.json +16 -0
- package/__tests__/vitest.setup.ts +5 -0
- package/dist/adapter/adapter.constants.d.ts +12 -0
- package/dist/adapter/adapter.constants.d.ts.map +1 -0
- package/dist/adapter/adapter.d.ts +10 -0
- package/dist/adapter/adapter.d.ts.map +1 -0
- package/dist/adapter/adapter.fetch.d.ts +3 -0
- package/dist/adapter/adapter.fetch.d.ts.map +1 -0
- package/dist/adapter/adapter.schema.d.ts +50 -0
- package/dist/adapter/adapter.schema.d.ts.map +1 -0
- package/dist/adapter/adapter.types.d.ts +42 -0
- package/dist/adapter/adapter.types.d.ts.map +1 -0
- package/dist/adapter/adapter.utils.d.ts +52 -0
- package/dist/adapter/adapter.utils.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +7 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +282 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -4
- package/project.json +4 -0
- package/src/adapter/adapter.constants.ts +20 -0
- package/src/adapter/adapter.fetch.ts +227 -0
- package/src/adapter/adapter.schema.ts +73 -0
- package/src/adapter/adapter.ts +13 -0
- package/src/adapter/adapter.types.ts +65 -0
- package/src/adapter/adapter.utils.ts +189 -0
- package/src/adapter/index.ts +6 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +12 -0
- package/vite.config.ts +42 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { RequestModel } from "@hyper-fetch/core";
|
|
2
|
+
import type { Client, NestedClient, ORPCError } from "@orpc/client";
|
|
3
|
+
import type { AnyRouter, RouterClient } from "@orpc/server";
|
|
4
|
+
|
|
5
|
+
import type { OrpcErrorType } from "./adapter.types";
|
|
6
|
+
|
|
7
|
+
type OrpcHasNoInput<Input> = unknown extends Input ? true : [Input] extends [void | undefined] ? true : false;
|
|
8
|
+
|
|
9
|
+
/** Procedures without an input are sent without the payload */
|
|
10
|
+
type OrpcProcedurePayload<Input> = OrpcHasNoInput<Input> extends true ? undefined : Exclude<Input, void | undefined>;
|
|
11
|
+
|
|
12
|
+
/** An optional input doesn't have to be set before sending the request */
|
|
13
|
+
type OrpcProcedureHasPayload<Input> =
|
|
14
|
+
OrpcHasNoInput<Input> extends true ? false : undefined extends Input ? true : false;
|
|
15
|
+
|
|
16
|
+
/** Errors from the `.errors()` map keep their code and data, any other error is not defined by the procedure */
|
|
17
|
+
type OrpcProcedureError<Error> =
|
|
18
|
+
| (Error extends ORPCError<infer Code, infer Data> ? OrpcErrorType<Code, Data> & { defined: true } : never)
|
|
19
|
+
| (OrpcErrorType & { defined: false });
|
|
20
|
+
|
|
21
|
+
type OrpcProcedureModel<Input, Output, Error, Endpoint extends string> = RequestModel<{
|
|
22
|
+
response: Output;
|
|
23
|
+
payload: OrpcProcedurePayload<Input>;
|
|
24
|
+
hasPayload: OrpcProcedureHasPayload<Input>;
|
|
25
|
+
error: OrpcProcedureError<Error>;
|
|
26
|
+
endpoint: Endpoint;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
/** Every procedure can be read with `$query` and changed with `$mutation`, the same as in the oRPC query utils */
|
|
30
|
+
type OrpcProcedureSchema<Input, Output, Error, Endpoint extends string> = {
|
|
31
|
+
$query: OrpcProcedureModel<Input, Output, Error, Endpoint>;
|
|
32
|
+
$mutation: OrpcProcedureModel<Input, Output, Error, Endpoint>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type OrpcAnyClient = Client<any, any, any, any>;
|
|
36
|
+
|
|
37
|
+
/** Event iterators are not supported by the adapter, so they are not a part of the schema. Procedures that only throw stay. */
|
|
38
|
+
type OrpcSupportedKeys<Record> = {
|
|
39
|
+
[Key in keyof Record]: Record[Key] extends Client<any, any, infer Output, any>
|
|
40
|
+
? [Output] extends [never]
|
|
41
|
+
? Key
|
|
42
|
+
: [Output] extends [{ [Symbol.asyncIterator]: unknown }]
|
|
43
|
+
? never
|
|
44
|
+
: Key
|
|
45
|
+
: Key;
|
|
46
|
+
}[keyof Record];
|
|
47
|
+
|
|
48
|
+
type OrpcClientSchema<Record, Path extends string> = {
|
|
49
|
+
[Key in OrpcSupportedKeys<Record> & string]: Record[Key] extends Client<any, infer Input, infer Output, infer Error>
|
|
50
|
+
? OrpcProcedureSchema<Input, Output, Error, `${Path}/${Key}`>
|
|
51
|
+
: Record[Key] extends NestedClient<any>
|
|
52
|
+
? OrpcClientSchema<Record[Key], `${Path}/${Key}`>
|
|
53
|
+
: never;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type OrpcRouterClient<Router> = Router extends OrpcAnyClient
|
|
57
|
+
? never
|
|
58
|
+
: Router extends NestedClient<any>
|
|
59
|
+
? Router
|
|
60
|
+
: Router extends AnyRouter
|
|
61
|
+
? RouterClient<Router>
|
|
62
|
+
: never;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Maps the type of an oRPC router to the schema understood by `createSdk`.
|
|
66
|
+
* It takes the router, or the client type, like `ContractRouterClient<typeof contract>` for contract-first APIs.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const api = createSdk<typeof client, OrpcSchema<typeof router>>(client, { camelCaseToKebabCase: false });
|
|
70
|
+
*
|
|
71
|
+
* const { data } = await api.planet.find.$query.setPayload({ id: 1 }).send();
|
|
72
|
+
*/
|
|
73
|
+
export type OrpcSchema<Router extends AnyRouter | NestedClient<any>> = OrpcClientSchema<OrpcRouterClient<Router>, "">;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getOrpcAdapter } from "./adapter.fetch";
|
|
2
|
+
import type { OrpcAdapterOptionsType, OrpcAdapterType } from "./adapter.types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Adapter calling oRPC procedures with the RPC protocol.
|
|
6
|
+
* The endpoint is the procedure path and the payload is the procedure input.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const client = createClient({ url: "http://localhost:3000/rpc" }).setAdapter(OrpcAdapter());
|
|
10
|
+
*/
|
|
11
|
+
export const OrpcAdapter = (options?: OrpcAdapterOptionsType): OrpcAdapterType => {
|
|
12
|
+
return getOrpcAdapter(options);
|
|
13
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Adapter,
|
|
3
|
+
DefaultMapperType,
|
|
4
|
+
QueryParamsType,
|
|
5
|
+
RequestInstance,
|
|
6
|
+
stringifyQueryParams,
|
|
7
|
+
} from "@hyper-fetch/core";
|
|
8
|
+
import type { StandardRPCCustomJsonSerializer } from "@orpc/client/standard";
|
|
9
|
+
|
|
10
|
+
import type { OrpcMethods } from "./adapter.constants";
|
|
11
|
+
|
|
12
|
+
export type OrpcMethod = (typeof OrpcMethods)[keyof typeof OrpcMethods];
|
|
13
|
+
|
|
14
|
+
export type OrpcExtraType = { headers: Record<string, string> };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* HTTP method used for the `QUERY` requests.
|
|
18
|
+
* The oRPC `RPCHandler` accepts only `POST` until `GET` is added to its `allowMethods`.
|
|
19
|
+
*/
|
|
20
|
+
export type OrpcQueryMethod = "POST" | "GET";
|
|
21
|
+
|
|
22
|
+
export type OrpcAdapterOptionsType = {
|
|
23
|
+
/**
|
|
24
|
+
* HTTP method of the `QUERY` requests, mutations always use `POST`.
|
|
25
|
+
* @default "POST"
|
|
26
|
+
*/
|
|
27
|
+
queryMethod?: OrpcQueryMethod;
|
|
28
|
+
/**
|
|
29
|
+
* Serializers of custom types, the same as the `customJsonSerializers` option of `RPCHandler` and `RPCLink`.
|
|
30
|
+
* Both sides need the same list.
|
|
31
|
+
*/
|
|
32
|
+
customJsonSerializers?: StandardRPCCustomJsonSerializer[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type FetchOrpcAdapterOptionsType = Omit<RequestInit, "method" | "headers" | "body" | "signal"> & {
|
|
36
|
+
timeout?: number;
|
|
37
|
+
/** Overrides the `queryMethod` of the adapter for one request */
|
|
38
|
+
queryMethod?: OrpcQueryMethod;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Error sent by an oRPC procedure, the JSON form of `ORPCError`.
|
|
43
|
+
* Errors from the `.errors()` map of the procedure have `defined: true`.
|
|
44
|
+
*/
|
|
45
|
+
export type OrpcErrorType<Code extends string = string, Data = unknown> = {
|
|
46
|
+
defined: boolean;
|
|
47
|
+
code: Code;
|
|
48
|
+
status: number;
|
|
49
|
+
message: string;
|
|
50
|
+
data: Data;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type OrpcAdapterType = Adapter<
|
|
54
|
+
FetchOrpcAdapterOptionsType,
|
|
55
|
+
OrpcMethod,
|
|
56
|
+
number,
|
|
57
|
+
OrpcExtraType,
|
|
58
|
+
QueryParamsType | string,
|
|
59
|
+
QueryParamsType | string | undefined,
|
|
60
|
+
string,
|
|
61
|
+
(endpoint: string) => string,
|
|
62
|
+
typeof stringifyQueryParams,
|
|
63
|
+
(request: RequestInstance) => HeadersInit,
|
|
64
|
+
DefaultMapperType
|
|
65
|
+
>;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { EmptyTypes, QueryParamsType, RequestInstance } from "@hyper-fetch/core";
|
|
2
|
+
import { getErrorMessage, parseResponse, stringifyKey, stringifyQueryParams } from "@hyper-fetch/core";
|
|
3
|
+
import type { StandardRPCCustomJsonSerializer } from "@orpc/client/standard";
|
|
4
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from "@orpc/client/standard";
|
|
5
|
+
|
|
6
|
+
import { maxGetUrlLength, OrpcMethods, reservedQueryParams } from "./adapter.constants";
|
|
7
|
+
import type { OrpcErrorType, OrpcQueryMethod } from "./adapter.types";
|
|
8
|
+
|
|
9
|
+
/** Serializer of the oRPC RPC protocol, it handles types like `Date`, `BigInt`, `Map`, `Set` and files */
|
|
10
|
+
export const createOrpcSerializer = (customJsonSerializers?: StandardRPCCustomJsonSerializer[]) => {
|
|
11
|
+
return new StandardRPCSerializer(new StandardRPCJsonSerializer({ customJsonSerializers }));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type OrpcSerializerType = ReturnType<typeof createOrpcSerializer>;
|
|
15
|
+
|
|
16
|
+
/** Turns the procedure path `user/byId` or `/user/byId` into the url path `/user/byId` */
|
|
17
|
+
export const orpcEndpointMapper = (endpoint: string): string => {
|
|
18
|
+
const segments = endpoint.split("/").filter(Boolean);
|
|
19
|
+
|
|
20
|
+
return `/${segments.map(encodeURIComponent).join("/")}`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Keys are built from the wire format, so values like `Date` or `Map` stay distinct.
|
|
25
|
+
* Mappers run while the request is created, so an input that can't be serialized can't throw here.
|
|
26
|
+
* It is reported when the request is sent.
|
|
27
|
+
*/
|
|
28
|
+
const getOrpcInputKey = (input: unknown, serializer: OrpcSerializerType): string => {
|
|
29
|
+
try {
|
|
30
|
+
const serialized = serializer.serialize(input);
|
|
31
|
+
|
|
32
|
+
if (!(serialized instanceof FormData)) {
|
|
33
|
+
return JSON.stringify(serialized);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Files are compared by their metadata, reading their content would be too expensive
|
|
37
|
+
const parts: string[] = [];
|
|
38
|
+
serialized.forEach((value, key) => {
|
|
39
|
+
parts.push(typeof value === "string" ? value : `${key}:${value.name}:${value.type}:${value.size}`);
|
|
40
|
+
});
|
|
41
|
+
return parts.join("|");
|
|
42
|
+
} catch {
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Key of the request response - the same procedure called with a different input is a different resource */
|
|
48
|
+
export const getOrpcRequestKey = (request: RequestInstance, serializer: OrpcSerializerType): string => {
|
|
49
|
+
const procedure = orpcEndpointMapper(request.endpoint);
|
|
50
|
+
const input = getOrpcInputKey(request.payload, serializer);
|
|
51
|
+
|
|
52
|
+
return `${request.method}_${procedure}-${input}-${stringifyKey(request.queryParams)}`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The input is not a part of this key, so `request.abort()` stops every running call of the procedure */
|
|
56
|
+
export const getOrpcAbortKey = (request: RequestInstance): string => {
|
|
57
|
+
return `${request.method}_${orpcEndpointMapper(request.endpoint)}-${request.cancelable}`;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Only the user headers, the content type depends on the encoded body and is set while sending */
|
|
61
|
+
export const getOrpcHeaders = (request: RequestInstance): HeadersInit => {
|
|
62
|
+
return { ...(request.headers as Record<string, string> | undefined) };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type OrpcHttpRequestType = {
|
|
66
|
+
url: string;
|
|
67
|
+
method: "GET" | "POST";
|
|
68
|
+
headers: Record<string, string>;
|
|
69
|
+
body?: string | FormData;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Encodes the call as described by the oRPC RPC protocol.
|
|
74
|
+
* GET sends the input in the `data` query param. Files and urls over the length limit fall back to POST,
|
|
75
|
+
* the same as the `RPCLink` of oRPC.
|
|
76
|
+
*/
|
|
77
|
+
export const getOrpcHttpRequest = ({
|
|
78
|
+
request,
|
|
79
|
+
endpoint,
|
|
80
|
+
queryParams,
|
|
81
|
+
headers,
|
|
82
|
+
payload,
|
|
83
|
+
queryMethod,
|
|
84
|
+
serializer,
|
|
85
|
+
}: {
|
|
86
|
+
request: RequestInstance;
|
|
87
|
+
endpoint: string;
|
|
88
|
+
queryParams: unknown;
|
|
89
|
+
headers: HeadersInit;
|
|
90
|
+
payload: unknown;
|
|
91
|
+
queryMethod: OrpcQueryMethod;
|
|
92
|
+
serializer: OrpcSerializerType;
|
|
93
|
+
}): OrpcHttpRequestType => {
|
|
94
|
+
const [baseUrl, baseQuery] = request.client.url.split("?");
|
|
95
|
+
const searchParams = new URLSearchParams(baseQuery);
|
|
96
|
+
|
|
97
|
+
// Mappers can return anything, so we normalize their result to the query string
|
|
98
|
+
new URLSearchParams(stringifyQueryParams(queryParams as QueryParamsType | string | EmptyTypes)).forEach(
|
|
99
|
+
(value, key) => {
|
|
100
|
+
if (!reservedQueryParams.includes(key)) {
|
|
101
|
+
searchParams.append(key, value);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const url = `${baseUrl.replace(/\/+$/, "")}${endpoint}`;
|
|
107
|
+
const serialized = serializer.serialize(payload);
|
|
108
|
+
const userHeaders = { ...(headers as Record<string, string>) };
|
|
109
|
+
|
|
110
|
+
if (request.method === OrpcMethods.QUERY && queryMethod === "GET" && !(serialized instanceof FormData)) {
|
|
111
|
+
const getParams = new URLSearchParams(searchParams);
|
|
112
|
+
getParams.append("data", JSON.stringify(serialized));
|
|
113
|
+
const getUrl = `${url}?${getParams.toString()}`;
|
|
114
|
+
|
|
115
|
+
if (getUrl.length <= maxGetUrlLength) {
|
|
116
|
+
return { url: getUrl, method: "GET", headers: userHeaders };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const queryString = searchParams.toString();
|
|
121
|
+
const postUrl = queryString ? `${url}?${queryString}` : url;
|
|
122
|
+
|
|
123
|
+
if (serialized instanceof FormData) {
|
|
124
|
+
// The browser sets the multipart content type together with its boundary
|
|
125
|
+
return { url: postUrl, method: "POST", headers: userHeaders, body: serialized };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
url: postUrl,
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers: { "Content-Type": "application/json", ...userHeaders },
|
|
132
|
+
body: JSON.stringify(serialized),
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const isRecord = (value: unknown): value is Record<string, unknown> => {
|
|
137
|
+
return typeof value === "object" && value !== null;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** The same check as `isORPCErrorJson` of oRPC */
|
|
141
|
+
const isOrpcError = (value: unknown): value is OrpcErrorType => {
|
|
142
|
+
return (
|
|
143
|
+
isRecord(value) &&
|
|
144
|
+
typeof value.defined === "boolean" &&
|
|
145
|
+
typeof value.code === "string" &&
|
|
146
|
+
typeof value.status === "number" &&
|
|
147
|
+
typeof value.message === "string"
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
type OrpcResultType = { isSuccess: true; data: unknown } | { isSuccess: false; error: unknown };
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Reads the serialized `{ json, meta }` body, or the multipart body when the output contains files.
|
|
155
|
+
* Statuses from 400 up are errors, the same as in oRPC.
|
|
156
|
+
*/
|
|
157
|
+
export const getOrpcResult = ({
|
|
158
|
+
body,
|
|
159
|
+
status,
|
|
160
|
+
serializer,
|
|
161
|
+
}: {
|
|
162
|
+
body: string | FormData;
|
|
163
|
+
status: number;
|
|
164
|
+
serializer: OrpcSerializerType;
|
|
165
|
+
}): OrpcResultType => {
|
|
166
|
+
// An empty body is an undefined output
|
|
167
|
+
let parsed: unknown = body || undefined;
|
|
168
|
+
if (typeof parsed === "string") {
|
|
169
|
+
parsed = parseResponse(parsed);
|
|
170
|
+
}
|
|
171
|
+
const isSerialized = parsed === undefined || parsed instanceof FormData || isRecord(parsed);
|
|
172
|
+
|
|
173
|
+
if (!isSerialized) {
|
|
174
|
+
return { isSuccess: false, error: getErrorMessage() };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const value = serializer.deserialize(parsed);
|
|
178
|
+
if (status < 400) {
|
|
179
|
+
return { isSuccess: true, data: value ?? null };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!isOrpcError(value)) {
|
|
183
|
+
return { isSuccess: false, error: getErrorMessage() };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// The same fields as `ORPCError.toJSON()`, the data key is there even when the error has no data
|
|
187
|
+
const { defined, code, status: errorStatus, message, data } = value;
|
|
188
|
+
return { isSuccess: false, error: { defined, code, status: errorStatus, message, data } };
|
|
189
|
+
};
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"types": ["node"],
|
|
6
|
+
"paths": {
|
|
7
|
+
"adapter": ["./src/adapter"],
|
|
8
|
+
"adapter/*": ["./src/adapter/*"]
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"exclude": ["node_modules", "dist", "vite.config.ts", "__tests__"]
|
|
12
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="vitest/config" />
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import dts from "vite-plugin-dts";
|
|
5
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
6
|
+
|
|
7
|
+
import { getRollupExternalsFromPackageJson } from "../../scripts/vite-lib-externals-from-package";
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
build: {
|
|
11
|
+
lib: {
|
|
12
|
+
entry: "src/index.ts",
|
|
13
|
+
fileName: "index",
|
|
14
|
+
formats: ["es"],
|
|
15
|
+
},
|
|
16
|
+
minify: false,
|
|
17
|
+
rollupOptions: {
|
|
18
|
+
// Subpath imports are matched exactly
|
|
19
|
+
external: [...getRollupExternalsFromPackageJson(__dirname), "@orpc/client/standard"],
|
|
20
|
+
},
|
|
21
|
+
sourcemap: true,
|
|
22
|
+
},
|
|
23
|
+
plugins: [tsconfigPaths(), dts({ entryRoot: "src" })],
|
|
24
|
+
test: {
|
|
25
|
+
alias: {
|
|
26
|
+
"@hyper-fetch/core": path.resolve(__dirname, "../core/src/index.ts"),
|
|
27
|
+
"@hyper-fetch/react": path.resolve(__dirname, "../react/src/index.ts"),
|
|
28
|
+
"@hyper-fetch/sockets": path.resolve(__dirname, "../sockets/src/index.ts"),
|
|
29
|
+
"@hyper-fetch/testing": path.resolve(__dirname, "../testing/src/index.ts"),
|
|
30
|
+
},
|
|
31
|
+
coverage: {
|
|
32
|
+
exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
|
|
33
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
34
|
+
provider: "v8",
|
|
35
|
+
thresholds: { 100: true },
|
|
36
|
+
},
|
|
37
|
+
environment: "node",
|
|
38
|
+
globals: true,
|
|
39
|
+
include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
|
|
40
|
+
setupFiles: ["./__tests__/vitest.setup.ts"],
|
|
41
|
+
},
|
|
42
|
+
});
|