@hyper-fetch/core 8.0.1 → 8.1.1
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/__tests__/features/dispatcher/dispatcher.requests.spec.ts +1 -1
- package/__tests__/features/sdk/sdk.configuration.spec.ts +203 -0
- package/dist/index.mjs +62 -20
- package/dist/index.mjs.map +1 -1
- package/dist/sdk/sdk.d.ts +23 -7
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sdk/sdk.ts +104 -33
package/dist/sdk/sdk.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export type SdkRequestDefaults = {
|
|
|
21
21
|
deduplicate?: boolean;
|
|
22
22
|
deduplicateTime?: number | null;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Configuration value: either a static property bag or a function that receives
|
|
26
|
+
* the request and returns a modified request (full access to every Request setter).
|
|
27
|
+
*/
|
|
28
|
+
export type SdkConfigurationValue = SdkRequestDefaults | ((request: RequestInstance) => RequestInstance);
|
|
24
29
|
/**
|
|
25
30
|
* Recursively extracts all endpoint strings from an SDK schema type.
|
|
26
31
|
* Leaf nodes (keys starting with $) are RequestInstance — extract endpoint from those.
|
|
@@ -29,19 +34,30 @@ export type SdkRequestDefaults = {
|
|
|
29
34
|
type ExtractSdkEndpoints<T, Depth extends unknown[] = []> = Depth["length"] extends 10 ? never : {
|
|
30
35
|
[K in keyof T]: K extends `$${string}` ? T[K] extends RequestInstance ? ExtractEndpointType<T[K]> : never : T[K] extends Record<string, any> ? ExtractSdkEndpoints<T[K], [...Depth, unknown]> : never;
|
|
31
36
|
}[keyof T];
|
|
37
|
+
/**
|
|
38
|
+
* Recursively extracts dot-path accessor keys from an SDK schema.
|
|
39
|
+
* These mirror the SDK property chain: "users.$get", "users.$userId.$get", etc.
|
|
40
|
+
*/
|
|
41
|
+
type ExtractSdkPaths<T, Prefix extends string = "", Depth extends unknown[] = []> = Depth["length"] extends 10 ? never : {
|
|
42
|
+
[K in keyof T & string]: T[K] extends RequestInstance ? `${Prefix}${K}` : T[K] extends Record<string, any> ? ExtractSdkPaths<T[K], `${Prefix}${K}.`, [...Depth, unknown]> : never;
|
|
43
|
+
}[keyof T & string];
|
|
32
44
|
/**
|
|
33
45
|
* Builds the set of valid configuration keys from an SDK schema:
|
|
34
46
|
* - "*" (global wildcard)
|
|
35
|
-
* - exact endpoint paths extracted from RequestInstance nodes
|
|
36
|
-
* - wildcard patterns like "/users/*"
|
|
47
|
+
* - exact endpoint paths extracted from RequestInstance nodes (group keys)
|
|
48
|
+
* - wildcard patterns like "/users/*" (group keys)
|
|
49
|
+
* - dot-path accessor keys like "users.$get" (method-specific keys)
|
|
37
50
|
*/
|
|
38
|
-
type SdkConfigurationKeys<Schema extends RecursiveSchemaType> = "*" | ExtractSdkEndpoints<Schema> | `${ExtractSdkEndpoints<Schema> & string}
|
|
51
|
+
type SdkConfigurationKeys<Schema extends RecursiveSchemaType> = "*" | ExtractSdkEndpoints<Schema> | `${ExtractSdkEndpoints<Schema> & string}/*` | ExtractSdkPaths<Schema>;
|
|
39
52
|
/**
|
|
40
|
-
* Maps endpoint paths
|
|
41
|
-
* Keys are validated against the SDK schema
|
|
42
|
-
*
|
|
53
|
+
* Maps endpoint paths, wildcard patterns, or dot-path accessor keys to request defaults.
|
|
54
|
+
* Keys are validated against the SDK schema.
|
|
55
|
+
*
|
|
56
|
+
* Values can be:
|
|
57
|
+
* - A plain `SdkRequestDefaults` object (shorthand for common settings)
|
|
58
|
+
* - A function `(request) => request` for full access to every Request setter
|
|
43
59
|
*/
|
|
44
|
-
export type SdkConfigurationMap<Schema extends RecursiveSchemaType = RecursiveSchemaType> = Partial<Record<SdkConfigurationKeys<Schema>,
|
|
60
|
+
export type SdkConfigurationMap<Schema extends RecursiveSchemaType = RecursiveSchemaType> = Partial<Record<SdkConfigurationKeys<Schema>, SdkConfigurationValue>>;
|
|
45
61
|
export type CreateSdkOptions<Schema extends RecursiveSchemaType = RecursiveSchemaType> = {
|
|
46
62
|
/** @default true */
|
|
47
63
|
camelCaseToKebabCase?: boolean;
|
package/dist/sdk/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CACtC,MAAM,EAAE,gDAAgD;AACxD,GAAG,CACJ,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,KAAK,mBAAmB,CAAC,CAAC,EAAE,KAAK,SAAS,OAAO,EAAE,GAAG,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,EAAE,GAClF,KAAK,GACL;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM,EAAE,GAClC,CAAC,CAAC,CAAC,CAAC,SAAS,eAAe,GAC1B,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C,MAAM,CAAC,GAAG,MAAM,IAAI,GAC3C,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,IAAI,OAAO,CACjG,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,qBAAqB,CAAC,CAC5D,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,IAAI;IACvF,oBAAoB;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gDAAgD;IAChD,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,oCAAoC;IACpC,QAAQ,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAmJF,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,mBAAmB,IAAI,MAAM,GAAG;IACrE;;;OAGG;IACH,UAAU,EAAE,CAAC,QAAQ,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5E,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,MAAM,SAAS,cAAc,EAAE,eAAe,SAAS,mBAAmB,EAClG,QAAQ,MAAM,EACd,UAAU,gBAAgB,CAAC,eAAe,CAAC,KAC1C,WAAW,CAAC,eAAe,CAyB7B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,SAAS,mBAAmB,QAC5D,UAAU,mBAAmB,CAAC,MAAM,CAAC,KAAG,mBAAmB,CAAC,MAAM,CAC3E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"description": "Cache, Queue and Persist your requests no matter if you are online or offline!",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -26,6 +26,12 @@ export type SdkRequestDefaults = {
|
|
|
26
26
|
deduplicateTime?: number | null;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Configuration value: either a static property bag or a function that receives
|
|
31
|
+
* the request and returns a modified request (full access to every Request setter).
|
|
32
|
+
*/
|
|
33
|
+
export type SdkConfigurationValue = SdkRequestDefaults | ((request: RequestInstance) => RequestInstance);
|
|
34
|
+
|
|
29
35
|
/**
|
|
30
36
|
* Recursively extracts all endpoint strings from an SDK schema type.
|
|
31
37
|
* Leaf nodes (keys starting with $) are RequestInstance — extract endpoint from those.
|
|
@@ -43,24 +49,43 @@ type ExtractSdkEndpoints<T, Depth extends unknown[] = []> = Depth["length"] exte
|
|
|
43
49
|
: never;
|
|
44
50
|
}[keyof T];
|
|
45
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Recursively extracts dot-path accessor keys from an SDK schema.
|
|
54
|
+
* These mirror the SDK property chain: "users.$get", "users.$userId.$get", etc.
|
|
55
|
+
*/
|
|
56
|
+
type ExtractSdkPaths<T, Prefix extends string = "", Depth extends unknown[] = []> = Depth["length"] extends 10
|
|
57
|
+
? never
|
|
58
|
+
: {
|
|
59
|
+
[K in keyof T & string]: T[K] extends RequestInstance
|
|
60
|
+
? `${Prefix}${K}`
|
|
61
|
+
: T[K] extends Record<string, any>
|
|
62
|
+
? ExtractSdkPaths<T[K], `${Prefix}${K}.`, [...Depth, unknown]>
|
|
63
|
+
: never;
|
|
64
|
+
}[keyof T & string];
|
|
65
|
+
|
|
46
66
|
/**
|
|
47
67
|
* Builds the set of valid configuration keys from an SDK schema:
|
|
48
68
|
* - "*" (global wildcard)
|
|
49
|
-
* - exact endpoint paths extracted from RequestInstance nodes
|
|
50
|
-
* - wildcard patterns like "/users/*"
|
|
69
|
+
* - exact endpoint paths extracted from RequestInstance nodes (group keys)
|
|
70
|
+
* - wildcard patterns like "/users/*" (group keys)
|
|
71
|
+
* - dot-path accessor keys like "users.$get" (method-specific keys)
|
|
51
72
|
*/
|
|
52
73
|
type SdkConfigurationKeys<Schema extends RecursiveSchemaType> =
|
|
53
74
|
| "*"
|
|
54
75
|
| ExtractSdkEndpoints<Schema>
|
|
55
|
-
| `${ExtractSdkEndpoints<Schema> & string}
|
|
76
|
+
| `${ExtractSdkEndpoints<Schema> & string}/*`
|
|
77
|
+
| ExtractSdkPaths<Schema>;
|
|
56
78
|
|
|
57
79
|
/**
|
|
58
|
-
* Maps endpoint paths
|
|
59
|
-
* Keys are validated against the SDK schema
|
|
60
|
-
*
|
|
80
|
+
* Maps endpoint paths, wildcard patterns, or dot-path accessor keys to request defaults.
|
|
81
|
+
* Keys are validated against the SDK schema.
|
|
82
|
+
*
|
|
83
|
+
* Values can be:
|
|
84
|
+
* - A plain `SdkRequestDefaults` object (shorthand for common settings)
|
|
85
|
+
* - A function `(request) => request` for full access to every Request setter
|
|
61
86
|
*/
|
|
62
87
|
export type SdkConfigurationMap<Schema extends RecursiveSchemaType = RecursiveSchemaType> = Partial<
|
|
63
|
-
Record<SdkConfigurationKeys<Schema>,
|
|
88
|
+
Record<SdkConfigurationKeys<Schema>, SdkConfigurationValue>
|
|
64
89
|
>;
|
|
65
90
|
|
|
66
91
|
export type CreateSdkOptions<Schema extends RecursiveSchemaType = RecursiveSchemaType> = {
|
|
@@ -88,32 +113,74 @@ const endpointMatchesPattern = (endpoint: string, pattern: string): boolean => {
|
|
|
88
113
|
return false;
|
|
89
114
|
};
|
|
90
115
|
|
|
116
|
+
const isDotPath = (key: string): boolean => {
|
|
117
|
+
return key.includes(".") && !key.startsWith("/");
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const applyObjectDefaults = (request: RequestInstance, config: SdkRequestDefaults): RequestInstance => {
|
|
121
|
+
let result = request;
|
|
122
|
+
if (config.headers) result = result.setHeaders(config.headers);
|
|
123
|
+
if (config.auth !== undefined) result = result.setAuth(config.auth);
|
|
124
|
+
if (config.cache !== undefined) result = result.setCache(config.cache);
|
|
125
|
+
if (config.cacheTime !== undefined) result = result.setCacheTime(config.cacheTime);
|
|
126
|
+
if (config.staleTime !== undefined) result = result.setStaleTime(config.staleTime);
|
|
127
|
+
if (config.retry !== undefined) result = result.setRetry(config.retry);
|
|
128
|
+
if (config.retryTime !== undefined) result = result.setRetryTime(config.retryTime);
|
|
129
|
+
if (config.cancelable !== undefined) result = result.setCancelable(config.cancelable);
|
|
130
|
+
if (config.queued !== undefined) result = result.setQueued(config.queued);
|
|
131
|
+
if (config.offline !== undefined) result = result.setOffline(config.offline);
|
|
132
|
+
if (config.deduplicate !== undefined) result = result.setDeduplicate(config.deduplicate);
|
|
133
|
+
if (config.deduplicateTime !== undefined && config.deduplicateTime !== null) {
|
|
134
|
+
result = result.setDeduplicateTime(config.deduplicateTime);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
|
|
91
139
|
const applyDefaults = (
|
|
92
140
|
request: RequestInstance,
|
|
93
|
-
endpoint: string,
|
|
94
|
-
defaults?: Record<string, SdkRequestDefaults>,
|
|
141
|
+
context: { endpoint: string; sdkPath: string; defaults?: Partial<Record<string, SdkConfigurationValue>> },
|
|
95
142
|
): RequestInstance => {
|
|
143
|
+
const { endpoint, sdkPath, defaults } = context;
|
|
96
144
|
if (!defaults) return request;
|
|
97
145
|
|
|
98
146
|
let result = request;
|
|
99
147
|
const entries = Object.entries(defaults);
|
|
100
148
|
|
|
149
|
+
// Sort: "*" first, then endpoint groups (start with "/"), then dot-path (method-specific) last
|
|
150
|
+
const globalEntries: [string, SdkConfigurationValue][] = [];
|
|
151
|
+
const groupEntries: [string, SdkConfigurationValue][] = [];
|
|
152
|
+
const pathEntries: [string, SdkConfigurationValue][] = [];
|
|
153
|
+
|
|
101
154
|
for (let i = 0; i < entries.length; i += 1) {
|
|
102
|
-
const [
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
155
|
+
const [key, value] = entries[i];
|
|
156
|
+
if (!value) continue;
|
|
157
|
+
const entry: [string, SdkConfigurationValue] = [key, value];
|
|
158
|
+
if (entry[0] === "*") {
|
|
159
|
+
globalEntries.push(entry);
|
|
160
|
+
} else if (isDotPath(entry[0])) {
|
|
161
|
+
pathEntries.push(entry);
|
|
162
|
+
} else {
|
|
163
|
+
groupEntries.push(entry);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const sorted = [...globalEntries, ...groupEntries, ...pathEntries];
|
|
168
|
+
|
|
169
|
+
for (let i = 0; i < sorted.length; i += 1) {
|
|
170
|
+
const [pattern, config] = sorted[i];
|
|
171
|
+
|
|
172
|
+
let matches = false;
|
|
173
|
+
if (isDotPath(pattern)) {
|
|
174
|
+
matches = pattern === sdkPath;
|
|
175
|
+
} else {
|
|
176
|
+
matches = endpointMatchesPattern(endpoint, pattern);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (matches) {
|
|
180
|
+
if (typeof config === "function") {
|
|
181
|
+
result = config(result);
|
|
182
|
+
} else {
|
|
183
|
+
result = applyObjectDefaults(result, config);
|
|
117
184
|
}
|
|
118
185
|
}
|
|
119
186
|
}
|
|
@@ -121,7 +188,11 @@ const applyDefaults = (
|
|
|
121
188
|
return result;
|
|
122
189
|
};
|
|
123
190
|
|
|
124
|
-
const createRecursiveProxy = (
|
|
191
|
+
const createRecursiveProxy = (
|
|
192
|
+
client: ClientInstance,
|
|
193
|
+
context: { path: string[]; sdkKeys: string[]; options?: CreateSdkOptions<any> },
|
|
194
|
+
): any => {
|
|
195
|
+
const { path, sdkKeys, options } = context;
|
|
125
196
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
126
197
|
return new Proxy(() => {}, {
|
|
127
198
|
get: (_target, key: string) => {
|
|
@@ -135,26 +206,26 @@ const createRecursiveProxy = (client: ClientInstance, path: string[], options?:
|
|
|
135
206
|
let pathSegment = key;
|
|
136
207
|
|
|
137
208
|
if (key.startsWith("$")) {
|
|
138
|
-
// This could be either a method or a parameter
|
|
139
|
-
// Try to determine by checking if it's a terminal access (method)
|
|
140
|
-
// For now, assume it's a method and strip the $ prefix
|
|
141
209
|
isMethod = true;
|
|
142
210
|
methodName = key.slice(1);
|
|
143
|
-
pathSegment = `:${key.slice(1)}`;
|
|
211
|
+
pathSegment = `:${key.slice(1)}`;
|
|
144
212
|
} else if (options?.camelCaseToKebabCase) {
|
|
145
|
-
// Convert camelCase to kebab-case for path segments if option is enabled
|
|
146
213
|
pathSegment = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
147
214
|
}
|
|
148
215
|
|
|
216
|
+
// Build the sdk dot-path for method-specific configuration matching
|
|
217
|
+
const currentSdkKeys = [...sdkKeys, key];
|
|
218
|
+
const sdkPath = currentSdkKeys.join(".");
|
|
219
|
+
|
|
149
220
|
// Always create a request assuming this is a method call
|
|
150
221
|
const endpoint = `/${path.join("/")}`;
|
|
151
222
|
const method = getMethod(isMethod ? methodName : key, options);
|
|
152
223
|
let request: RequestInstance = client.createRequest()({ endpoint, method });
|
|
153
|
-
request = applyDefaults(request, endpoint, options?.defaults);
|
|
224
|
+
request = applyDefaults(request, { endpoint, sdkPath, defaults: options?.defaults });
|
|
154
225
|
|
|
155
226
|
// But also, assume the key is a new path segment for a deeper call
|
|
156
227
|
const newPath = [...path, pathSegment];
|
|
157
|
-
const deeperProxy = createRecursiveProxy(client, newPath, options);
|
|
228
|
+
const deeperProxy = createRecursiveProxy(client, { path: newPath, sdkKeys: currentSdkKeys, options });
|
|
158
229
|
|
|
159
230
|
// Return a new proxy that wraps both the request and the deeper proxy
|
|
160
231
|
return new Proxy(request, {
|
|
@@ -191,7 +262,7 @@ export const createSdk = <Client extends ClientInstance, RecursiveSchema extends
|
|
|
191
262
|
|
|
192
263
|
const mergedOptions: CreateSdkOptions<RecursiveSchema> = { camelCaseToKebabCase, methodTransform, ...rest };
|
|
193
264
|
// Break inference for TypeDoc / tsserver (TS2589) — runtime value is unchanged.
|
|
194
|
-
const proxy = createRecursiveProxy(client, [], mergedOptions as never);
|
|
265
|
+
const proxy = createRecursiveProxy(client, { path: [], sdkKeys: [], options: mergedOptions as never });
|
|
195
266
|
|
|
196
267
|
return new Proxy(proxy, {
|
|
197
268
|
get: (target, key: string) => {
|