@hyper-fetch/core 7.5.2 → 8.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/.eslintrc.cjs +12 -0
- package/__tests__/e2e/e2e.abort-timeout.spec.ts +101 -0
- package/__tests__/e2e/e2e.advanced.spec.ts +423 -0
- package/__tests__/e2e/e2e.methods.spec.ts +243 -0
- package/__tests__/e2e/e2e.payloads.spec.ts +154 -0
- package/__tests__/features/adapter/adapter.base.spec.ts +414 -0
- package/__tests__/features/adapter/adapter.bindings.spec.ts +1025 -0
- package/__tests__/features/adapter/adapter.browser.spec.ts +88 -0
- package/__tests__/features/adapter/adapter.server.spec.ts +369 -0
- package/__tests__/features/adapter/adapter.utils.spec.ts +165 -0
- package/__tests__/features/cache/cache.base.spec.ts +366 -0
- package/__tests__/features/cache/cache.events.spec.ts +219 -0
- package/__tests__/features/cache/cache.garbage-collector.spec.ts +175 -0
- package/__tests__/features/cache/cache.lazy-storage.spec.ts +132 -0
- package/__tests__/features/cache/cache.modes.spec.ts +145 -0
- package/__tests__/features/cache/cache.scoping.spec.ts +171 -0
- package/__tests__/features/cache/cache.typescript.spec.ts +147 -0
- package/__tests__/features/cache/cache.utils.spec.ts +126 -0
- package/__tests__/features/client/client.auth.spec.ts +125 -0
- package/__tests__/features/client/client.base.spec.ts +161 -0
- package/__tests__/features/client/client.from-json.spec.ts +182 -0
- package/__tests__/features/client/client.hydration.spec.ts +236 -0
- package/__tests__/features/client/client.interceptor.spec.ts +225 -0
- package/__tests__/features/client/client.methods.spec.ts +189 -0
- package/__tests__/features/client/client.middleware.spec.ts +118 -0
- package/__tests__/features/client/client.utils.spec.ts +292 -0
- package/__tests__/features/dispatcher/dispatcher.base.spec.ts +123 -0
- package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +189 -0
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +309 -0
- package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +462 -0
- package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +241 -0
- package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +142 -0
- package/__tests__/features/managers/app/app.manager.base.spec.ts +235 -0
- package/__tests__/features/managers/app/app.manager.ssr.spec.ts +43 -0
- package/__tests__/features/managers/logger/logger.base.spec.ts +109 -0
- package/__tests__/features/managers/logger/logger.utils.spec.ts +106 -0
- package/__tests__/features/managers/request/request.manager.base.spec.ts +224 -0
- package/__tests__/features/managers/request/request.manager.events.spec.ts +364 -0
- package/__tests__/features/mocker/mocker.base.spec.ts +639 -0
- package/__tests__/features/plugin/plugin.base.spec.ts +255 -0
- package/__tests__/features/request/request.base.spec.ts +225 -0
- package/__tests__/features/request/request.cloning.spec.ts +47 -0
- package/__tests__/features/request/request.hooks.spec.ts +173 -0
- package/__tests__/features/request/request.optimistic.spec.ts +93 -0
- package/__tests__/features/request/request.retry-on-error.spec.ts +359 -0
- package/__tests__/features/request/request.sending.spec.ts +364 -0
- package/__tests__/features/request/request.setters.spec.ts +164 -0
- package/__tests__/features/request/request.typescript.spec.ts +423 -0
- package/__tests__/features/request/request.utils.spec.ts +77 -0
- package/__tests__/features/sdk/sdk.base.spec.ts +132 -0
- package/__tests__/features/sdk/sdk.configuration.spec.ts +262 -0
- package/__tests__/features/utils/emitter.utils.spec.ts +88 -0
- package/__tests__/shared/callbacks.shared.ts +11 -0
- package/__tests__/shared/index.ts +2 -0
- package/__tests__/shared/progress.shared.ts +36 -0
- package/__tests__/tsconfig.json +24 -0
- package/__tests__/type-stress/generate-stress-test.ts +92 -0
- package/__tests__/type-stress/stress-10.ts +35 -0
- package/__tests__/type-stress/stress-just-create.ts +2107 -0
- package/__tests__/type-stress/stress-minimal.ts +23 -0
- package/__tests__/type-stress/stress-test-500.ts +2319 -0
- package/__tests__/type-stress/stress-test-sdk.ts +210 -0
- package/__tests__/type-stress/tsconfig.json +6 -0
- package/__tests__/utils/adapter.utils.ts +39 -0
- package/__tests__/utils/cache.utils.ts +20 -0
- package/__tests__/utils/callbacks.utils.ts +48 -0
- package/__tests__/utils/dispatcher.utils.ts +7 -0
- package/__tests__/utils/index.ts +4 -0
- package/__tests__/vitest.setup.ts +15 -0
- package/dist/adapter/adapter.bindings.d.ts +71 -0
- package/dist/adapter/adapter.bindings.d.ts.map +1 -0
- package/dist/adapter/adapter.d.ts +127 -0
- package/dist/adapter/adapter.d.ts.map +1 -0
- package/dist/adapter/adapter.types.d.ts +108 -0
- package/dist/adapter/adapter.types.d.ts.map +1 -0
- package/dist/adapter/adapter.utils.d.ts +23 -0
- package/dist/adapter/adapter.utils.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +5 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/cache/cache.d.ts +95 -0
- package/dist/cache/cache.d.ts.map +1 -0
- package/dist/cache/cache.events.d.ts +51 -0
- package/dist/cache/cache.events.d.ts.map +1 -0
- package/dist/cache/cache.types.d.ts +44 -0
- package/dist/cache/cache.types.d.ts.map +1 -0
- package/dist/cache/cache.utils.d.ts +11 -0
- package/dist/cache/cache.utils.d.ts.map +1 -0
- package/dist/cache/index.d.ts +5 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/client/client.constants.d.ts +10 -0
- package/dist/client/client.constants.d.ts.map +1 -0
- package/dist/client/client.create.d.ts +8 -0
- package/dist/client/client.create.d.ts.map +1 -0
- package/dist/client/client.d.ts +195 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.types.d.ts +71 -0
- package/dist/client/client.types.d.ts.map +1 -0
- package/dist/client/client.utils.d.ts +11 -0
- package/dist/client/client.utils.d.ts.map +1 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/constants/http.constants.d.ts +8 -0
- package/dist/constants/http.constants.d.ts.map +1 -0
- package/dist/constants/time.constants.d.ts +12 -0
- package/dist/constants/time.constants.d.ts.map +1 -0
- package/dist/dispatcher/dispatcher.constants.d.ts +7 -0
- package/dist/dispatcher/dispatcher.constants.d.ts.map +1 -0
- package/dist/dispatcher/dispatcher.d.ts +168 -0
- package/dist/dispatcher/dispatcher.d.ts.map +1 -0
- package/dist/dispatcher/dispatcher.events.d.ts +49 -0
- package/dist/dispatcher/dispatcher.events.d.ts.map +1 -0
- package/dist/dispatcher/dispatcher.types.d.ts +44 -0
- package/dist/dispatcher/dispatcher.types.d.ts.map +1 -0
- package/dist/dispatcher/dispatcher.utils.d.ts +12 -0
- package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -0
- package/dist/dispatcher/index.d.ts +6 -0
- package/dist/dispatcher/index.d.ts.map +1 -0
- package/dist/http-adapter/http-adapter.constants.d.ts +4 -0
- package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -0
- package/dist/http-adapter/http-adapter.d.ts +3 -0
- package/dist/http-adapter/http-adapter.d.ts.map +1 -0
- package/dist/http-adapter/http-adapter.fetch.d.ts +6 -0
- package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -0
- package/dist/http-adapter/http-adapter.types.d.ts +73 -0
- package/dist/http-adapter/http-adapter.types.d.ts.map +1 -0
- package/dist/http-adapter/http-adapter.utils.d.ts +10 -0
- package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -0
- package/dist/http-adapter/index.d.ts +6 -0
- package/dist/http-adapter/index.d.ts.map +1 -0
- package/dist/index.d.ts +15 -2083
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +4084 -0
- package/dist/index.mjs.map +1 -0
- package/dist/managers/app/app.manager.constants.d.ts +10 -0
- package/dist/managers/app/app.manager.constants.d.ts.map +1 -0
- package/dist/managers/app/app.manager.d.ts +35 -0
- package/dist/managers/app/app.manager.d.ts.map +1 -0
- package/dist/managers/app/app.manager.events.d.ts +12 -0
- package/dist/managers/app/app.manager.events.d.ts.map +1 -0
- package/dist/managers/app/app.manager.types.d.ts +7 -0
- package/dist/managers/app/app.manager.types.d.ts.map +1 -0
- package/dist/managers/app/app.manager.utils.d.ts +5 -0
- package/dist/managers/app/app.manager.utils.d.ts.map +1 -0
- package/dist/managers/app/index.d.ts +6 -0
- package/dist/managers/app/index.d.ts.map +1 -0
- package/dist/managers/index.d.ts +4 -0
- package/dist/managers/index.d.ts.map +1 -0
- package/dist/managers/logger/index.d.ts +5 -0
- package/dist/managers/logger/index.d.ts.map +1 -0
- package/dist/managers/logger/logger.manager.constants.d.ts +5 -0
- package/dist/managers/logger/logger.manager.constants.d.ts.map +1 -0
- package/dist/managers/logger/logger.manager.d.ts +22 -0
- package/dist/managers/logger/logger.manager.d.ts.map +1 -0
- package/dist/managers/logger/logger.manager.types.d.ts +43 -0
- package/dist/managers/logger/logger.manager.types.d.ts.map +1 -0
- package/dist/managers/logger/logger.manager.utils.d.ts +4 -0
- package/dist/managers/logger/logger.manager.utils.d.ts.map +1 -0
- package/dist/managers/request/index.d.ts +5 -0
- package/dist/managers/request/index.d.ts.map +1 -0
- package/dist/managers/request/request.manager.d.ts +60 -0
- package/dist/managers/request/request.manager.d.ts.map +1 -0
- package/dist/managers/request/request.manager.events.d.ts +55 -0
- package/dist/managers/request/request.manager.events.d.ts.map +1 -0
- package/dist/managers/request/request.manager.types.d.ts +48 -0
- package/dist/managers/request/request.manager.types.d.ts.map +1 -0
- package/dist/managers/request/request.manager.utils.d.ts +30 -0
- package/dist/managers/request/request.manager.utils.d.ts.map +1 -0
- package/dist/mocker/index.d.ts +3 -0
- package/dist/mocker/index.d.ts.map +1 -0
- package/dist/mocker/mocker.d.ts +3 -0
- package/dist/mocker/mocker.d.ts.map +1 -0
- package/dist/mocker/mocker.types.d.ts +25 -0
- package/dist/mocker/mocker.types.d.ts.map +1 -0
- package/dist/plugin/index.d.ts +3 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/plugin.d.ts +55 -0
- package/dist/plugin/plugin.d.ts.map +1 -0
- package/dist/plugin/plugin.types.d.ts +122 -0
- package/dist/plugin/plugin.types.d.ts.map +1 -0
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.d.ts.map +1 -0
- package/dist/request/request.d.ts +195 -0
- package/dist/request/request.d.ts.map +1 -0
- package/dist/request/request.hooks.d.ts +19 -0
- package/dist/request/request.hooks.d.ts.map +1 -0
- package/dist/request/request.types.d.ts +240 -0
- package/dist/request/request.types.d.ts.map +1 -0
- package/dist/request/request.utils.d.ts +25 -0
- package/dist/request/request.utils.d.ts.map +1 -0
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/sdk.d.ts +69 -0
- package/dist/sdk/sdk.d.ts.map +1 -0
- package/dist/types/adapter.types.d.ts +22 -0
- package/dist/types/adapter.types.d.ts.map +1 -0
- package/dist/types/client.types.d.ts +4 -0
- package/dist/types/client.types.d.ts.map +1 -0
- package/dist/types/helpers.types.d.ts +17 -0
- package/dist/types/helpers.types.d.ts.map +1 -0
- package/dist/types/http.types.d.ts +3 -0
- package/dist/types/http.types.d.ts.map +1 -0
- package/dist/types/hydration.types.d.ts +15 -0
- package/dist/types/hydration.types.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/request.types.d.ts +34 -0
- package/dist/types/request.types.d.ts.map +1 -0
- package/dist/utils/emitter.utils.d.ts +13 -0
- package/dist/utils/emitter.utils.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/uuid.utils.d.ts +3 -0
- package/dist/utils/uuid.utils.d.ts.map +1 -0
- package/package.json +10 -25
- package/project.json +4 -0
- package/src/adapter/adapter.bindings.ts +8 -12
- package/src/adapter/adapter.ts +8 -7
- package/src/adapter/adapter.types.ts +10 -6
- package/src/adapter/adapter.utils.ts +1 -1
- package/src/cache/cache.events.ts +4 -11
- package/src/cache/cache.ts +28 -22
- package/src/cache/cache.types.ts +8 -4
- package/src/cache/cache.utils.ts +3 -3
- package/src/client/client.create.ts +4 -3
- package/src/client/client.ts +44 -12
- package/src/client/client.types.ts +25 -3
- package/src/client/client.utils.ts +24 -4
- package/src/dispatcher/dispatcher.events.ts +3 -3
- package/src/dispatcher/dispatcher.ts +59 -28
- package/src/dispatcher/dispatcher.types.ts +19 -2
- package/src/dispatcher/dispatcher.utils.ts +5 -4
- package/src/http-adapter/http-adapter.constants.ts +1 -1
- package/src/http-adapter/http-adapter.fetch.ts +174 -0
- package/src/http-adapter/http-adapter.ts +3 -8
- package/src/http-adapter/http-adapter.types.ts +17 -9
- package/src/http-adapter/http-adapter.utils.ts +6 -9
- package/src/http-adapter/index.ts +1 -0
- package/src/managers/app/app.manager.constants.ts +2 -2
- package/src/managers/app/app.manager.events.ts +1 -1
- package/src/managers/app/app.manager.ts +2 -1
- package/src/managers/logger/logger.manager.constants.ts +1 -1
- package/src/managers/logger/logger.manager.ts +2 -1
- package/src/managers/logger/logger.manager.types.ts +2 -2
- package/src/managers/logger/logger.manager.utils.ts +2 -1
- package/src/managers/request/request.manager.events.ts +13 -11
- package/src/managers/request/request.manager.types.ts +6 -3
- package/src/mocker/mocker.ts +3 -2
- package/src/mocker/mocker.types.ts +1 -1
- package/src/plugin/plugin.ts +2 -2
- package/src/plugin/plugin.types.ts +9 -9
- package/src/request/index.ts +1 -0
- package/src/request/request.hooks.ts +87 -0
- package/src/request/request.ts +155 -77
- package/src/request/request.types.ts +54 -22
- package/src/request/request.utils.ts +86 -23
- package/src/sdk/sdk.ts +153 -8
- package/src/types/adapter.types.ts +1 -1
- package/src/types/client.types.ts +1 -1
- package/src/types/hydration.types.ts +3 -3
- package/src/types/request.types.ts +30 -20
- package/src/utils/uuid.utils.ts +1 -1
- package/tsconfig.base.json +1 -6
- package/tsconfig.json +1 -4
- package/vite.config.ts +45 -0
- package/.eslintrc.json +0 -11
- package/dist/browser/index.js +0 -3751
- package/dist/browser/index.js.map +0 -7
- package/dist/index.js +0 -3991
- package/dist/index.js.map +0 -7
- package/src/http-adapter/http-adapter.browser.ts +0 -102
- package/src/http-adapter/http-adapter.server.ts +0 -135
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ProgressEventType, RequestInstance, RequestJSON, RequestSendOptionsType } from "request";
|
|
1
|
+
import { getErrorMessage } from "adapter";
|
|
3
2
|
import { HttpMethods } from "constants/http.constants";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import type { AdapterInstance, ProgressType, RequestResponseType, ResponseType } from "adapter";
|
|
4
|
+
import type { Dispatcher } from "dispatcher";
|
|
5
|
+
import type { ExtractAdapterType, ExtractErrorType } from "types";
|
|
6
|
+
import type {
|
|
7
|
+
OptimisticCallbackResult,
|
|
8
|
+
ProgressEventType,
|
|
9
|
+
RequestInstance,
|
|
10
|
+
RequestJSON,
|
|
11
|
+
RequestSendOptionsType,
|
|
12
|
+
} from "./request.types";
|
|
13
|
+
|
|
14
|
+
export const scopeKey = (key: string, scope: string | null): string => {
|
|
15
|
+
return scope ? `${scope}__${key}` : key;
|
|
16
|
+
};
|
|
6
17
|
|
|
7
18
|
export const stringifyKey = (value: unknown): string => {
|
|
8
19
|
try {
|
|
@@ -111,7 +122,20 @@ export const getRequestDispatcher = <Request extends RequestInstance>(
|
|
|
111
122
|
return [dispatcher, isFetchDispatcher];
|
|
112
123
|
};
|
|
113
124
|
|
|
114
|
-
export const
|
|
125
|
+
export const mapResponseForSend = async <Request extends RequestInstance>(
|
|
126
|
+
request: Request,
|
|
127
|
+
response: ResponseType<any, any, AdapterInstance>,
|
|
128
|
+
): Promise<RequestResponseType<Request>> => {
|
|
129
|
+
const mapping = request.unstable_responseMapper?.(response as ResponseType<any, any, ExtractAdapterType<Request>>);
|
|
130
|
+
|
|
131
|
+
if (mapping instanceof Promise) {
|
|
132
|
+
return (await mapping) as RequestResponseType<Request>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (mapping || response) as RequestResponseType<Request>;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const sendRequest = async <Request extends RequestInstance>(
|
|
115
139
|
request: Request,
|
|
116
140
|
options?: RequestSendOptionsType<Request>,
|
|
117
141
|
): Promise<RequestResponseType<Request>> => {
|
|
@@ -119,38 +143,74 @@ export const sendRequest = <Request extends RequestInstance>(
|
|
|
119
143
|
const { requestManager } = client;
|
|
120
144
|
const [dispatcher] = getRequestDispatcher(request, options?.dispatcherType);
|
|
121
145
|
|
|
146
|
+
let mutationContext: OptimisticCallbackResult<any> | undefined;
|
|
147
|
+
|
|
148
|
+
if (request.optimistic) {
|
|
149
|
+
try {
|
|
150
|
+
mutationContext = await request.optimistic({
|
|
151
|
+
request,
|
|
152
|
+
client: request.client,
|
|
153
|
+
payload: request.payload,
|
|
154
|
+
});
|
|
155
|
+
} catch (err) {
|
|
156
|
+
return {
|
|
157
|
+
data: null,
|
|
158
|
+
error: new Error(
|
|
159
|
+
`Optimistic callback failed: ${err instanceof Error ? err.message : err}`,
|
|
160
|
+
) as unknown as ExtractErrorType<Request>,
|
|
161
|
+
status: null,
|
|
162
|
+
success: false,
|
|
163
|
+
extra: client.adapter.defaultExtra,
|
|
164
|
+
requestTimestamp: +new Date(),
|
|
165
|
+
responseTimestamp: +new Date(),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
122
170
|
return new Promise<RequestResponseType<Request>>((resolve) => {
|
|
123
171
|
let isResolved = false;
|
|
124
172
|
const requestId = dispatcher.add(request);
|
|
125
|
-
|
|
173
|
+
const { $hooks } = request;
|
|
174
|
+
const beforeSentData = { requestId, request, mutationContext };
|
|
175
|
+
options?.onBeforeSent?.(beforeSentData);
|
|
176
|
+
$hooks.__emit("onBeforeSent", beforeSentData);
|
|
126
177
|
|
|
127
|
-
const unmountRequestStart = requestManager.events.onRequestStartById<Request>(requestId, (data) =>
|
|
128
|
-
|
|
129
|
-
|
|
178
|
+
const unmountRequestStart = requestManager.events.onRequestStartById<Request>(requestId, (data) => {
|
|
179
|
+
const enriched = { ...data, mutationContext };
|
|
180
|
+
options?.onRequestStart?.(enriched);
|
|
181
|
+
$hooks.__emit("onRequestStart", enriched);
|
|
182
|
+
});
|
|
130
183
|
|
|
131
|
-
const unmountResponseStart = requestManager.events.onResponseStartById<Request>(requestId, (data) =>
|
|
132
|
-
|
|
133
|
-
|
|
184
|
+
const unmountResponseStart = requestManager.events.onResponseStartById<Request>(requestId, (data) => {
|
|
185
|
+
const enriched = { ...data, mutationContext };
|
|
186
|
+
options?.onResponseStart?.(enriched);
|
|
187
|
+
$hooks.__emit("onResponseStart", enriched);
|
|
188
|
+
});
|
|
134
189
|
|
|
135
|
-
const unmountUpload = requestManager.events.onUploadProgressById<Request>(requestId, (data) =>
|
|
136
|
-
|
|
137
|
-
|
|
190
|
+
const unmountUpload = requestManager.events.onUploadProgressById<Request>(requestId, (data) => {
|
|
191
|
+
const enriched = { ...data, mutationContext };
|
|
192
|
+
options?.onUploadProgress?.(enriched);
|
|
193
|
+
$hooks.__emit("onUploadProgress", enriched);
|
|
194
|
+
});
|
|
138
195
|
|
|
139
|
-
const unmountDownload = requestManager.events.onDownloadProgressById<Request>(requestId, (data) =>
|
|
140
|
-
|
|
141
|
-
|
|
196
|
+
const unmountDownload = requestManager.events.onDownloadProgressById<Request>(requestId, (data) => {
|
|
197
|
+
const enriched = { ...data, mutationContext };
|
|
198
|
+
options?.onDownloadProgress?.(enriched);
|
|
199
|
+
$hooks.__emit("onDownloadProgress", enriched);
|
|
200
|
+
});
|
|
142
201
|
|
|
143
202
|
// When resolved
|
|
144
203
|
const unmountResponse = requestManager.events.onResponseById<Request>(requestId, (values) => {
|
|
145
204
|
const { details, response } = values;
|
|
146
205
|
isResolved = true;
|
|
206
|
+
const enrichedValues = { ...values, mutationContext };
|
|
147
207
|
|
|
148
208
|
const mapping = request.unstable_responseMapper?.(
|
|
149
209
|
response as ResponseType<any, any, ExtractAdapterType<Request>>,
|
|
150
210
|
);
|
|
151
211
|
|
|
152
212
|
const isOfflineStatus = request.offline && details.isOffline;
|
|
153
|
-
const willRetry =
|
|
213
|
+
const { willRetry } = details;
|
|
154
214
|
|
|
155
215
|
const handleResponse = (success: boolean, data: ResponseType<any, any, ExtractAdapterType<Request>>) => {
|
|
156
216
|
// When going offline we can't handle the request as it will be postponed to later resolve
|
|
@@ -159,11 +219,12 @@ export const sendRequest = <Request extends RequestInstance>(
|
|
|
159
219
|
// When request is in retry mode we need to listen for retries end
|
|
160
220
|
if (!success && willRetry) return;
|
|
161
221
|
|
|
162
|
-
options?.onResponse?.(
|
|
222
|
+
options?.onResponse?.(enrichedValues);
|
|
223
|
+
$hooks.__emit("onResponse", enrichedValues);
|
|
163
224
|
resolve(data);
|
|
164
225
|
|
|
165
226
|
// Unmount Listeners
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define, @typescript-eslint/no-use-before-define
|
|
167
228
|
umountAll();
|
|
168
229
|
};
|
|
169
230
|
|
|
@@ -185,9 +246,11 @@ export const sendRequest = <Request extends RequestInstance>(
|
|
|
185
246
|
});
|
|
186
247
|
|
|
187
248
|
// When removed from queue storage we need to clean event listeners and return proper error
|
|
188
|
-
const unmountRemoveQueueElement = requestManager.events.onRemoveById<Request>(requestId, (
|
|
249
|
+
const unmountRemoveQueueElement = requestManager.events.onRemoveById<Request>(requestId, (data) => {
|
|
189
250
|
if (!isResolved) {
|
|
190
|
-
|
|
251
|
+
const enriched = { ...data, mutationContext };
|
|
252
|
+
options?.onRemove?.(enriched);
|
|
253
|
+
$hooks.__emit("onRemove", enriched);
|
|
191
254
|
resolve({
|
|
192
255
|
data: null,
|
|
193
256
|
status: null,
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -1,23 +1,127 @@
|
|
|
1
|
-
import { ClientInstance } from "client";
|
|
1
|
+
import type { ClientInstance } from "client";
|
|
2
|
+
import type { RequestInstance } from "request";
|
|
3
|
+
import type { ExtractEndpointType } from "types";
|
|
2
4
|
|
|
3
5
|
export type RecursiveSchemaType = Record<
|
|
4
6
|
string, // for example users / $userId / posts / $postId
|
|
5
7
|
any
|
|
6
8
|
>;
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Per-request defaults that can be applied via SDK configuration.
|
|
12
|
+
* These mirror the chainable setters on Request (headers, cache, retry, etc.).
|
|
13
|
+
*/
|
|
14
|
+
export type SdkRequestDefaults = {
|
|
15
|
+
headers?: HeadersInit;
|
|
16
|
+
auth?: boolean;
|
|
17
|
+
cache?: boolean;
|
|
18
|
+
cacheTime?: number;
|
|
19
|
+
staleTime?: number;
|
|
20
|
+
retry?: number;
|
|
21
|
+
retryTime?: number;
|
|
22
|
+
cancelable?: boolean;
|
|
23
|
+
queued?: boolean;
|
|
24
|
+
offline?: boolean;
|
|
25
|
+
deduplicate?: boolean;
|
|
26
|
+
deduplicateTime?: number | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Recursively extracts all endpoint strings from an SDK schema type.
|
|
31
|
+
* Leaf nodes (keys starting with $) are RequestInstance — extract endpoint from those.
|
|
32
|
+
* Other keys are nested schema segments to recurse into.
|
|
33
|
+
*/
|
|
34
|
+
type ExtractSdkEndpoints<T, Depth extends unknown[] = []> = Depth["length"] extends 10
|
|
35
|
+
? never
|
|
36
|
+
: {
|
|
37
|
+
[K in keyof T]: K extends `$${string}`
|
|
38
|
+
? T[K] extends RequestInstance
|
|
39
|
+
? ExtractEndpointType<T[K]>
|
|
40
|
+
: never
|
|
41
|
+
: T[K] extends Record<string, any>
|
|
42
|
+
? ExtractSdkEndpoints<T[K], [...Depth, unknown]>
|
|
43
|
+
: never;
|
|
44
|
+
}[keyof T];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Builds the set of valid configuration keys from an SDK schema:
|
|
48
|
+
* - "*" (global wildcard)
|
|
49
|
+
* - exact endpoint paths extracted from RequestInstance nodes
|
|
50
|
+
* - wildcard patterns like "/users/*"
|
|
51
|
+
*/
|
|
52
|
+
type SdkConfigurationKeys<Schema extends RecursiveSchemaType> =
|
|
53
|
+
| "*"
|
|
54
|
+
| ExtractSdkEndpoints<Schema>
|
|
55
|
+
| `${ExtractSdkEndpoints<Schema> & string}/*`;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Maps endpoint paths or wildcard patterns to request defaults.
|
|
59
|
+
* Keys are validated against the SDK schema — only known endpoints, their wildcard
|
|
60
|
+
* variants, and "*" are accepted.
|
|
61
|
+
*/
|
|
62
|
+
export type SdkConfigurationMap<Schema extends RecursiveSchemaType = RecursiveSchemaType> = Partial<
|
|
63
|
+
Record<SdkConfigurationKeys<Schema>, SdkRequestDefaults>
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
export type CreateSdkOptions<Schema extends RecursiveSchemaType = RecursiveSchemaType> = {
|
|
9
67
|
/** @default true */
|
|
10
68
|
camelCaseToKebabCase?: boolean;
|
|
11
69
|
/** @default (method) => method.toUpperCase() */
|
|
12
70
|
methodTransform?: (method: string) => string;
|
|
71
|
+
/** Per-endpoint request defaults */
|
|
72
|
+
defaults?: SdkConfigurationMap<Schema>;
|
|
13
73
|
};
|
|
14
74
|
|
|
15
|
-
const getMethod = (key: string, options?: CreateSdkOptions) => {
|
|
75
|
+
const getMethod = (key: string, options?: CreateSdkOptions<any>) => {
|
|
16
76
|
const { methodTransform = (method: string) => method.toUpperCase() } = options ?? {};
|
|
17
77
|
return methodTransform(key);
|
|
18
78
|
};
|
|
19
79
|
|
|
20
|
-
const
|
|
80
|
+
const endpointMatchesPattern = (endpoint: string, pattern: string): boolean => {
|
|
81
|
+
if (pattern === "*") return true;
|
|
82
|
+
if (pattern === endpoint) return true;
|
|
83
|
+
// Simple wildcard: "/users/*" matches "/users/:userId", "/users/:userId/posts", etc.
|
|
84
|
+
if (pattern.endsWith("/*")) {
|
|
85
|
+
const prefix = pattern.slice(0, -1);
|
|
86
|
+
return endpoint.startsWith(prefix) || endpoint === prefix.slice(0, -1);
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const applyDefaults = (
|
|
92
|
+
request: RequestInstance,
|
|
93
|
+
endpoint: string,
|
|
94
|
+
defaults?: Record<string, SdkRequestDefaults>,
|
|
95
|
+
): RequestInstance => {
|
|
96
|
+
if (!defaults) return request;
|
|
97
|
+
|
|
98
|
+
let result = request;
|
|
99
|
+
const entries = Object.entries(defaults);
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
102
|
+
const [pattern, config] = entries[i];
|
|
103
|
+
if (endpointMatchesPattern(endpoint, pattern)) {
|
|
104
|
+
if (config.headers) result = result.setHeaders(config.headers);
|
|
105
|
+
if (config.auth !== undefined) result = result.setAuth(config.auth);
|
|
106
|
+
if (config.cache !== undefined) result = result.setCache(config.cache);
|
|
107
|
+
if (config.cacheTime !== undefined) result = result.setCacheTime(config.cacheTime);
|
|
108
|
+
if (config.staleTime !== undefined) result = result.setStaleTime(config.staleTime);
|
|
109
|
+
if (config.retry !== undefined) result = result.setRetry(config.retry);
|
|
110
|
+
if (config.retryTime !== undefined) result = result.setRetryTime(config.retryTime);
|
|
111
|
+
if (config.cancelable !== undefined) result = result.setCancelable(config.cancelable);
|
|
112
|
+
if (config.queued !== undefined) result = result.setQueued(config.queued);
|
|
113
|
+
if (config.offline !== undefined) result = result.setOffline(config.offline);
|
|
114
|
+
if (config.deduplicate !== undefined) result = result.setDeduplicate(config.deduplicate);
|
|
115
|
+
if (config.deduplicateTime !== undefined && config.deduplicateTime !== null) {
|
|
116
|
+
result = result.setDeduplicateTime(config.deduplicateTime);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const createRecursiveProxy = (client: ClientInstance, path: string[], options?: CreateSdkOptions<any>): any => {
|
|
21
125
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
22
126
|
return new Proxy(() => {}, {
|
|
23
127
|
get: (_target, key: string) => {
|
|
@@ -45,7 +149,8 @@ const createRecursiveProxy = (client: ClientInstance, path: string[], options?:
|
|
|
45
149
|
// Always create a request assuming this is a method call
|
|
46
150
|
const endpoint = `/${path.join("/")}`;
|
|
47
151
|
const method = getMethod(isMethod ? methodName : key, options);
|
|
48
|
-
|
|
152
|
+
let request: RequestInstance = client.createRequest()({ endpoint, method });
|
|
153
|
+
request = applyDefaults(request, endpoint, options?.defaults);
|
|
49
154
|
|
|
50
155
|
// But also, assume the key is a new path segment for a deeper call
|
|
51
156
|
const newPath = [...path, pathSegment];
|
|
@@ -66,14 +171,54 @@ const createRecursiveProxy = (client: ClientInstance, path: string[], options?:
|
|
|
66
171
|
});
|
|
67
172
|
};
|
|
68
173
|
|
|
174
|
+
export type SdkInstance<Schema extends RecursiveSchemaType> = Schema & {
|
|
175
|
+
/**
|
|
176
|
+
* Apply request defaults to the SDK. Returns a new SDK instance with the configuration applied.
|
|
177
|
+
* Use "*" to match all endpoints, or specific endpoint strings / wildcard patterns.
|
|
178
|
+
*/
|
|
179
|
+
$configure: (defaults: SdkConfigurationMap<Schema>) => SdkInstance<Schema>;
|
|
180
|
+
};
|
|
181
|
+
|
|
69
182
|
export const createSdk = <Client extends ClientInstance, RecursiveSchema extends RecursiveSchemaType>(
|
|
70
183
|
client: Client,
|
|
71
|
-
options?: CreateSdkOptions
|
|
72
|
-
): RecursiveSchema => {
|
|
184
|
+
options?: CreateSdkOptions<RecursiveSchema>,
|
|
185
|
+
): SdkInstance<RecursiveSchema> => {
|
|
73
186
|
const {
|
|
74
187
|
camelCaseToKebabCase = true,
|
|
75
188
|
methodTransform = (method: string) => method.toUpperCase(),
|
|
76
189
|
...rest
|
|
77
190
|
} = options ?? {};
|
|
78
|
-
|
|
191
|
+
|
|
192
|
+
const mergedOptions = {
|
|
193
|
+
camelCaseToKebabCase,
|
|
194
|
+
methodTransform,
|
|
195
|
+
...rest,
|
|
196
|
+
} as CreateSdkOptions<RecursiveSchema>;
|
|
197
|
+
|
|
198
|
+
const proxy = createRecursiveProxy(client, [], mergedOptions);
|
|
199
|
+
|
|
200
|
+
return new Proxy(proxy, {
|
|
201
|
+
get: (target, key: string) => {
|
|
202
|
+
if (key === "$configure") {
|
|
203
|
+
return (defaults: SdkConfigurationMap<RecursiveSchema>) => {
|
|
204
|
+
const existingDefaults = mergedOptions.defaults || {};
|
|
205
|
+
return createSdk<Client, RecursiveSchema>(client, {
|
|
206
|
+
...mergedOptions,
|
|
207
|
+
defaults: { ...existingDefaults, ...defaults } as SdkConfigurationMap<RecursiveSchema>,
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return target[key];
|
|
212
|
+
},
|
|
213
|
+
}) as SdkInstance<RecursiveSchema>;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Type-safe factory for creating SDK configuration maps.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const config = createConfiguration<MySdkSchema>()({ "*": { retry: 3 } })
|
|
221
|
+
*/
|
|
222
|
+
export const createConfiguration = <Schema extends RecursiveSchemaType>() => {
|
|
223
|
+
return (defaults: SdkConfigurationMap<Schema>): SdkConfigurationMap<Schema> => defaults;
|
|
79
224
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, ClientInstance } from "client";
|
|
1
|
+
import type { Client, ClientInstance } from "client";
|
|
2
2
|
|
|
3
3
|
export type ExtractClientGlobalError<T extends ClientInstance> = T extends Client<infer P, any> ? P : never;
|
|
4
4
|
export type ExtractClientAdapterType<T extends ClientInstance> = T extends Client<any, infer P> ? P : never;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AdapterInstance, ResponseType } from "adapter";
|
|
2
|
-
import { RequestCacheType } from "cache";
|
|
3
|
-
import { RequestInstance } from "request";
|
|
1
|
+
import type { AdapterInstance, ResponseType } from "adapter";
|
|
2
|
+
import type { RequestCacheType } from "cache";
|
|
3
|
+
import type { RequestInstance } from "request";
|
|
4
4
|
|
|
5
5
|
export type HydrationOptions = RequestCacheType<RequestInstance> & {
|
|
6
6
|
override: boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ResponseType } from "adapter";
|
|
2
|
-
import { ExtractUrlParams, Request, RequestInstance } from "request";
|
|
3
|
-
import { ExtractClientAdapterType, ExtractClientGlobalError } from "./client.types";
|
|
4
|
-
import { Client, ClientInstance } from "client";
|
|
5
|
-
import { TypeWithDefaults } from "./helpers.types";
|
|
6
|
-
import { ExtractAdapterEndpointType } from "./adapter.types";
|
|
1
|
+
import type { ResponseType } from "adapter";
|
|
2
|
+
import type { ExtractUrlParams, Request, RequestInstance } from "request";
|
|
3
|
+
import type { ExtractClientAdapterType, ExtractClientGlobalError } from "./client.types";
|
|
4
|
+
import type { Client, ClientInstance } from "client";
|
|
5
|
+
import type { TypeWithDefaults } from "./helpers.types";
|
|
6
|
+
import type { ExtractAdapterEndpointType } from "./adapter.types";
|
|
7
7
|
|
|
8
8
|
export type ExtractAdapterResolvedType<T extends RequestInstance> = ResponseType<
|
|
9
9
|
ExtractResponseType<T>,
|
|
@@ -11,40 +11,49 @@ export type ExtractAdapterResolvedType<T extends RequestInstance> = ResponseType
|
|
|
11
11
|
ExtractAdapterType<T>
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
export type ExtractResponseType<T> =
|
|
14
|
+
export type ExtractResponseType<T> =
|
|
15
|
+
T extends Request<infer D, any, any, any, any, any, any, any, any, any> ? D : never;
|
|
15
16
|
|
|
16
|
-
export type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any> ? D : never;
|
|
17
|
+
export type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any, any> ? D : never;
|
|
17
18
|
|
|
18
|
-
export type ExtractQueryParamsType<T> =
|
|
19
|
+
export type ExtractQueryParamsType<T> =
|
|
20
|
+
T extends Request<any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
19
21
|
|
|
20
22
|
export type ExtractErrorType<T> =
|
|
21
|
-
T extends Request<any, any, any, infer G, any, infer C, any, any, any> ? G | ExtractClientGlobalError<C> : never;
|
|
23
|
+
T extends Request<any, any, any, infer G, any, infer C, any, any, any, any> ? G | ExtractClientGlobalError<C> : never;
|
|
22
24
|
|
|
23
25
|
export type ExtractGlobalErrorType<T> =
|
|
24
|
-
T extends Request<any, any, any, any, any, infer C, any, any, any> ? ExtractClientGlobalError<C> : never;
|
|
26
|
+
T extends Request<any, any, any, any, any, infer C, any, any, any, any> ? ExtractClientGlobalError<C> : never;
|
|
25
27
|
|
|
26
|
-
export type ExtractLocalErrorType<T> =
|
|
28
|
+
export type ExtractLocalErrorType<T> =
|
|
29
|
+
T extends Request<any, any, any, infer E, any, any, any, any, any, any> ? E : never;
|
|
27
30
|
|
|
28
31
|
export type ExtractParamsType<T> =
|
|
29
|
-
T extends Request<any, any, any, any, infer E, any, any, any, any>
|
|
32
|
+
T extends Request<any, any, any, any, infer E, any, any, any, any, any>
|
|
30
33
|
? E extends string
|
|
31
34
|
? ExtractUrlParams<E>
|
|
32
35
|
: never
|
|
33
36
|
: never;
|
|
34
37
|
|
|
35
|
-
export type ExtractEndpointType<T> =
|
|
38
|
+
export type ExtractEndpointType<T> =
|
|
39
|
+
T extends Request<any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
36
40
|
|
|
37
|
-
export type ExtractClientType<T> = T extends Request<any, any, any, any, any, infer C, any, any, any> ? C : never;
|
|
41
|
+
export type ExtractClientType<T> = T extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
38
42
|
|
|
39
43
|
export type ExtractAdapterType<T> =
|
|
40
|
-
T extends Request<any, any, any, any, any, infer C, any, any, any> ? ExtractClientAdapterType<C> : never;
|
|
44
|
+
T extends Request<any, any, any, any, any, infer C, any, any, any, any> ? ExtractClientAdapterType<C> : never;
|
|
41
45
|
|
|
42
|
-
export type ExtractHasPayloadType<T> =
|
|
46
|
+
export type ExtractHasPayloadType<T> =
|
|
47
|
+
T extends Request<any, any, any, any, any, any, infer D, any, any, any> ? D : never;
|
|
43
48
|
|
|
44
|
-
export type ExtractHasParamsType<T> =
|
|
49
|
+
export type ExtractHasParamsType<T> =
|
|
50
|
+
T extends Request<any, any, any, any, any, any, any, infer P, any, any> ? P : never;
|
|
45
51
|
|
|
46
52
|
export type ExtractHasQueryParamsType<T> =
|
|
47
|
-
T extends Request<any, any, any, any, any, any, any, any, infer Q> ? Q : never;
|
|
53
|
+
T extends Request<any, any, any, any, any, any, any, any, infer Q, any> ? Q : never;
|
|
54
|
+
|
|
55
|
+
export type ExtractMutationContextType<T> =
|
|
56
|
+
T extends Request<any, any, any, any, any, any, any, any, any, infer Ctx> ? Ctx : undefined;
|
|
48
57
|
|
|
49
58
|
export type ExtendRequest<
|
|
50
59
|
Req extends RequestInstance,
|
|
@@ -69,5 +78,6 @@ export type ExtendRequest<
|
|
|
69
78
|
Properties["client"] extends ClientInstance ? Properties["client"] : ExtractClientType<Req>,
|
|
70
79
|
Properties["hasData"] extends true ? true : ExtractHasPayloadType<Req>,
|
|
71
80
|
Properties["hasParams"] extends true ? true : ExtractHasParamsType<Req>,
|
|
72
|
-
Properties["hasQuery"] extends true ? true : ExtractHasQueryParamsType<Req
|
|
81
|
+
Properties["hasQuery"] extends true ? true : ExtractHasQueryParamsType<Req>,
|
|
82
|
+
ExtractMutationContextType<Req>
|
|
73
83
|
>;
|
package/src/utils/uuid.utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestInstance } from "request";
|
|
1
|
+
import type { RequestInstance } from "request";
|
|
2
2
|
|
|
3
3
|
export const getUniqueRequestId = (request: Pick<RequestInstance, "queryKey">) => {
|
|
4
4
|
return `${request.queryKey}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`;
|
package/tsconfig.base.json
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
"extends": "../../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"rootDir": "./src",
|
|
5
|
-
"baseUrl": "./src"
|
|
6
|
-
"paths": {
|
|
7
|
-
// We set double browser adapters because this file is used only for the browser build
|
|
8
|
-
"@browser-adapter": ["./http-adapter/http-adapter.browser.ts"],
|
|
9
|
-
"@server-adapter": ["./http-adapter/http-adapter.browser.ts"]
|
|
10
|
-
}
|
|
5
|
+
"baseUrl": "./src"
|
|
11
6
|
}
|
|
12
7
|
}
|
package/tsconfig.json
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"baseUrl": "./src",
|
|
5
5
|
"paths": {
|
|
6
|
-
// This build produce the isomorphic build
|
|
7
|
-
"@browser-adapter": ["./http-adapter/http-adapter.browser.ts"],
|
|
8
|
-
"@server-adapter": ["./http-adapter/http-adapter.server.ts"],
|
|
9
6
|
"@hyper-fetch/core": ["../src"]
|
|
10
7
|
}
|
|
11
8
|
},
|
|
12
|
-
"exclude": ["node_modules", "dist", "
|
|
9
|
+
"exclude": ["node_modules", "dist", "vite.config.ts", "__tests__"]
|
|
13
10
|
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="vitest/config" />
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
import dts from "vite-plugin-dts";
|
|
4
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { getDtsCompilerOptionsForPackage } from "../../scripts/vite-dts-internal-paths";
|
|
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
|
+
formats: ["es"],
|
|
14
|
+
fileName: "index",
|
|
15
|
+
},
|
|
16
|
+
sourcemap: true,
|
|
17
|
+
minify: false,
|
|
18
|
+
rollupOptions: {
|
|
19
|
+
external: getRollupExternalsFromPackageJson(__dirname),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
plugins: [
|
|
23
|
+
dts({
|
|
24
|
+
entryRoot: "src",
|
|
25
|
+
compilerOptions: getDtsCompilerOptionsForPackage(__dirname),
|
|
26
|
+
}),
|
|
27
|
+
tsconfigPaths(),
|
|
28
|
+
],
|
|
29
|
+
test: {
|
|
30
|
+
globals: true,
|
|
31
|
+
environment: "jsdom",
|
|
32
|
+
setupFiles: ["./__tests__/vitest.setup.ts"],
|
|
33
|
+
include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
|
|
34
|
+
coverage: {
|
|
35
|
+
provider: "v8",
|
|
36
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
37
|
+
exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
|
|
38
|
+
},
|
|
39
|
+
alias: {
|
|
40
|
+
"@hyper-fetch/core": path.resolve(__dirname, "./src/index.ts"),
|
|
41
|
+
"@hyper-fetch/sockets": path.resolve(__dirname, "../sockets/src/index.ts"),
|
|
42
|
+
"@hyper-fetch/testing": path.resolve(__dirname, "../testing/src/index.ts"),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
package/.eslintrc.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["plugin:@nx/react", "../../.eslintrc.js"],
|
|
3
|
-
"parserOptions": {
|
|
4
|
-
"project": ["./tsconfig.json"]
|
|
5
|
-
},
|
|
6
|
-
"rules": {
|
|
7
|
-
"react/jsx-props-no-spreading": 0,
|
|
8
|
-
"react/require-default-props": 0
|
|
9
|
-
},
|
|
10
|
-
"ignorePatterns": ["dist/", "coverage/", "jest.config.ts", "/*.js"]
|
|
11
|
-
}
|