@hyper-fetch/core 8.1.1 → 8.2.2
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 +137 -52
- package/__tests__/e2e/e2e.advanced.spec.ts +7 -7
- package/__tests__/features/adapter/adapter.base.spec.ts +2 -1
- package/__tests__/features/adapter/adapter.bindings.spec.ts +4 -4
- package/__tests__/features/adapter/adapter.browser.spec.ts +0 -1
- package/__tests__/features/adapter/adapter.server.spec.ts +4 -5
- package/__tests__/features/adapter/adapter.utils.spec.ts +6 -7
- package/__tests__/features/cache/cache.base.spec.ts +7 -7
- package/__tests__/features/cache/cache.events.spec.ts +15 -15
- package/__tests__/features/cache/cache.garbage-collector.spec.ts +18 -18
- package/__tests__/features/cache/cache.lazy-storage.spec.ts +8 -8
- package/__tests__/features/cache/cache.modes.spec.ts +7 -6
- package/__tests__/features/cache/cache.scoping.spec.ts +12 -8
- package/__tests__/features/cache/cache.typescript.spec.ts +2 -2
- package/__tests__/features/cache/cache.utils.spec.ts +14 -14
- package/__tests__/features/client/client.auth.spec.ts +0 -1
- package/__tests__/features/client/client.base.spec.ts +2 -3
- package/__tests__/features/client/client.from-json.spec.ts +0 -1
- package/__tests__/features/client/client.hydration.spec.ts +5 -5
- package/__tests__/features/client/client.interceptor.spec.ts +3 -3
- package/__tests__/features/client/client.methods.spec.ts +5 -5
- package/__tests__/features/client/client.middleware.spec.ts +2 -2
- package/__tests__/features/client/client.utils.spec.ts +16 -15
- package/__tests__/features/dispatcher/dispatcher.base.spec.ts +3 -3
- package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +4 -5
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +4 -4
- package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +13 -13
- package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +10 -10
- package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +35 -8
- package/__tests__/features/managers/app/app.manager.base.spec.ts +2 -3
- package/__tests__/features/managers/logger/logger.base.spec.ts +1 -2
- package/__tests__/features/managers/request/request.manager.base.spec.ts +8 -9
- package/__tests__/features/managers/request/request.manager.events.spec.ts +1 -2
- package/__tests__/features/mocker/mocker.base.spec.ts +6 -6
- package/__tests__/features/plugin/plugin.base.spec.ts +1 -2
- package/__tests__/features/request/request.cloning.spec.ts +0 -1
- package/__tests__/features/request/request.deduplicate-defaults.spec.ts +79 -0
- package/__tests__/features/request/request.retry-on-error.spec.ts +1 -2
- package/__tests__/features/request/request.sending.spec.ts +73 -24
- package/__tests__/features/request/request.setters.spec.ts +4 -3
- package/__tests__/features/request/request.typescript.spec.ts +0 -1
- package/__tests__/features/request/request.utils.spec.ts +1 -0
- package/__tests__/features/sdk/sdk.base.spec.ts +7 -12
- package/__tests__/features/sdk/sdk.configuration.spec.ts +5 -7
- package/__tests__/features/sdk/sdk.request-fields.spec.ts +80 -0
- package/__tests__/features/sdk/sdk.types.spec.ts +283 -0
- package/__tests__/shared/callbacks.shared.ts +1 -1
- package/__tests__/tsconfig.json +4 -17
- package/__tests__/utils/adapter.utils.ts +1 -2
- package/__tests__/utils/callbacks.utils.ts +1 -2
- package/__tests__/utils/dispatcher.utils.ts +1 -1
- package/__tests__/vitest.setup.ts +1 -1
- package/dist/adapter/adapter.d.ts +22 -5
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.types.d.ts +9 -1
- package/dist/adapter/adapter.types.d.ts.map +1 -1
- package/dist/adapter/adapter.utils.d.ts.map +1 -1
- package/dist/cache/cache.d.ts +6 -9
- package/dist/cache/cache.d.ts.map +1 -1
- package/dist/cache/cache.events.d.ts +7 -4
- package/dist/cache/cache.events.d.ts.map +1 -1
- package/dist/cache/cache.types.d.ts +1 -0
- package/dist/cache/cache.types.d.ts.map +1 -1
- package/dist/client/client.create.d.ts +1 -1
- package/dist/client/client.create.d.ts.map +1 -1
- package/dist/client/client.d.ts +8 -4
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.types.d.ts +1 -1
- package/dist/client/client.types.d.ts.map +1 -1
- package/dist/client/client.utils.d.ts.map +1 -1
- package/dist/constants/http.constants.d.ts +5 -1
- package/dist/constants/http.constants.d.ts.map +1 -1
- package/dist/constants/time.constants.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.d.ts +4 -4
- package/dist/dispatcher/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts +2 -2
- package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.types.d.ts +2 -2
- package/dist/http-adapter/http-adapter.types.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -1
- package/dist/index.mjs +2382 -2301
- package/dist/index.mjs.map +1 -1
- package/dist/managers/app/app.manager.constants.d.ts +1 -1
- package/dist/managers/app/app.manager.constants.d.ts.map +1 -1
- package/dist/managers/app/app.manager.d.ts +1 -1
- package/dist/managers/app/app.manager.d.ts.map +1 -1
- package/dist/managers/app/app.manager.events.d.ts +9 -0
- package/dist/managers/app/app.manager.events.d.ts.map +1 -1
- package/dist/managers/logger/logger.manager.d.ts +1 -1
- package/dist/managers/logger/logger.manager.d.ts.map +1 -1
- package/dist/managers/request/request.manager.d.ts.map +1 -1
- package/dist/managers/request/request.manager.events.d.ts +14 -3
- package/dist/managers/request/request.manager.events.d.ts.map +1 -1
- package/dist/mocker/mocker.types.d.ts +1 -0
- package/dist/mocker/mocker.types.d.ts.map +1 -1
- package/dist/plugin/plugin.d.ts +17 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.types.d.ts +5 -4
- package/dist/plugin/plugin.types.d.ts.map +1 -1
- package/dist/request/request.d.ts +33 -4
- package/dist/request/request.d.ts.map +1 -1
- package/dist/request/request.hooks.d.ts +2 -2
- package/dist/request/request.hooks.d.ts.map +1 -1
- package/dist/request/request.types.d.ts +92 -5
- package/dist/request/request.types.d.ts.map +1 -1
- package/dist/request/request.utils.d.ts.map +1 -1
- package/dist/sdk/sdk.d.ts +25 -5
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/dist/types/http.types.d.ts +1 -1
- package/dist/types/http.types.d.ts.map +1 -1
- package/dist/types/request.types.d.ts +2 -2
- package/dist/types/request.types.d.ts.map +1 -1
- package/dist/utils/emitter.utils.d.ts +1 -1
- package/dist/utils/emitter.utils.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/adapter/adapter.bindings.ts +14 -14
- package/src/adapter/adapter.ts +28 -10
- package/src/adapter/adapter.types.ts +10 -1
- package/src/adapter/adapter.utils.ts +5 -5
- package/src/cache/cache.events.ts +7 -5
- package/src/cache/cache.ts +14 -17
- package/src/cache/cache.types.ts +1 -0
- package/src/client/client.create.ts +1 -1
- package/src/client/client.ts +14 -9
- package/src/client/client.types.ts +2 -2
- package/src/client/client.utils.ts +3 -2
- package/src/constants/http.constants.ts +5 -0
- package/src/constants/time.constants.ts +1 -1
- package/src/dispatcher/dispatcher.events.ts +1 -2
- package/src/dispatcher/dispatcher.ts +13 -13
- package/src/dispatcher/dispatcher.utils.ts +10 -4
- package/src/http-adapter/http-adapter.constants.ts +1 -0
- package/src/http-adapter/http-adapter.fetch.ts +19 -9
- package/src/http-adapter/http-adapter.ts +2 -1
- package/src/http-adapter/http-adapter.types.ts +3 -2
- package/src/http-adapter/http-adapter.utils.ts +15 -11
- package/src/managers/app/app.manager.constants.ts +2 -1
- package/src/managers/app/app.manager.events.ts +9 -1
- package/src/managers/app/app.manager.ts +1 -1
- package/src/managers/app/app.manager.utils.ts +2 -2
- package/src/managers/logger/logger.manager.ts +1 -2
- package/src/managers/request/request.manager.events.ts +14 -12
- package/src/managers/request/request.manager.ts +4 -4
- package/src/mocker/mocker.ts +2 -2
- package/src/mocker/mocker.types.ts +1 -0
- package/src/plugin/plugin.ts +17 -1
- package/src/plugin/plugin.types.ts +5 -4
- package/src/request/request.hooks.ts +6 -5
- package/src/request/request.ts +77 -34
- package/src/request/request.types.ts +107 -5
- package/src/request/request.utils.ts +17 -16
- package/src/sdk/sdk.ts +79 -23
- package/src/types/http.types.ts +1 -1
- package/src/types/request.types.ts +3 -2
- package/src/utils/emitter.utils.ts +1 -1
- package/src/utils/uuid.utils.ts +1 -1
- package/tsconfig.json +30 -2
- package/vite.config.ts +14 -20
- package/.eslintrc.cjs +0 -12
- package/tsconfig.base.json +0 -7
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { createClient } from "client";
|
|
2
|
+
import type { ClientInstance, Client } from "client";
|
|
3
|
+
import type { HttpAdapterType } from "http-adapter";
|
|
4
|
+
import type { Request, RequestInstance, RequestModel } from "request";
|
|
5
|
+
import { createSdk } from "sdk";
|
|
6
|
+
import type { InjectClient } from "sdk";
|
|
7
|
+
import { describe, it, expect, expectTypeOf } from "vitest";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Type-only tests for the SDK type surface.
|
|
11
|
+
*
|
|
12
|
+
* These tests do not exercise runtime behaviour - they verify that the type system narrows,
|
|
13
|
+
* defaults, and propagates types as designed. Each `it` block contains a static
|
|
14
|
+
* `expectTypeOf` assertion plus a trivial runtime `expect(true).toBe(true)` placeholder so
|
|
15
|
+
* the test shows up in the Vitest report.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
type TestClient = Client<Error, HttpAdapterType>;
|
|
19
|
+
type CustomError = { code: string; message: string };
|
|
20
|
+
type User = { id: string; name: string };
|
|
21
|
+
|
|
22
|
+
describe("RequestModel - defaults for omitted fields", () => {
|
|
23
|
+
it("should default response to unknown", () => {
|
|
24
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
25
|
+
type Response = R extends Request<infer Resp, any, any, any, any, any, any, any, any, any> ? Resp : never;
|
|
26
|
+
expectTypeOf<Response>().toEqualTypeOf<unknown>();
|
|
27
|
+
expect(true).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should default payload to undefined", () => {
|
|
31
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
32
|
+
type Payload = R extends Request<any, infer P, any, any, any, any, any, any, any, any> ? P : never;
|
|
33
|
+
expectTypeOf<Payload>().toEqualTypeOf<undefined>();
|
|
34
|
+
expect(true).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should default queryParams to undefined", () => {
|
|
38
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
39
|
+
type Query = R extends Request<any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
40
|
+
expectTypeOf<Query>().toEqualTypeOf<undefined>();
|
|
41
|
+
expect(true).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should default localError to Error", () => {
|
|
45
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
46
|
+
type LocalError = R extends Request<any, any, any, infer E, any, any, any, any, any, any> ? E : never;
|
|
47
|
+
expectTypeOf<LocalError>().toEqualTypeOf<Error>();
|
|
48
|
+
expect(true).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should default endpoint to string when not provided", () => {
|
|
52
|
+
type R = RequestModel<{ response: User }>;
|
|
53
|
+
type Endpoint = R extends Request<any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
54
|
+
expectTypeOf<Endpoint>().toEqualTypeOf<string>();
|
|
55
|
+
expect(true).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should default client to ClientInstance when not provided", () => {
|
|
59
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
60
|
+
type ClientType = R extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
61
|
+
expectTypeOf<ClientType>().toEqualTypeOf<ClientInstance>();
|
|
62
|
+
expect(true).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should default hasPayload, hasParams, hasQueryParams to false", () => {
|
|
66
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
67
|
+
type HasPayload = R extends Request<any, any, any, any, any, any, infer Hp, any, any, any> ? Hp : never;
|
|
68
|
+
type HasParams = R extends Request<any, any, any, any, any, any, any, infer Hpa, any, any> ? Hpa : never;
|
|
69
|
+
type HasQuery = R extends Request<any, any, any, any, any, any, any, any, infer Hq, any> ? Hq : never;
|
|
70
|
+
expectTypeOf<HasPayload>().toEqualTypeOf<false>();
|
|
71
|
+
expectTypeOf<HasParams>().toEqualTypeOf<false>();
|
|
72
|
+
expectTypeOf<HasQuery>().toEqualTypeOf<false>();
|
|
73
|
+
expect(true).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should default mutationContext to undefined", () => {
|
|
77
|
+
type R = RequestModel<{ endpoint: "/users" }>;
|
|
78
|
+
type Ctx = R extends Request<any, any, any, any, any, any, any, any, any, infer C> ? C : never;
|
|
79
|
+
expectTypeOf<Ctx>().toEqualTypeOf<undefined>();
|
|
80
|
+
expect(true).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("RequestModel - user-provided fields override defaults", () => {
|
|
85
|
+
it("should narrow response when provided", () => {
|
|
86
|
+
type R = RequestModel<{ response: User; endpoint: "/users/:userId" }>;
|
|
87
|
+
type Response = R extends Request<infer Resp, any, any, any, any, any, any, any, any, any> ? Resp : never;
|
|
88
|
+
expectTypeOf<Response>().toEqualTypeOf<User>();
|
|
89
|
+
expect(true).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should narrow payload, queryParams, error when provided", () => {
|
|
93
|
+
type R = RequestModel<{
|
|
94
|
+
payload: { name: string };
|
|
95
|
+
queryParams: { page: number };
|
|
96
|
+
error: CustomError;
|
|
97
|
+
endpoint: "/users";
|
|
98
|
+
}>;
|
|
99
|
+
type Payload = R extends Request<any, infer P, any, any, any, any, any, any, any, any> ? P : never;
|
|
100
|
+
type Query = R extends Request<any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
101
|
+
type LocalError = R extends Request<any, any, any, infer E, any, any, any, any, any, any> ? E : never;
|
|
102
|
+
|
|
103
|
+
expectTypeOf<Payload>().toEqualTypeOf<{ name: string }>();
|
|
104
|
+
expectTypeOf<Query>().toEqualTypeOf<{ page: number }>();
|
|
105
|
+
expectTypeOf<LocalError>().toEqualTypeOf<CustomError>();
|
|
106
|
+
expect(true).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should narrow endpoint to its literal type", () => {
|
|
110
|
+
type R = RequestModel<{ response: User; endpoint: "/users/:userId" }>;
|
|
111
|
+
type Endpoint = R extends Request<any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
112
|
+
expectTypeOf<Endpoint>().toEqualTypeOf<"/users/:userId">();
|
|
113
|
+
expect(true).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("RequestInstance - keeps `any` defaults (regression check for constraint use)", () => {
|
|
118
|
+
it("should default every slot to any so any concrete Request is assignable", () => {
|
|
119
|
+
// RequestInstance with no args must remain wide so it acts as the "any Request" constraint
|
|
120
|
+
type RI = RequestInstance;
|
|
121
|
+
type Response = RI extends Request<infer R, any, any, any, any, any, any, any, any, any> ? R : never;
|
|
122
|
+
type Payload = RI extends Request<any, infer P, any, any, any, any, any, any, any, any> ? P : never;
|
|
123
|
+
type Query = RI extends Request<any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
124
|
+
|
|
125
|
+
expectTypeOf<Response>().toEqualTypeOf<any>();
|
|
126
|
+
expectTypeOf<Payload>().toEqualTypeOf<any>();
|
|
127
|
+
expectTypeOf<Query>().toEqualTypeOf<any>();
|
|
128
|
+
expect(true).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should accept a concrete RequestModel as a RequestInstance via constraint", () => {
|
|
132
|
+
type ConcreteRequest = RequestModel<{ response: User; endpoint: "/users" }>;
|
|
133
|
+
expectTypeOf<ConcreteRequest>().toMatchTypeOf<RequestInstance>();
|
|
134
|
+
expect(true).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("InjectClient - schema-level client injection", () => {
|
|
139
|
+
it("should replace the Client slot on a single Request leaf with the SDK client", () => {
|
|
140
|
+
type Schema = {
|
|
141
|
+
$get: RequestModel<{ response: User; endpoint: "/users" }>;
|
|
142
|
+
};
|
|
143
|
+
type Injected = InjectClient<Schema, TestClient>;
|
|
144
|
+
type ResolvedRequest = Injected["$get"];
|
|
145
|
+
type ResolvedClient =
|
|
146
|
+
ResolvedRequest extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
147
|
+
expectTypeOf<ResolvedClient>().toEqualTypeOf<TestClient>();
|
|
148
|
+
expect(true).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should walk nested schema objects and inject into every leaf", () => {
|
|
152
|
+
type Schema = {
|
|
153
|
+
users: {
|
|
154
|
+
$get: RequestModel<{ response: User[]; endpoint: "/users" }>;
|
|
155
|
+
$userId: {
|
|
156
|
+
$get: RequestModel<{ response: User; endpoint: "/users/:userId" }>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
type Injected = InjectClient<Schema, TestClient>;
|
|
161
|
+
|
|
162
|
+
type FlatRequest = Injected["users"]["$get"];
|
|
163
|
+
type NestedRequest = Injected["users"]["$userId"]["$get"];
|
|
164
|
+
|
|
165
|
+
type FlatClient = FlatRequest extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
166
|
+
type NestedClient = NestedRequest extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
167
|
+
|
|
168
|
+
expectTypeOf<FlatClient>().toEqualTypeOf<TestClient>();
|
|
169
|
+
expectTypeOf<NestedClient>().toEqualTypeOf<TestClient>();
|
|
170
|
+
expect(true).toBe(true);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should preserve response, endpoint and other fields after injection", () => {
|
|
174
|
+
type Schema = {
|
|
175
|
+
$get: RequestModel<{ response: User; endpoint: "/users/:userId" }>;
|
|
176
|
+
};
|
|
177
|
+
type Injected = InjectClient<Schema, TestClient>;
|
|
178
|
+
type R = Injected["$get"];
|
|
179
|
+
|
|
180
|
+
type Response = R extends Request<infer Resp, any, any, any, any, any, any, any, any, any> ? Resp : never;
|
|
181
|
+
type Endpoint = R extends Request<any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
182
|
+
|
|
183
|
+
expectTypeOf<Response>().toEqualTypeOf<User>();
|
|
184
|
+
expectTypeOf<Endpoint>().toEqualTypeOf<"/users/:userId">();
|
|
185
|
+
expect(true).toBe(true);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("should override an explicitly-passed client in the schema", () => {
|
|
189
|
+
// Edge case: schema declares client (e.g. a placeholder ClientInstance) - SDK still wins
|
|
190
|
+
type SchemaWithExplicitClient = {
|
|
191
|
+
$get: RequestModel<{ client: ClientInstance; response: User; endpoint: "/users" }>;
|
|
192
|
+
};
|
|
193
|
+
type Injected = InjectClient<SchemaWithExplicitClient, TestClient>;
|
|
194
|
+
type R = Injected["$get"];
|
|
195
|
+
type ResolvedClient = R extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
196
|
+
expectTypeOf<ResolvedClient>().toEqualTypeOf<TestClient>();
|
|
197
|
+
expect(true).toBe(true);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("createSdk - produces a fully resolved SDK type", () => {
|
|
202
|
+
type Schema = {
|
|
203
|
+
users: {
|
|
204
|
+
$get: RequestModel<{ response: User[]; endpoint: "/users" }>;
|
|
205
|
+
$userId: {
|
|
206
|
+
$get: RequestModel<{ response: User; endpoint: "/users/:userId" }>;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
it("should type sdk.users.$get with the SDK client injected", () => {
|
|
212
|
+
const client = createClient<{ error: Error }>({ url: "http://localhost" });
|
|
213
|
+
const sdk = createSdk<typeof client, Schema>(client);
|
|
214
|
+
|
|
215
|
+
type UsersGet = typeof sdk.users.$get;
|
|
216
|
+
type ResolvedClient = UsersGet extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
217
|
+
type ResolvedResponse = UsersGet extends Request<infer R, any, any, any, any, any, any, any, any, any> ? R : never;
|
|
218
|
+
type ResolvedEndpoint = UsersGet extends Request<any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
219
|
+
|
|
220
|
+
expectTypeOf<ResolvedClient>().toEqualTypeOf<typeof client>();
|
|
221
|
+
expectTypeOf<ResolvedResponse>().toEqualTypeOf<User[]>();
|
|
222
|
+
expectTypeOf<ResolvedEndpoint>().toEqualTypeOf<"/users">();
|
|
223
|
+
expect(true).toBe(true);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("should type nested sdk.users.$userId.$get with the SDK client injected", () => {
|
|
227
|
+
const client = createClient<{ error: Error }>({ url: "http://localhost" });
|
|
228
|
+
const sdk = createSdk<typeof client, Schema>(client);
|
|
229
|
+
|
|
230
|
+
type NestedGet = typeof sdk.users.$userId.$get;
|
|
231
|
+
type ResolvedClient = NestedGet extends Request<any, any, any, any, any, infer C, any, any, any, any> ? C : never;
|
|
232
|
+
type ResolvedResponse = NestedGet extends Request<infer R, any, any, any, any, any, any, any, any, any> ? R : never;
|
|
233
|
+
|
|
234
|
+
expectTypeOf<ResolvedClient>().toEqualTypeOf<typeof client>();
|
|
235
|
+
expectTypeOf<ResolvedResponse>().toEqualTypeOf<User>();
|
|
236
|
+
expect(true).toBe(true);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("should expose $configure on the SDK type", () => {
|
|
240
|
+
const client = createClient<{ error: Error }>({ url: "http://localhost" });
|
|
241
|
+
const sdk = createSdk<typeof client, Schema>(client);
|
|
242
|
+
|
|
243
|
+
expectTypeOf(sdk.$configure).toBeFunction();
|
|
244
|
+
expect(true).toBe(true);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe("$configure - dot-path callback narrowing", () => {
|
|
249
|
+
type Schema = {
|
|
250
|
+
users: {
|
|
251
|
+
$get: RequestModel<{ response: User[]; endpoint: "/users" }>;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
it("should accept a function value matching the SDK request type for a dot-path key", () => {
|
|
256
|
+
const client = createClient<{ error: Error }>({ url: "http://localhost" });
|
|
257
|
+
const sdk = createSdk<typeof client, Schema>(client);
|
|
258
|
+
|
|
259
|
+
// The configure call must accept a function whose parameter is assignable from any Request.
|
|
260
|
+
// Stronger narrowing happens at the configuration value level via SocketSdkConfigurationMap.
|
|
261
|
+
sdk.$configure({
|
|
262
|
+
"users.$get": (request) => {
|
|
263
|
+
expectTypeOf(request).toMatchTypeOf<RequestInstance>();
|
|
264
|
+
return request;
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(true).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("should accept a plain-object value for an endpoint group key", () => {
|
|
272
|
+
const client = createClient<{ error: Error }>({ url: "http://localhost" });
|
|
273
|
+
const sdk = createSdk<typeof client, Schema>(client);
|
|
274
|
+
|
|
275
|
+
// Compile-time only: just verify the call typechecks.
|
|
276
|
+
sdk.$configure({
|
|
277
|
+
"*": { retry: 3 },
|
|
278
|
+
"/users": { cache: true, cacheTime: 30_000 },
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
expect(true).toBe(true);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Mock } from "vitest";
|
|
2
2
|
|
|
3
|
-
export const testCallbacksExecution = (callbacks:
|
|
3
|
+
export const testCallbacksExecution = (callbacks: Mock[]) => {
|
|
4
4
|
callbacks.forEach((spyFn, index) => {
|
|
5
5
|
const nextSpy = callbacks[index + 1];
|
|
6
6
|
if (nextSpy) {
|
package/__tests__/tsconfig.json
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "../tsconfig.json",
|
|
2
3
|
"compilerOptions": {
|
|
3
|
-
"target": "esnext",
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["dom", "dom.iterable", "ESNext"],
|
|
7
|
-
"strict": true,
|
|
8
|
-
"strictPropertyInitialization": false,
|
|
9
4
|
"noEmit": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"isolatedModules": true,
|
|
15
5
|
"noUnusedLocals": false,
|
|
16
6
|
"noUnusedParameters": false,
|
|
17
|
-
"types": ["vitest/globals", "jest-extended", "@types/node"]
|
|
18
|
-
"baseUrl": "../src",
|
|
19
|
-
"paths": {
|
|
20
|
-
"@hyper-fetch/core": ["../src"]
|
|
21
|
-
}
|
|
7
|
+
"types": ["vitest/globals", "jest-extended", "@types/node"]
|
|
22
8
|
},
|
|
23
|
-
"include": ["**/*.ts", "**/*.tsx", "../../../global.d.ts", "../../../vitest.d.ts"]
|
|
9
|
+
"include": ["**/*.ts", "**/*.tsx", "../../../global.d.ts", "../../../vitest.d.ts"],
|
|
10
|
+
"exclude": ["node_modules"]
|
|
24
11
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { sleep } from "@hyper-fetch/testing";
|
|
2
|
-
|
|
3
|
-
import type { RequestInstance } from "request";
|
|
4
2
|
import { Adapter } from "adapter";
|
|
5
3
|
import type { HttpAdapterType } from "http-adapter";
|
|
6
4
|
import { HttpAdapter } from "http-adapter";
|
|
7
5
|
import { LoggerManager } from "managers";
|
|
6
|
+
import type { RequestInstance } from "request";
|
|
8
7
|
|
|
9
8
|
export const createAdapter = (props?: {
|
|
10
9
|
sleepTime?: number;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { sleep } from "@hyper-fetch/testing";
|
|
2
|
-
|
|
3
2
|
import type { ResponseType } from "adapter";
|
|
4
|
-
import type { RequestInstance } from "request";
|
|
5
3
|
import type { ClientInstance, ResponseInterceptorType } from "client";
|
|
6
4
|
import type { HttpAdapterType } from "http-adapter";
|
|
7
5
|
import { xhrExtra } from "http-adapter";
|
|
6
|
+
import type { RequestInstance } from "request";
|
|
8
7
|
|
|
9
8
|
export const interceptorCallback = (props?: {
|
|
10
9
|
sleepTime?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ClientInstance } from "client";
|
|
1
2
|
import type { DispatcherOptionsType } from "dispatcher";
|
|
2
3
|
import { Dispatcher } from "dispatcher";
|
|
3
|
-
import type { ClientInstance } from "client";
|
|
4
4
|
|
|
5
5
|
export const createDispatcher = (client: ClientInstance, options?: DispatcherOptionsType) => {
|
|
6
6
|
return new Dispatcher(options).initialize(client);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="vitest/globals" />
|
|
2
2
|
import { AbortController } from "abortcontroller-polyfill/dist/cjs-ponyfill";
|
|
3
|
-
import { BroadcastChannel } from "node:worker_threads";
|
|
4
3
|
import * as matchers from "jest-extended";
|
|
4
|
+
import { BroadcastChannel } from "node:worker_threads";
|
|
5
5
|
import { expect } from "vitest";
|
|
6
6
|
|
|
7
7
|
expect.extend(matchers);
|
|
@@ -1,11 +1,16 @@
|
|
|
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
1
|
import { Client, ClientInstance } from '../client';
|
|
5
2
|
import { LoggerMethods } from '../managers';
|
|
3
|
+
import { RequestInstance, RequestOptionsType } from '../request';
|
|
4
|
+
import { EmptyTypes, ExtendRequest } from '../types';
|
|
5
|
+
import { EndpointMapper, AdapterFetcherType, AdapterPayloadMappingType, HeaderMappingType, QueryParamsMapper, QueryParamsType, RequestResponseType } from './adapter.types';
|
|
6
6
|
import { getErrorMessage } from './adapter.utils';
|
|
7
|
-
export type DefaultMapperType = <V, C>(value: V, config
|
|
7
|
+
export type DefaultMapperType = <V, C = undefined>(value: V, config?: C) => V;
|
|
8
8
|
export declare const defaultMapper: DefaultMapperType;
|
|
9
|
+
/**
|
|
10
|
+
* Base adapter class responsible for executing HTTP requests. Adapters handle endpoint resolution,
|
|
11
|
+
* header/payload/query-params mapping, and the actual fetch call. Extend or configure this class
|
|
12
|
+
* to integrate custom transport layers (e.g., axios, graphql, firebase).
|
|
13
|
+
*/
|
|
9
14
|
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
15
|
options: {
|
|
11
16
|
name: string;
|
|
@@ -46,7 +51,9 @@ export declare class Adapter<AdapterOptions, MethodType extends string, StatusTy
|
|
|
46
51
|
systemErrorExtra: Extra;
|
|
47
52
|
defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
|
|
48
53
|
});
|
|
54
|
+
/** Initialize the adapter with a client reference and set up logging. Called automatically when the client is created. */
|
|
49
55
|
initialize: (client: ClientInstance) => this;
|
|
56
|
+
/** Register a callback invoked once the adapter is initialized with a client. */
|
|
50
57
|
onInitialize: (callback: (options: {
|
|
51
58
|
client: ClientInstance;
|
|
52
59
|
}) => void) => this;
|
|
@@ -80,8 +87,11 @@ export declare class Adapter<AdapterOptions, MethodType extends string, StatusTy
|
|
|
80
87
|
* Methods
|
|
81
88
|
* ********************
|
|
82
89
|
*/
|
|
90
|
+
/** Set the default HTTP method used when a request does not specify one. */
|
|
83
91
|
setDefaultMethod: (method: MethodType) => this;
|
|
92
|
+
/** Set the default extra metadata attached to every request response (e.g., headers, status). */
|
|
84
93
|
setDefaultExtra: (extra: Extra) => this;
|
|
94
|
+
/** Set a function that formats the endpoint string for display in devtools. */
|
|
85
95
|
setDevtoolsEndpointGetter: (callback: (endpoint: string) => string) => this;
|
|
86
96
|
/**
|
|
87
97
|
* This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
|
|
@@ -93,6 +103,7 @@ export declare class Adapter<AdapterOptions, MethodType extends string, StatusTy
|
|
|
93
103
|
setAdapterDefaults: (callback: (request: ExtendRequest<RequestInstance, {
|
|
94
104
|
client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
|
|
95
105
|
}>) => AdapterOptions) => this;
|
|
106
|
+
/** Set a custom mapping for internal adapter errors before they are returned in the response. */
|
|
96
107
|
setInternalErrorMapping: (callback: (error: ReturnType<typeof getErrorMessage>) => any) => this;
|
|
97
108
|
/**
|
|
98
109
|
* Set the custom header mapping function
|
|
@@ -103,23 +114,29 @@ export declare class Adapter<AdapterOptions, MethodType extends string, StatusTy
|
|
|
103
114
|
*/
|
|
104
115
|
setPayloadMapper: <NewMapper extends AdapterPayloadMappingType>(payloadMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>;
|
|
105
116
|
/**
|
|
106
|
-
* Set the
|
|
117
|
+
* Set the endpoint mapping function which transforms the endpoint string before the request is sent
|
|
107
118
|
*/
|
|
108
119
|
setEndpointMapper: <NewEndpointMapper extends EndpointMapper<EndpointType>>(endpointMapper: NewEndpointMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
|
|
109
120
|
/**
|
|
110
121
|
* Set the query params mapping function which get triggered before request get sent
|
|
111
122
|
*/
|
|
112
123
|
setQueryParamsMapper: <NewQueryParamsMapper extends QueryParamsMapper<QueryParams>>(queryParamsMapper: NewQueryParamsMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>;
|
|
124
|
+
/** Set the configuration object passed as the second argument to the query params mapper. */
|
|
113
125
|
setQueryParamsMapperConfig: <NewQueryParamsMapperConfig extends Parameters<QueryParamsMapperType>[1]>(config: NewQueryParamsMapperConfig) => this;
|
|
126
|
+
/** Set the configuration object passed as the second argument to the header mapper. */
|
|
114
127
|
setHeaderMapperConfig: <NewHeaderMapperConfig extends Parameters<HeaderMapperType>[1]>(config: NewHeaderMapperConfig) => this;
|
|
128
|
+
/** Set the configuration object passed as the second argument to the endpoint mapper. */
|
|
115
129
|
setEndpointMapperConfig: <NewEndpointMapperConfig extends Parameters<EndpointMapperType>[1]>(config: NewEndpointMapperConfig) => this;
|
|
130
|
+
/** Set the configuration object passed as the second argument to the payload mapper. */
|
|
116
131
|
setPayloadMapperConfig: <NewPayloadMapperConfig extends Parameters<PayloadMapperType>[1]>(config: NewPayloadMapperConfig) => this;
|
|
117
132
|
/**
|
|
118
133
|
* ********************
|
|
119
134
|
* Fetching
|
|
120
135
|
* ********************
|
|
121
136
|
*/
|
|
137
|
+
/** Set the fetcher function that performs the actual network request. Must be called before any request can be executed. */
|
|
122
138
|
setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>): this;
|
|
139
|
+
/** Execute a request through the adapter pipeline: maps endpoint/headers/payload, runs plugins, then calls the fetcher. */
|
|
123
140
|
fetch(request: ExtendRequest<RequestInstance, {
|
|
124
141
|
client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
|
|
125
142
|
}>, requestId: string): Promise<RequestResponseType<RequestInstance>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGvD,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,MAAM,iBAAiB,CAAC;AAGvD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,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QAAQ,0BAA0B,UAIlC;IAEF,uFAAuF;IACvF,qBAAqB,GAAI,qBAAqB,SAAS,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EACpF,QAAQ,qBAAqB,UAI7B;IAEF,yFAAyF;IACzF,uBAAuB,GAAI,uBAAuB,SAAS,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC1F,QAAQ,uBAAuB,UAI/B;IAEF,wFAAwF;IACxF,sBAAsB,GAAI,sBAAsB,SAAS,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EACvF,QAAQ,sBAAsB,UAI9B;IAEF;;;;OAIG;IAEH,4HAA4H;IACrH,UAAU,CACf,OAAO,EAAE,kBAAkB,CACzB,OAAO,CACL,cAAc,EACd,UAAU,EACV,UAAU,EACV,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,CAClB,CACF;IAMH,2HAA2H;IAC9G,KAAK,CAChB,OAAO,EAAE,aAAa,CACpB,eAAe,EACf;QAEE,MAAM,EAAE,MAAM,CACZ,GAAG,EACH,OAAO,CACL,cAAc,EACd,UAAU,EACV,UAAU,EACV,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,CAClB,CACF,CAAC;KACH,CACF,EACD,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;CAqFjD"}
|
|
@@ -44,7 +44,7 @@ export type DefaultPayloadMapper = (options: {
|
|
|
44
44
|
payload: unknown;
|
|
45
45
|
}) => string;
|
|
46
46
|
export type QueryParamValuesType = number | string | boolean | null | undefined | Record<any, any>;
|
|
47
|
-
export type QueryParamType = QueryParamValuesType |
|
|
47
|
+
export type QueryParamType = QueryParamValuesType | QueryParamValuesType[] | Record<string, QueryParamValuesType>;
|
|
48
48
|
export type QueryParamsType = Record<string, QueryParamType>;
|
|
49
49
|
type RequestAdapterStatus<Req extends RequestInstance> = ExtractAdapterStatusType<ExtractAdapterType<Req>>;
|
|
50
50
|
type RequestAdapterExtra<Req extends RequestInstance> = ExtractAdapterExtraType<ExtractAdapterType<Req>>;
|
|
@@ -57,13 +57,21 @@ export type RequestResponseType<Request extends RequestInstance> = {
|
|
|
57
57
|
responseTimestamp: number;
|
|
58
58
|
requestTimestamp: number;
|
|
59
59
|
};
|
|
60
|
+
/** The normalized response shape returned by every adapter after a request completes. */
|
|
60
61
|
export type ResponseType<GenericDataType, GenericErrorType, Adapter extends AdapterInstance> = {
|
|
62
|
+
/** Response data when successful, null on error */
|
|
61
63
|
data: GenericDataType | null;
|
|
64
|
+
/** Error payload when the request fails, null on success */
|
|
62
65
|
error: GenericErrorType | null;
|
|
66
|
+
/** HTTP status code or adapter-specific status indicator */
|
|
63
67
|
status: ExtractAdapterStatusType<Adapter> | null;
|
|
68
|
+
/** Whether the request completed successfully */
|
|
64
69
|
success: true | false;
|
|
70
|
+
/** Adapter-specific metadata (e.g., response headers) */
|
|
65
71
|
extra: ExtractAdapterExtraType<Adapter> | null;
|
|
72
|
+
/** Timestamp (ms) when the response was received */
|
|
66
73
|
responseTimestamp: number;
|
|
74
|
+
/** Timestamp (ms) when the request was sent */
|
|
67
75
|
requestTimestamp: number;
|
|
68
76
|
};
|
|
69
77
|
export type ResponseSuccessType<GenericDataType, Adapter extends AdapterInstance> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.types.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.types.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC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AC1B,CAAC;AAIF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0BAA0B;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2BAA2B;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.utils.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,qBAAa,YAAa,SAAQ,KAAK;;CAKtC;AAED,qBAAa,UAAW,SAAQ,KAAK;;CAKpC;AAED,qBAAa,YAAa,SAAQ,KAAK;;CAKtC;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,WAAW,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"adapter.utils.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,qBAAa,YAAa,SAAQ,KAAK;;CAKtC;AAED,qBAAa,UAAW,SAAQ,KAAK;;CAKpC;AAED,qBAAa,YAAa,SAAQ,KAAK;;CAKtC;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAa;gBAErB,WAAW,CAAC,EAAE,MAAM;CAKjC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,WAAW,CAAC,EAAE,MAAM,CAAa;gBAErB,WAAW,CAAC,EAAE,MAAM;CAKjC;AAED,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,YAAY,wFAcxG,CAAC;AAIF,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,GAAG,OAAO,KAAG,MAM3D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,SAAS,eAAe,KAQtC,WACnB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,MAAM,OAAO,KAAG,MAAM,GAAG,QAK1D,CAAC"}
|
package/dist/cache/cache.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AdapterInstance, ResponseType } from '../adapter';
|
|
2
|
-
import { ResponseDetailsType } from '../managers';
|
|
3
|
-
import { ClientInstance } from '../client';
|
|
4
2
|
import { CacheOptionsType, CacheAsyncStorageType, CacheStorageType, CacheValueType, CacheSetState, RequestCacheType, getCacheEvents } from '.';
|
|
3
|
+
import { ClientInstance } from '../client';
|
|
4
|
+
import { ResponseDetailsType } from '../managers';
|
|
5
5
|
import { RequestInstance } from '../request';
|
|
6
6
|
import { ExtractAdapterType, ExtractErrorType, ExtractResponseType } from '../types';
|
|
7
7
|
import { EventEmitter } from '../utils';
|
|
@@ -23,6 +23,7 @@ export declare class Cache<Adapter extends AdapterInstance> {
|
|
|
23
23
|
private logger;
|
|
24
24
|
private client;
|
|
25
25
|
constructor(options?: CacheOptionsType | undefined);
|
|
26
|
+
/** Initialize the cache with a client reference, set up logging, and start garbage collection. */
|
|
26
27
|
initialize: (client: ClientInstance<{
|
|
27
28
|
adapter: Adapter;
|
|
28
29
|
}>) => this;
|
|
@@ -39,8 +40,6 @@ export declare class Cache<Adapter extends AdapterInstance> {
|
|
|
39
40
|
* Update the cache data with partial response data
|
|
40
41
|
* @param request
|
|
41
42
|
* @param partialResponse
|
|
42
|
-
* @param isTriggeredExtrenally - informs whether an update was triggered due to internal logic or externally, e.g.
|
|
43
|
-
* via plugin.
|
|
44
43
|
* @returns
|
|
45
44
|
*/
|
|
46
45
|
update: <Request extends RequestCacheType<RequestInstance>>(request: Request, partialResponse: CacheSetState<Partial<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>> & ResponseDetailsType>>) => void;
|
|
@@ -65,20 +64,18 @@ export declare class Cache<Adapter extends AdapterInstance> {
|
|
|
65
64
|
* It emits invalidation event for each matching cacheKey and sets staleTime to 0 to indicate out of time cache
|
|
66
65
|
* @param key - cacheKey or Request instance or RegExp for partial matching
|
|
67
66
|
*/
|
|
68
|
-
invalidate: (cacheKeys: string | RegExp | RequestInstance |
|
|
67
|
+
invalidate: (cacheKeys: string | RegExp | RequestInstance | (string | RegExp | RequestInstance)[]) => void;
|
|
69
68
|
/**
|
|
70
69
|
* Used to receive data from lazy storage
|
|
71
70
|
* @param cacheKey
|
|
72
71
|
*/
|
|
73
72
|
getLazyResource: <Response, Error>(cacheKey: string) => Promise<CacheValueType<Response, Error, Adapter> | undefined>;
|
|
74
73
|
/**
|
|
75
|
-
* Used to receive keys from
|
|
76
|
-
* @param cacheKey
|
|
74
|
+
* Used to receive keys from lazy storage only
|
|
77
75
|
*/
|
|
78
76
|
getLazyKeys: () => Promise<string[]>;
|
|
79
77
|
/**
|
|
80
|
-
* Used to receive keys from sync storage and lazy storage
|
|
81
|
-
* @param cacheKey
|
|
78
|
+
* Used to receive deduplicated keys from both sync storage and lazy storage
|
|
82
79
|
*/
|
|
83
80
|
getAllKeys: () => Promise<string[]>;
|
|
84
81
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":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