@ahoo-wang/fetcher 3.0.1 → 3.0.3
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/dist/types.d.ts +130 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -35,27 +35,149 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
35
35
|
*/
|
|
36
36
|
export type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* Creates a new type by removing all readonly properties from an existing type.
|
|
39
|
+
*
|
|
40
|
+
* This utility type takes a type T and produces a new type that excludes all properties
|
|
41
|
+
* that are marked as readonly in the original type. This is useful when you need to create
|
|
42
|
+
* a mutable version of an interface or when working with data that should be modifiable.
|
|
43
|
+
*
|
|
44
|
+
* @template T - The original type from which to remove readonly properties
|
|
45
|
+
* @returns A new type containing only the mutable (non-readonly) properties of T
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* interface User {
|
|
49
|
+
* readonly id: number;
|
|
50
|
+
* name: string;
|
|
51
|
+
* readonly createdAt: Date;
|
|
52
|
+
* email: string;
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* type MutableUser = RemoveReadonlyFields<User>;
|
|
56
|
+
* // Result: { name: string; email: string; }
|
|
57
|
+
* // 'id' and 'createdAt' are excluded because they are readonly
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Usage in function parameters
|
|
61
|
+
* function updateUser(user: RemoveReadonlyFields<User>) {
|
|
62
|
+
* // user.id and user.createdAt are not available here
|
|
63
|
+
* user.name = 'New Name'; // OK
|
|
64
|
+
* user.email = 'new@email.com'; // OK
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
export type RemoveReadonlyFields<T> = {
|
|
68
|
+
[K in keyof T as Equal<Pick<T, K>, Readonly<Pick<T, K>>> extends true ? never : K]: T[K];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Utility type to check if two types X and Y are exactly equal.
|
|
72
|
+
*
|
|
73
|
+
* This type uses conditional types and function type inference to determine
|
|
74
|
+
* strict type equality. It returns true if X and Y are identical types,
|
|
75
|
+
* false otherwise. This is particularly useful in mapped types for filtering
|
|
76
|
+
* based on type properties.
|
|
77
|
+
*
|
|
78
|
+
* @template X - First type to compare
|
|
79
|
+
* @template Y - Second type to compare
|
|
80
|
+
* @returns true if X and Y are the same type, false otherwise
|
|
81
|
+
*
|
|
82
|
+
* @internal This is an internal utility type used by other type definitions
|
|
83
|
+
*/
|
|
84
|
+
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
85
|
+
/**
|
|
86
|
+
* Interface representing a named capable entity.
|
|
87
|
+
*
|
|
88
|
+
* This interface defines a contract for objects that have an identifiable name.
|
|
89
|
+
* Any type implementing this interface must provide a string property called 'name'
|
|
90
|
+
* that uniquely identifies the entity within its context.
|
|
91
|
+
*
|
|
92
|
+
* @interface NamedCapable
|
|
93
|
+
*
|
|
94
|
+
* @property {string} name - A unique identifier for the entity, used for
|
|
95
|
+
* identification, logging, and user-facing display purposes.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* class Service implements NamedCapable {
|
|
99
|
+
* name = 'UserService';
|
|
100
|
+
*
|
|
101
|
+
* async getUser(id: number) {
|
|
102
|
+
* // Implementation
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* const services: NamedCapable[] = [
|
|
108
|
+
* { name: 'AuthService' },
|
|
109
|
+
* { name: 'DataService' }
|
|
110
|
+
* ];
|
|
111
|
+
*
|
|
112
|
+
* services.forEach(service => {
|
|
113
|
+
* console.log(`Initializing ${service.name}`);
|
|
114
|
+
* });
|
|
40
115
|
*/
|
|
41
116
|
export interface NamedCapable {
|
|
42
117
|
/**
|
|
43
|
-
* The name of the entity
|
|
118
|
+
* The name of the entity.
|
|
119
|
+
*
|
|
120
|
+
* This property serves as a unique identifier for the implementing object.
|
|
121
|
+
* It should be descriptive and follow consistent naming conventions
|
|
122
|
+
* within the application context.
|
|
44
123
|
*/
|
|
45
124
|
name: string;
|
|
46
125
|
}
|
|
47
126
|
/**
|
|
48
|
-
* Global extension of Response interface
|
|
49
|
-
*
|
|
127
|
+
* Global extension of the native Response interface.
|
|
128
|
+
*
|
|
129
|
+
* This declaration augments the standard Web API Response interface to provide
|
|
130
|
+
* enhanced type safety for JSON parsing operations. The extended json() method
|
|
131
|
+
* allows specifying the expected return type, enabling better TypeScript
|
|
132
|
+
* inference and compile-time type checking.
|
|
133
|
+
*
|
|
134
|
+
* @interface Response
|
|
50
135
|
*/
|
|
51
136
|
declare global {
|
|
52
137
|
interface Response {
|
|
53
138
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
139
|
+
* Parses the response body as JSON with type safety.
|
|
140
|
+
*
|
|
141
|
+
* This method extends the native Response.json() method to support generic
|
|
142
|
+
* type parameters, allowing developers to specify the expected shape of
|
|
143
|
+
* the parsed JSON data. This provides compile-time type checking and
|
|
144
|
+
* better IDE support.
|
|
145
|
+
*
|
|
146
|
+
* @template T - The expected type of the parsed JSON data. Defaults to 'any' for backward compatibility.
|
|
147
|
+
* @returns {Promise<T>} A promise that resolves to the parsed JSON data of type T.
|
|
148
|
+
*
|
|
149
|
+
* @throws {SyntaxError} If the response body is not valid JSON.
|
|
150
|
+
* @throws {TypeError} If the response has no body or the body cannot be parsed.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* interface User {
|
|
154
|
+
* id: number;
|
|
155
|
+
* name: string;
|
|
156
|
+
* email: string;
|
|
157
|
+
* }
|
|
158
|
+
*
|
|
159
|
+
* const response = await fetch('/api/user/123');
|
|
160
|
+
* const user: User = await response.json<User>();
|
|
161
|
+
* console.log(user.name); // TypeScript knows this is a string
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* // Without type parameter (defaults to any)
|
|
165
|
+
* const data = await response.json();
|
|
166
|
+
* // data is of type 'any'
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Error handling
|
|
170
|
+
* try {
|
|
171
|
+
* const result = await response.json<{ success: boolean; data: string[] }>();
|
|
172
|
+
* if (result.success) {
|
|
173
|
+
* result.data.forEach(item => console.log(item));
|
|
174
|
+
* }
|
|
175
|
+
* } catch (error) {
|
|
176
|
+
* console.error('Failed to parse JSON:', error);
|
|
177
|
+
* }
|
|
57
178
|
*/
|
|
58
179
|
json<T = any>(): Promise<T>;
|
|
59
180
|
}
|
|
60
181
|
}
|
|
182
|
+
export {};
|
|
61
183
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACvD,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Fetcher is not just another HTTP client—it's a complete ecosystem designed for modern web development with native LLM\nstreaming API support. Built on the native Fetch API, Fetcher provides an Axios-like experience with powerful features\nwhile maintaining an incredibly small footprint.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|