@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
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
// Auto-generated SDK stress test — deeply typed SDK with 500+ endpoints
|
|
4
|
+
import { createClient, createSdk } from "../../src";
|
|
5
|
+
|
|
6
|
+
const client = createClient({ url: "https://api.test.com" });
|
|
7
|
+
|
|
8
|
+
// Simulate a real-world SDK type with many endpoints organized by domain
|
|
9
|
+
type UserResponse = { id: number; name: string; email: string };
|
|
10
|
+
type PostResponse = { id: number; title: string; body: string; authorId: number };
|
|
11
|
+
type CommentResponse = { id: number; text: string; postId: number; userId: number };
|
|
12
|
+
type ProductResponse = { id: number; name: string; price: number; sku: string };
|
|
13
|
+
type OrderResponse = { id: number; total: number; status: string; userId: number };
|
|
14
|
+
type PaymentResponse = { id: number; amount: number; method: string; orderId: number };
|
|
15
|
+
type NotificationResponse = { id: number; message: string; read: boolean };
|
|
16
|
+
type SettingsResponse = { theme: string; language: string; timezone: string };
|
|
17
|
+
type AnalyticsResponse = { pageViews: number; uniqueVisitors: number; bounceRate: number };
|
|
18
|
+
type TeamResponse = { id: number; name: string; memberCount: number };
|
|
19
|
+
|
|
20
|
+
// Build a large SDK schema type — each path has multiple methods
|
|
21
|
+
type SdkRequest<T extends Record<string, any> = {}> = ReturnType<ReturnType<typeof client.createRequest<T>>>;
|
|
22
|
+
|
|
23
|
+
type SdkSchema = {
|
|
24
|
+
users: {
|
|
25
|
+
$GET: SdkRequest<{ response: UserResponse[] }>;
|
|
26
|
+
$POST: SdkRequest<{ response: UserResponse; payload: Omit<UserResponse, "id"> }>;
|
|
27
|
+
$userId: {
|
|
28
|
+
$GET: SdkRequest<{ response: UserResponse }>;
|
|
29
|
+
$PUT: SdkRequest<{ response: UserResponse; payload: Partial<UserResponse> }>;
|
|
30
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
31
|
+
posts: {
|
|
32
|
+
$GET: SdkRequest<{ response: PostResponse[] }>;
|
|
33
|
+
$POST: SdkRequest<{ response: PostResponse; payload: Omit<PostResponse, "id"> }>;
|
|
34
|
+
$postId: {
|
|
35
|
+
$GET: SdkRequest<{ response: PostResponse }>;
|
|
36
|
+
$PUT: SdkRequest<{ response: PostResponse; payload: Partial<PostResponse> }>;
|
|
37
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
38
|
+
comments: {
|
|
39
|
+
$GET: SdkRequest<{ response: CommentResponse[] }>;
|
|
40
|
+
$POST: SdkRequest<{ response: CommentResponse; payload: Omit<CommentResponse, "id"> }>;
|
|
41
|
+
$commentId: {
|
|
42
|
+
$GET: SdkRequest<{ response: CommentResponse }>;
|
|
43
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
settings: {
|
|
49
|
+
$GET: SdkRequest<{ response: SettingsResponse }>;
|
|
50
|
+
$PUT: SdkRequest<{ response: SettingsResponse; payload: SettingsResponse }>;
|
|
51
|
+
};
|
|
52
|
+
notifications: {
|
|
53
|
+
$GET: SdkRequest<{
|
|
54
|
+
response: NotificationResponse[];
|
|
55
|
+
queryParams: { page: number; limit: number };
|
|
56
|
+
}>;
|
|
57
|
+
$notificationId: {
|
|
58
|
+
$PATCH: SdkRequest<{ response: NotificationResponse; payload: { read: boolean } }>;
|
|
59
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
teams: {
|
|
63
|
+
$GET: SdkRequest<{ response: TeamResponse[] }>;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
products: {
|
|
68
|
+
$GET: SdkRequest<{
|
|
69
|
+
response: ProductResponse[];
|
|
70
|
+
queryParams: { category?: string; minPrice?: number };
|
|
71
|
+
}>;
|
|
72
|
+
$POST: SdkRequest<{ response: ProductResponse; payload: Omit<ProductResponse, "id"> }>;
|
|
73
|
+
$productId: {
|
|
74
|
+
$GET: SdkRequest<{ response: ProductResponse }>;
|
|
75
|
+
$PUT: SdkRequest<{ response: ProductResponse; payload: Partial<ProductResponse> }>;
|
|
76
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
77
|
+
reviews: {
|
|
78
|
+
$GET: SdkRequest<{ response: { rating: number; text: string }[] }>;
|
|
79
|
+
$POST: SdkRequest<{
|
|
80
|
+
response: { rating: number; text: string };
|
|
81
|
+
payload: { rating: number; text: string };
|
|
82
|
+
}>;
|
|
83
|
+
};
|
|
84
|
+
variants: {
|
|
85
|
+
$GET: SdkRequest<{ response: { id: number; color: string; size: string }[] }>;
|
|
86
|
+
$variantId: {
|
|
87
|
+
$GET: SdkRequest<{ response: { id: number; color: string; size: string } }>;
|
|
88
|
+
$PATCH: SdkRequest<{
|
|
89
|
+
response: { id: number; color: string; size: string };
|
|
90
|
+
payload: { color?: string; size?: string };
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
orders: {
|
|
97
|
+
$GET: SdkRequest<{ response: OrderResponse[]; queryParams: { status?: string } }>;
|
|
98
|
+
$POST: SdkRequest<{
|
|
99
|
+
response: OrderResponse;
|
|
100
|
+
payload: { items: { productId: number; quantity: number }[] };
|
|
101
|
+
}>;
|
|
102
|
+
$orderId: {
|
|
103
|
+
$GET: SdkRequest<{ response: OrderResponse }>;
|
|
104
|
+
$PATCH: SdkRequest<{ response: OrderResponse; payload: { status: string } }>;
|
|
105
|
+
items: {
|
|
106
|
+
$GET: SdkRequest<{ response: { productId: number; quantity: number; price: number }[] }>;
|
|
107
|
+
$itemId: {
|
|
108
|
+
$PATCH: SdkRequest<{ response: { quantity: number }; payload: { quantity: number } }>;
|
|
109
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
payments: {
|
|
113
|
+
$GET: SdkRequest<{ response: PaymentResponse[] }>;
|
|
114
|
+
$POST: SdkRequest<{ response: PaymentResponse; payload: { amount: number; method: string } }>;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
analytics: {
|
|
119
|
+
overview: {
|
|
120
|
+
$GET: SdkRequest<{ response: AnalyticsResponse; queryParams: { from: string; to: string } }>;
|
|
121
|
+
};
|
|
122
|
+
users: {
|
|
123
|
+
$GET: SdkRequest<{
|
|
124
|
+
response: { activeUsers: number; newUsers: number };
|
|
125
|
+
queryParams: { period: string };
|
|
126
|
+
}>;
|
|
127
|
+
};
|
|
128
|
+
revenue: {
|
|
129
|
+
$GET: SdkRequest<{ response: { total: number; byMonth: { month: string; amount: number }[] } }>;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
auth: {
|
|
133
|
+
login: {
|
|
134
|
+
$POST: SdkRequest<{
|
|
135
|
+
response: { token: string; refreshToken: string };
|
|
136
|
+
payload: { email: string; password: string };
|
|
137
|
+
}>;
|
|
138
|
+
};
|
|
139
|
+
register: {
|
|
140
|
+
$POST: SdkRequest<{
|
|
141
|
+
response: UserResponse;
|
|
142
|
+
payload: { email: string; password: string; name: string };
|
|
143
|
+
}>;
|
|
144
|
+
};
|
|
145
|
+
refresh: {
|
|
146
|
+
$POST: SdkRequest<{ response: { token: string }; payload: { refreshToken: string } }>;
|
|
147
|
+
};
|
|
148
|
+
logout: {
|
|
149
|
+
$POST: SdkRequest<{ response: void }>;
|
|
150
|
+
};
|
|
151
|
+
forgotPassword: {
|
|
152
|
+
$POST: SdkRequest<{ response: { message: string }; payload: { email: string } }>;
|
|
153
|
+
};
|
|
154
|
+
resetPassword: {
|
|
155
|
+
$POST: SdkRequest<{ response: { message: string }; payload: { token: string; password: string } }>;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
teams: {
|
|
159
|
+
$GET: SdkRequest<{ response: TeamResponse[] }>;
|
|
160
|
+
$POST: SdkRequest<{ response: TeamResponse; payload: { name: string } }>;
|
|
161
|
+
$teamId: {
|
|
162
|
+
$GET: SdkRequest<{ response: TeamResponse }>;
|
|
163
|
+
$PUT: SdkRequest<{ response: TeamResponse; payload: Partial<TeamResponse> }>;
|
|
164
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
165
|
+
members: {
|
|
166
|
+
$GET: SdkRequest<{ response: UserResponse[] }>;
|
|
167
|
+
$POST: SdkRequest<{ response: void; payload: { userId: number } }>;
|
|
168
|
+
$memberId: {
|
|
169
|
+
$DELETE: SdkRequest<{ response: void }>;
|
|
170
|
+
$PATCH: SdkRequest<{ response: { role: string }; payload: { role: string } }>;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const sdk = createSdk<typeof client, SdkSchema>(client);
|
|
178
|
+
|
|
179
|
+
// Exercise various SDK access patterns
|
|
180
|
+
const r1 = sdk.users.$GET;
|
|
181
|
+
const r2 = sdk.users.$POST;
|
|
182
|
+
const r3 = sdk.users.$userId.$GET;
|
|
183
|
+
const r4 = sdk.users.$userId.posts.$GET;
|
|
184
|
+
const r5 = sdk.users.$userId.posts.$postId.comments.$GET;
|
|
185
|
+
const r6 = sdk.products.$GET;
|
|
186
|
+
const r7 = sdk.products.$productId.reviews.$GET;
|
|
187
|
+
const r8 = sdk.orders.$orderId.items.$GET;
|
|
188
|
+
const r9 = sdk.analytics.overview.$GET;
|
|
189
|
+
const r10 = sdk.auth.login.$POST;
|
|
190
|
+
const r11 = sdk.teams.$teamId.members.$GET;
|
|
191
|
+
const r12 = sdk.products.$productId.variants.$variantId.$PATCH;
|
|
192
|
+
|
|
193
|
+
// Exercise send types
|
|
194
|
+
type S1 = ReturnType<typeof r1.send>;
|
|
195
|
+
type S2 = ReturnType<typeof r2.send>;
|
|
196
|
+
type S3 = ReturnType<typeof r3.send>;
|
|
197
|
+
type S4 = ReturnType<typeof r10.send>;
|
|
198
|
+
type S5 = ReturnType<typeof r11.send>;
|
|
199
|
+
|
|
200
|
+
// Exercise setParams
|
|
201
|
+
const p1 = r3.setParams({ userId: "1" } as any);
|
|
202
|
+
const p2 = r5.setParams({ userId: "1", postId: "2" } as any);
|
|
203
|
+
|
|
204
|
+
// Exercise toJSON
|
|
205
|
+
const j1 = r1.toJSON();
|
|
206
|
+
const j2 = r6.toJSON();
|
|
207
|
+
|
|
208
|
+
const a = "123";
|
|
209
|
+
|
|
210
|
+
export { a };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { sleep } from "@hyper-fetch/testing";
|
|
2
|
+
|
|
3
|
+
import type { RequestInstance } from "request";
|
|
4
|
+
import { Adapter } from "adapter";
|
|
5
|
+
import type { HttpAdapterType } from "http-adapter";
|
|
6
|
+
import { HttpAdapter } from "http-adapter";
|
|
7
|
+
import { LoggerManager } from "managers";
|
|
8
|
+
|
|
9
|
+
export const createAdapter = (props?: {
|
|
10
|
+
sleepTime?: number;
|
|
11
|
+
callback: (request: RequestInstance, requestId: string) => void;
|
|
12
|
+
}): HttpAdapterType => {
|
|
13
|
+
const { sleepTime, callback } = props || {};
|
|
14
|
+
|
|
15
|
+
const httpAdapter = HttpAdapter();
|
|
16
|
+
|
|
17
|
+
const adapter = new Adapter({
|
|
18
|
+
name: "test",
|
|
19
|
+
defaultMethod: "GET",
|
|
20
|
+
defaultExtra: {},
|
|
21
|
+
systemErrorStatus: 0,
|
|
22
|
+
systemErrorExtra: {},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
adapter.logger = new LoggerManager().initialize({ debug: false }, "Adapter");
|
|
26
|
+
httpAdapter.logger = new LoggerManager().initialize({ debug: false }, "Adapter");
|
|
27
|
+
|
|
28
|
+
adapter.unstable_fetcher = httpAdapter.unstable_fetcher as any;
|
|
29
|
+
adapter.fetch = async (request, requestId) => {
|
|
30
|
+
if (sleepTime) {
|
|
31
|
+
await sleep(sleepTime);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
callback?.(request, requestId);
|
|
35
|
+
return httpAdapter.fetch(request as any, requestId);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return httpAdapter as unknown as HttpAdapterType;
|
|
39
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CacheAsyncStorageType, CacheOptionsType } from "cache";
|
|
2
|
+
import { Cache } from "cache";
|
|
3
|
+
import type { ClientInstance } from "client";
|
|
4
|
+
|
|
5
|
+
export const createCache = (client: ClientInstance, options?: CacheOptionsType) => {
|
|
6
|
+
return new Cache(options).initialize(client);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const createLazyCacheAdapter = (storage: Map<any, any>): CacheAsyncStorageType => {
|
|
10
|
+
return {
|
|
11
|
+
get: async (key) => storage.get(key),
|
|
12
|
+
set: async (key, value) => {
|
|
13
|
+
storage.set(key, value);
|
|
14
|
+
},
|
|
15
|
+
keys: async () => storage.keys(),
|
|
16
|
+
delete: async (key) => {
|
|
17
|
+
storage.delete(key);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { sleep } from "@hyper-fetch/testing";
|
|
2
|
+
|
|
3
|
+
import type { ResponseType } from "adapter";
|
|
4
|
+
import type { RequestInstance } from "request";
|
|
5
|
+
import type { ClientInstance, ResponseInterceptorType } from "client";
|
|
6
|
+
import type { HttpAdapterType } from "http-adapter";
|
|
7
|
+
import { xhrExtra } from "http-adapter";
|
|
8
|
+
|
|
9
|
+
export const interceptorCallback = (props?: {
|
|
10
|
+
sleepTime?: number;
|
|
11
|
+
callback: () => void;
|
|
12
|
+
}): ResponseInterceptorType<ClientInstance> => {
|
|
13
|
+
const { sleepTime, callback } = props || {};
|
|
14
|
+
|
|
15
|
+
return async (
|
|
16
|
+
response?: ResponseType<null, null, HttpAdapterType>,
|
|
17
|
+
): Promise<ResponseType<null, null, HttpAdapterType>> => {
|
|
18
|
+
if (sleepTime) {
|
|
19
|
+
await sleep(sleepTime);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
callback?.();
|
|
23
|
+
return (
|
|
24
|
+
response || {
|
|
25
|
+
data: null,
|
|
26
|
+
error: null,
|
|
27
|
+
success: true,
|
|
28
|
+
status: 200,
|
|
29
|
+
extra: xhrExtra,
|
|
30
|
+
requestTimestamp: 0,
|
|
31
|
+
responseTimestamp: 0,
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const middlewareCallback = (props?: { sleepTime?: number; callback: () => void }) => {
|
|
38
|
+
const { sleepTime, callback } = props || {};
|
|
39
|
+
|
|
40
|
+
return async (request: RequestInstance): Promise<RequestInstance> => {
|
|
41
|
+
if (sleepTime) {
|
|
42
|
+
await sleep(sleepTime);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
callback?.();
|
|
46
|
+
return request;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DispatcherOptionsType } from "dispatcher";
|
|
2
|
+
import { Dispatcher } from "dispatcher";
|
|
3
|
+
import type { ClientInstance } from "client";
|
|
4
|
+
|
|
5
|
+
export const createDispatcher = (client: ClientInstance, options?: DispatcherOptionsType) => {
|
|
6
|
+
return new Dispatcher(options).initialize(client);
|
|
7
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="vitest/globals" />
|
|
2
|
+
import { AbortController } from "abortcontroller-polyfill/dist/cjs-ponyfill";
|
|
3
|
+
import { BroadcastChannel } from "node:worker_threads";
|
|
4
|
+
import * as matchers from "jest-extended";
|
|
5
|
+
import { expect } from "vitest";
|
|
6
|
+
|
|
7
|
+
expect.extend(matchers);
|
|
8
|
+
|
|
9
|
+
if (!globalThis.AbortController) {
|
|
10
|
+
globalThis.AbortController = AbortController as any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Object.defineProperties(globalThis, {
|
|
14
|
+
BroadcastChannel: { value: BroadcastChannel },
|
|
15
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ResponseSuccessType, ResponseErrorType, ProgressDataType, AdapterInstance, getErrorMessage } from '.';
|
|
2
|
+
import { LoggerMethods } from '../managers';
|
|
3
|
+
import { RequestInstance } from '../request';
|
|
4
|
+
import { ExtractResponseType, ExtractErrorType, ExtractAdapterOptionsType, ExtractAdapterStatusType, ExtractAdapterExtraType } from '../types';
|
|
5
|
+
export declare const getAdapterBindings: <T extends AdapterInstance>({ request: baseRequest, requestId, resolve, onStartTime, internalErrorMapping, }: {
|
|
6
|
+
request: RequestInstance;
|
|
7
|
+
requestId: string;
|
|
8
|
+
resolve: (value: ResponseSuccessType<any, T> | ResponseErrorType<any, T>) => void;
|
|
9
|
+
onStartTime: (timestamp: number) => void;
|
|
10
|
+
internalErrorMapping: (error: ReturnType<typeof getErrorMessage>) => any;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
request: RequestInstance;
|
|
13
|
+
requestId: string;
|
|
14
|
+
url: string;
|
|
15
|
+
endpoint: any;
|
|
16
|
+
queryParams: any;
|
|
17
|
+
payload: any;
|
|
18
|
+
headers: any;
|
|
19
|
+
adapter: AdapterInstance;
|
|
20
|
+
adapterOptions: ExtractAdapterOptionsType<T> | undefined;
|
|
21
|
+
getAbortController: () => AbortController | undefined;
|
|
22
|
+
getRequestStartTimestamp: () => number | null;
|
|
23
|
+
getResponseStartTimestamp: () => number | null;
|
|
24
|
+
createAbortListener: ({ status, extra, onAbort, }: {
|
|
25
|
+
status: ExtractAdapterStatusType<T>;
|
|
26
|
+
extra: ExtractAdapterExtraType<T>;
|
|
27
|
+
onAbort?: () => void;
|
|
28
|
+
}) => () => void;
|
|
29
|
+
onBeforeRequest: () => void;
|
|
30
|
+
onRequestStart: (progress?: ProgressDataType) => number;
|
|
31
|
+
onRequestProgress: (progress: ProgressDataType) => number;
|
|
32
|
+
onRequestEnd: () => number;
|
|
33
|
+
onResponseStart: (progress?: ProgressDataType) => number;
|
|
34
|
+
onResponseProgress: (progress: ProgressDataType) => number;
|
|
35
|
+
onResponseEnd: () => number;
|
|
36
|
+
onSuccess: ({ data, error, status, extra, }: {
|
|
37
|
+
data: any;
|
|
38
|
+
status: ExtractAdapterStatusType<T>;
|
|
39
|
+
extra: ExtractAdapterExtraType<T>;
|
|
40
|
+
error?: ExtractErrorType<T>;
|
|
41
|
+
}) => Promise<ResponseSuccessType<ExtractResponseType<T>, T>>;
|
|
42
|
+
onAbortError: ({ status, extra, }: {
|
|
43
|
+
status: ExtractAdapterStatusType<T>;
|
|
44
|
+
extra: ExtractAdapterExtraType<T>;
|
|
45
|
+
}) => Promise<ResponseErrorType<any, T>>;
|
|
46
|
+
onTimeoutError: ({ status, extra, }: {
|
|
47
|
+
status: ExtractAdapterStatusType<T>;
|
|
48
|
+
extra: ExtractAdapterExtraType<T>;
|
|
49
|
+
}) => Promise<ResponseErrorType<any, T>>;
|
|
50
|
+
onUnexpectedError: ({ status, extra, }: {
|
|
51
|
+
status: ExtractAdapterStatusType<T>;
|
|
52
|
+
extra: ExtractAdapterExtraType<T>;
|
|
53
|
+
}) => Promise<ResponseErrorType<any, T>>;
|
|
54
|
+
onError: ({ error, status, extra, }: {
|
|
55
|
+
error: any;
|
|
56
|
+
status: ExtractAdapterStatusType<T>;
|
|
57
|
+
extra: ExtractAdapterExtraType<T>;
|
|
58
|
+
}) => Promise<ResponseErrorType<any, T>>;
|
|
59
|
+
}>;
|
|
60
|
+
export declare function getAdapterOnError<T extends AdapterInstance>({ request, requestId, startTime, resolve, logger, }: {
|
|
61
|
+
request: RequestInstance;
|
|
62
|
+
requestId: string;
|
|
63
|
+
startTime: number;
|
|
64
|
+
logger: LoggerMethods;
|
|
65
|
+
resolve: (value: ResponseSuccessType<any, T> | ResponseErrorType<any, T>) => void;
|
|
66
|
+
}): ({ error, status, extra, }: {
|
|
67
|
+
error: any;
|
|
68
|
+
status: ExtractAdapterStatusType<T>;
|
|
69
|
+
extra: ExtractAdapterExtraType<T>;
|
|
70
|
+
}) => Promise<ResponseErrorType<any, T>>;
|
|
71
|
+
//# sourceMappingURL=adapter.bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.bindings.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.bindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACzG,OAAO,EAAE,eAAe,EAA0B,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,SAAS,CAAC;AAElE,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EAEhB,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,OAAO,CAAC;AAEf,eAAO,MAAM,kBAAkB,GAAU,CAAC,SAAS,eAAe,EAAE,kFAMjE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;IAClF,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,oBAAoB,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC;CAC1E;;;;;;;;;;;;;uDA2UI;QACD,MAAM,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC;QACpC,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;KACtB;;gCA9NkC,gBAAgB;kCAyBd,gBAAgB;;iCA8BjB,gBAAgB;mCAed,gBAAgB;;iDAmCnD;QACD,IAAI,EAAE,GAA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"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { EmptyTypes, ExtendRequest } from '../types';
|
|
2
|
+
import { EndpointMapper, AdapterFetcherType, AdapterPayloadMappingType, HeaderMappingType, QueryParamsMapper, QueryParamsType, RequestResponseType } from './adapter.types';
|
|
3
|
+
import { RequestInstance, RequestOptionsType } from '../request';
|
|
4
|
+
import { Client, ClientInstance } from '../client';
|
|
5
|
+
import { LoggerMethods } from '../managers';
|
|
6
|
+
import { getErrorMessage } from './adapter.utils';
|
|
7
|
+
export type DefaultMapperType = <V, C>(value: V, config: C) => V;
|
|
8
|
+
export declare const defaultMapper: DefaultMapperType;
|
|
9
|
+
export declare class Adapter<AdapterOptions, MethodType extends string, StatusType extends number | string, Extra extends Record<string, any>, QueryParams = QueryParamsType | string | EmptyTypes, DefaultQueryParams = undefined, EndpointType = string, EndpointMapperType extends EndpointMapper<EndpointType> | DefaultMapperType = DefaultMapperType, QueryParamsMapperType extends QueryParamsMapper<QueryParams> | DefaultMapperType = DefaultMapperType, HeaderMapperType extends HeaderMappingType | DefaultMapperType = DefaultMapperType, PayloadMapperType extends AdapterPayloadMappingType | DefaultMapperType = DefaultMapperType> {
|
|
10
|
+
options: {
|
|
11
|
+
name: string;
|
|
12
|
+
defaultMethod: MethodType;
|
|
13
|
+
defaultExtra: Extra;
|
|
14
|
+
systemErrorStatus: StatusType;
|
|
15
|
+
systemErrorExtra: Extra;
|
|
16
|
+
defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
|
|
17
|
+
};
|
|
18
|
+
/** Fetching function */
|
|
19
|
+
unstable_fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
|
|
20
|
+
/**
|
|
21
|
+
* ********************
|
|
22
|
+
* Defaults
|
|
23
|
+
* ********************
|
|
24
|
+
*/
|
|
25
|
+
name: string;
|
|
26
|
+
defaultMethod: MethodType;
|
|
27
|
+
defaultExtra: Extra;
|
|
28
|
+
systemErrorStatus: StatusType;
|
|
29
|
+
systemErrorExtra: Extra;
|
|
30
|
+
defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
|
|
31
|
+
logger: LoggerMethods;
|
|
32
|
+
initialized: boolean;
|
|
33
|
+
client: ClientInstance;
|
|
34
|
+
unstable_onInitializeCallback?: (options: {
|
|
35
|
+
client: ClientInstance;
|
|
36
|
+
}) => void;
|
|
37
|
+
unstable_queryParamsMapperConfig: Parameters<QueryParamsMapperType>[1];
|
|
38
|
+
unstable_headerMapperConfig: Parameters<HeaderMapperType>[1];
|
|
39
|
+
unstable_payloadMapperConfig: Parameters<PayloadMapperType>[1];
|
|
40
|
+
unstable_endpointMapperConfig: Parameters<EndpointMapperType>[1];
|
|
41
|
+
constructor(options: {
|
|
42
|
+
name: string;
|
|
43
|
+
defaultMethod: MethodType;
|
|
44
|
+
defaultExtra: Extra;
|
|
45
|
+
systemErrorStatus: StatusType;
|
|
46
|
+
systemErrorExtra: Extra;
|
|
47
|
+
defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
|
|
48
|
+
});
|
|
49
|
+
initialize: (client: ClientInstance) => this;
|
|
50
|
+
onInitialize: (callback: (options: {
|
|
51
|
+
client: ClientInstance;
|
|
52
|
+
}) => void) => this;
|
|
53
|
+
/**
|
|
54
|
+
* ********************
|
|
55
|
+
* Options Setters
|
|
56
|
+
* ********************
|
|
57
|
+
*/
|
|
58
|
+
unstable_internalErrorMapping: (error: ReturnType<typeof getErrorMessage>) => any;
|
|
59
|
+
/** Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats. */
|
|
60
|
+
unstable_headerMapper: HeaderMapperType;
|
|
61
|
+
/** Method to get request data and transform them to the required format. It handles FormData and JSON by default. */
|
|
62
|
+
unstable_payloadMapper: PayloadMapperType;
|
|
63
|
+
/** Method to get the endpoint for the adapter request. */
|
|
64
|
+
unstable_endpointMapper: EndpointMapperType;
|
|
65
|
+
/** Method to get request data and transform them to the required format. */
|
|
66
|
+
unstable_queryParamsMapper: QueryParamsMapperType;
|
|
67
|
+
/** Get default adapter options for the request. */
|
|
68
|
+
unstable_getAdapterDefaults?: (request: ExtendRequest<RequestInstance, {
|
|
69
|
+
client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
|
|
70
|
+
}>) => AdapterOptions;
|
|
71
|
+
/** Get default request options for the request. */
|
|
72
|
+
unstable_getRequestDefaults?: (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>;
|
|
73
|
+
/**
|
|
74
|
+
* Get formatted endpoint name of the request.
|
|
75
|
+
* Helpful in displaying long endpoints like in case of graphql schemas etc.
|
|
76
|
+
*/
|
|
77
|
+
unstable_devtoolsEndpointGetter: (endpoint: string) => string;
|
|
78
|
+
/**
|
|
79
|
+
* ********************
|
|
80
|
+
* Methods
|
|
81
|
+
* ********************
|
|
82
|
+
*/
|
|
83
|
+
setDefaultMethod: (method: MethodType) => this;
|
|
84
|
+
setDefaultExtra: (extra: Extra) => this;
|
|
85
|
+
setDevtoolsEndpointGetter: (callback: (endpoint: string) => string) => this;
|
|
86
|
+
/**
|
|
87
|
+
* This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
|
|
88
|
+
*/
|
|
89
|
+
setRequestDefaults: (callback: typeof this.unstable_getRequestDefaults) => this;
|
|
90
|
+
/**
|
|
91
|
+
* Set the adapter default options added to every sent request
|
|
92
|
+
*/
|
|
93
|
+
setAdapterDefaults: (callback: (request: ExtendRequest<RequestInstance, {
|
|
94
|
+
client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
|
|
95
|
+
}>) => AdapterOptions) => this;
|
|
96
|
+
setInternalErrorMapping: (callback: (error: ReturnType<typeof getErrorMessage>) => any) => this;
|
|
97
|
+
/**
|
|
98
|
+
* Set the custom header mapping function
|
|
99
|
+
*/
|
|
100
|
+
setHeaderMapper: <NewMapper extends HeaderMappingType>(headerMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, NewMapper, PayloadMapperType>;
|
|
101
|
+
/**
|
|
102
|
+
* Set the request payload mapping function which gets triggered before request is send
|
|
103
|
+
*/
|
|
104
|
+
setPayloadMapper: <NewMapper extends AdapterPayloadMappingType>(payloadMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>;
|
|
105
|
+
/**
|
|
106
|
+
* Set the request payload mapping function which get triggered before request get sent
|
|
107
|
+
*/
|
|
108
|
+
setEndpointMapper: <NewEndpointMapper extends EndpointMapper<EndpointType>>(endpointMapper: NewEndpointMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
|
|
109
|
+
/**
|
|
110
|
+
* Set the query params mapping function which get triggered before request get sent
|
|
111
|
+
*/
|
|
112
|
+
setQueryParamsMapper: <NewQueryParamsMapper extends QueryParamsMapper<QueryParams>>(queryParamsMapper: NewQueryParamsMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>;
|
|
113
|
+
setQueryParamsMapperConfig: <NewQueryParamsMapperConfig extends Parameters<QueryParamsMapperType>[1]>(config: NewQueryParamsMapperConfig) => this;
|
|
114
|
+
setHeaderMapperConfig: <NewHeaderMapperConfig extends Parameters<HeaderMapperType>[1]>(config: NewHeaderMapperConfig) => this;
|
|
115
|
+
setEndpointMapperConfig: <NewEndpointMapperConfig extends Parameters<EndpointMapperType>[1]>(config: NewEndpointMapperConfig) => this;
|
|
116
|
+
setPayloadMapperConfig: <NewPayloadMapperConfig extends Parameters<PayloadMapperType>[1]>(config: NewPayloadMapperConfig) => this;
|
|
117
|
+
/**
|
|
118
|
+
* ********************
|
|
119
|
+
* Fetching
|
|
120
|
+
* ********************
|
|
121
|
+
*/
|
|
122
|
+
setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>): this;
|
|
123
|
+
fetch(request: ExtendRequest<RequestInstance, {
|
|
124
|
+
client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
|
|
125
|
+
}>, requestId: string): Promise<RequestResponseType<RequestInstance>>;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC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