@data-client/rest 0.1.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/LICENSE +201 -0
- package/README.md +110 -0
- package/dist/index.js +561 -0
- package/dist/index.umd.min.js +1 -0
- package/dist/next.js +520 -0
- package/dist/package.json +1 -0
- package/legacy/NetworkError.js +13 -0
- package/legacy/OptionsToFunction.js +2 -0
- package/legacy/RestEndpoint.js +225 -0
- package/legacy/RestEndpointTypeHelp.js +2 -0
- package/legacy/RestHelpers.js +33 -0
- package/legacy/createResource.js +88 -0
- package/legacy/extractCollection.js +14 -0
- package/legacy/getArrayPath.js +19 -0
- package/legacy/hookifyResource.js +24 -0
- package/legacy/index.js +10 -0
- package/legacy/mapCollection.js +14 -0
- package/legacy/next/OptionsToFunction.js +2 -0
- package/legacy/next/RestEndpoint.js +225 -0
- package/legacy/next/createResource.js +86 -0
- package/legacy/next/index.js +4 -0
- package/legacy/next/resourceTypes.js +2 -0
- package/legacy/paginatedCollections.js +29 -0
- package/legacy/paginationUpdate.js +36 -0
- package/legacy/paramsToString.js +6 -0
- package/legacy/paramsToString.native.js +9 -0
- package/legacy/pathTypes.js +2 -0
- package/legacy/test-fixtures.js +111 -0
- package/legacy/utiltypes.js +2 -0
- package/lib/NetworkError.d.ts +11 -0
- package/lib/NetworkError.d.ts.map +1 -0
- package/lib/NetworkError.js +13 -0
- package/lib/OptionsToFunction.d.ts +7 -0
- package/lib/OptionsToFunction.d.ts.map +1 -0
- package/lib/OptionsToFunction.js +2 -0
- package/lib/RestEndpoint.d.ts +548 -0
- package/lib/RestEndpoint.js +229 -0
- package/lib/RestEndpointTypeHelp.d.ts +10 -0
- package/lib/RestEndpointTypeHelp.d.ts.map +1 -0
- package/lib/RestEndpointTypeHelp.js +2 -0
- package/lib/RestHelpers.d.ts +7 -0
- package/lib/RestHelpers.d.ts.map +1 -0
- package/lib/RestHelpers.js +33 -0
- package/lib/createResource.d.ts +66 -0
- package/lib/createResource.d.ts.map +1 -0
- package/lib/createResource.js +104 -0
- package/lib/extractCollection.d.ts +11 -0
- package/lib/extractCollection.d.ts.map +1 -0
- package/lib/extractCollection.js +16 -0
- package/lib/getArrayPath.d.ts +3 -0
- package/lib/getArrayPath.d.ts.map +1 -0
- package/lib/getArrayPath.js +19 -0
- package/lib/hookifyResource.d.ts +14 -0
- package/lib/hookifyResource.d.ts.map +1 -0
- package/lib/hookifyResource.js +24 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/mapCollection.d.ts +16 -0
- package/lib/mapCollection.d.ts.map +1 -0
- package/lib/mapCollection.js +16 -0
- package/lib/next/OptionsToFunction.d.ts +7 -0
- package/lib/next/OptionsToFunction.d.ts.map +1 -0
- package/lib/next/OptionsToFunction.js +2 -0
- package/lib/next/RestEndpoint.d.ts +542 -0
- package/lib/next/RestEndpoint.js +229 -0
- package/lib/next/createResource.d.ts +86 -0
- package/lib/next/createResource.d.ts.map +1 -0
- package/lib/next/createResource.js +100 -0
- package/lib/next/index.d.ts +6 -0
- package/lib/next/index.d.ts.map +1 -0
- package/lib/next/index.js +4 -0
- package/lib/next/resourceTypes.d.ts +31 -0
- package/lib/next/resourceTypes.d.ts.map +1 -0
- package/lib/next/resourceTypes.js +2 -0
- package/lib/paginatedCollections.d.ts +3 -0
- package/lib/paginatedCollections.d.ts.map +1 -0
- package/lib/paginatedCollections.js +29 -0
- package/lib/paginationUpdate.d.ts +8 -0
- package/lib/paginationUpdate.d.ts.map +1 -0
- package/lib/paginationUpdate.js +40 -0
- package/lib/paramsToString.d.ts +2 -0
- package/lib/paramsToString.d.ts.map +1 -0
- package/lib/paramsToString.js +6 -0
- package/lib/paramsToString.native.d.ts +2 -0
- package/lib/paramsToString.native.d.ts.map +1 -0
- package/lib/paramsToString.native.js +9 -0
- package/lib/pathTypes.d.ts +20 -0
- package/lib/pathTypes.d.ts.map +1 -0
- package/lib/pathTypes.js +2 -0
- package/lib/test-fixtures.d.ts +141 -0
- package/lib/test-fixtures.d.ts.map +1 -0
- package/lib/test-fixtures.js +111 -0
- package/lib/utiltypes.d.ts +21 -0
- package/lib/utiltypes.d.ts.map +1 -0
- package/lib/utiltypes.js +2 -0
- package/node.mjs +1 -0
- package/package.json +121 -0
- package/src/NetworkError.ts +17 -0
- package/src/OptionsToFunction.ts +42 -0
- package/src/RestEndpoint.d.ts +548 -0
- package/src/RestEndpoint.js +262 -0
- package/src/RestEndpointTypeHelp.ts +20 -0
- package/src/RestHelpers.ts +48 -0
- package/src/__tests__/Resource.test.ts +317 -0
- package/src/__tests__/RestEndpoint.ts +1304 -0
- package/src/__tests__/__snapshots__/RestEndpoint.ts.snap +18 -0
- package/src/__tests__/__snapshots__/createResource.test.ts.snap +5 -0
- package/src/__tests__/createResource.test.ts +583 -0
- package/src/__tests__/getArrayPath.test.ts +30 -0
- package/src/__tests__/hookifyResource.ts +197 -0
- package/src/__tests__/types.test.ts +309 -0
- package/src/createResource.ts +172 -0
- package/src/extractCollection.ts +34 -0
- package/src/getArrayPath.ts +20 -0
- package/src/hookifyResource.ts +36 -0
- package/src/index.ts +42 -0
- package/src/mapCollection.ts +54 -0
- package/src/next/OptionsToFunction.ts +41 -0
- package/src/next/RestEndpoint.d.ts +542 -0
- package/src/next/RestEndpoint.js +262 -0
- package/src/next/__tests__/RestEndpoint.ts +1333 -0
- package/src/next/__tests__/__snapshots__/RestEndpoint.ts.snap +18 -0
- package/src/next/__tests__/types.test.ts +429 -0
- package/src/next/createResource.ts +194 -0
- package/src/next/index.ts +5 -0
- package/src/next/resourceTypes.ts +32 -0
- package/src/package.json +1 -0
- package/src/paginatedCollections.ts +32 -0
- package/src/paginationUpdate.ts +49 -0
- package/src/paramsToString.native.ts +10 -0
- package/src/paramsToString.ts +7 -0
- package/src/pathTypes.ts +58 -0
- package/src/test-fixtures.ts +128 -0
- package/src/utiltypes.ts +25 -0
- package/ts4.0/NetworkError.d.ts +11 -0
- package/ts4.0/OptionsToFunction.d.ts +16 -0
- package/ts4.0/RestEndpoint.d.ts +240 -0
- package/ts4.0/RestEndpointTypeHelp.d.ts +10 -0
- package/ts4.0/RestHelpers.d.ts +7 -0
- package/ts4.0/createResource.d.ts +66 -0
- package/ts4.0/extractCollection.d.ts +11 -0
- package/ts4.0/getArrayPath.d.ts +3 -0
- package/ts4.0/hookifyResource.d.ts +19 -0
- package/ts4.0/index.d.ts +12 -0
- package/ts4.0/mapCollection.d.ts +16 -0
- package/ts4.0/next/OptionsToFunction.d.ts +16 -0
- package/ts4.0/next/RestEndpoint.d.ts +226 -0
- package/ts4.0/next/createResource.d.ts +94 -0
- package/ts4.0/next/index.d.ts +6 -0
- package/ts4.0/next/resourceTypes.d.ts +31 -0
- package/ts4.0/paginatedCollections.d.ts +3 -0
- package/ts4.0/paginationUpdate.d.ts +10 -0
- package/ts4.0/paramsToString.d.ts +2 -0
- package/ts4.0/paramsToString.native.d.ts +2 -0
- package/ts4.0/pathTypes.d.ts +20 -0
- package/ts4.0/test-fixtures.d.ts +141 -0
- package/ts4.0/utiltypes.d.ts +5 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** An error with a Rest Endpoint fetch
|
|
2
|
+
*
|
|
3
|
+
* @see https://resthooks.io/rest/api/NetworkError
|
|
4
|
+
*/
|
|
5
|
+
export default class NetworkError extends Error {
|
|
6
|
+
constructor(response) {
|
|
7
|
+
super(response.statusText || `Network response not 'ok': ${response.status}`);
|
|
8
|
+
this.name = 'NetworkError';
|
|
9
|
+
this.status = response.status;
|
|
10
|
+
this.response = response;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJOZXR3b3JrRXJyb3IiLCJFcnJvciIsImNvbnN0cnVjdG9yIiwicmVzcG9uc2UiLCJzdGF0dXNUZXh0Iiwic3RhdHVzIiwibmFtZSJdLCJzb3VyY2VzIjpbIi4uL3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|
|
1
|
+
import type { FetchFunction, ResolveType } from '@data-client/endpoint';
|
|
2
|
+
import { PathArgs } from './pathTypes.js';
|
|
3
|
+
import { PartialRestGenerics, RestInstanceBase, RestFetch } from './RestEndpoint.js';
|
|
4
|
+
export type OptionsToFunction<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
5
|
+
body?: any;
|
|
6
|
+
}, F extends FetchFunction> = 'path' extends keyof O ? RestFetch<'searchParams' extends keyof O ? O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, 'body' extends keyof O ? O['body'] : E['body'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>> : 'body' extends keyof O ? RestFetch<'searchParams' extends keyof O ? O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, O['body'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>> : 'searchParams' extends keyof O ? RestFetch<O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, E['body'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>> : (this: ThisParameterType<F>, ...args: Parameters<F>) => Promise<O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>>;
|
|
7
|
+
//# sourceMappingURL=OptionsToFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionsToFunction.d.ts","sourceRoot":"","sources":["../src/OptionsToFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,mBAAmB,EAEnB,gBAAgB,EAChB,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,iBAAiB,CAC3B,CAAC,SAAS,mBAAmB,EAC7B,CAAC,SAAS,gBAAgB,GAAG;IAAE,IAAI,CAAC,EAAE,GAAG,CAAA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uLi5hcmdzOiBQYXJhbWV0ZXJzPEY+XG4gICAgKSA9PiBQcm9taXNlPFxuICAgICAgT1sncHJvY2VzcyddIGV4dGVuZHMge30gPyBSZXR1cm5UeXBlPE9bJ3Byb2Nlc3MnXT4gOiBSZXNvbHZlVHlwZTxGPlxuICAgID47XG4iXSwibWFwcGluZ3MiOiIifQ==
|
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
import type {
|
|
3
|
+
EndpointExtraOptions,
|
|
4
|
+
EndpointInstanceInterface,
|
|
5
|
+
Schema,
|
|
6
|
+
FetchFunction,
|
|
7
|
+
ResolveType,
|
|
8
|
+
} from '@data-client/endpoint';
|
|
9
|
+
|
|
10
|
+
import type { ExtractCollection } from './extractCollection.js';
|
|
11
|
+
import { OptionsToFunction } from './OptionsToFunction.js';
|
|
12
|
+
import { PathArgs } from './pathTypes.js';
|
|
13
|
+
import { EndpointUpdateFunction } from './RestEndpointTypeHelp.js';
|
|
14
|
+
|
|
15
|
+
export interface RestInstanceBase<
|
|
16
|
+
F extends FetchFunction = FetchFunction,
|
|
17
|
+
S extends Schema | undefined = any,
|
|
18
|
+
M extends true | undefined = true | undefined,
|
|
19
|
+
O extends {
|
|
20
|
+
path: string;
|
|
21
|
+
body?: any;
|
|
22
|
+
searchParams?: any;
|
|
23
|
+
} = { path: string },
|
|
24
|
+
> extends EndpointInstanceInterface<F, S, M> {
|
|
25
|
+
readonly body?: 'body' extends keyof O ? O['body'] : any;
|
|
26
|
+
readonly searchParams?: 'searchParams' extends keyof O
|
|
27
|
+
? O['searchParams']
|
|
28
|
+
: // unknown is identity with '&' type operator
|
|
29
|
+
unknown;
|
|
30
|
+
|
|
31
|
+
/** Pattern to construct url based on Url Parameters
|
|
32
|
+
* @see https://resthooks.io/rest/api/RestEndpoint#path
|
|
33
|
+
*/
|
|
34
|
+
readonly path: O['path'];
|
|
35
|
+
/** Prepended to all urls
|
|
36
|
+
* @see https://resthooks.io/rest/api/RestEndpoint#urlPrefix
|
|
37
|
+
*/
|
|
38
|
+
readonly urlPrefix: string;
|
|
39
|
+
readonly requestInit: RequestInit;
|
|
40
|
+
readonly method: string;
|
|
41
|
+
readonly signal: AbortSignal | undefined;
|
|
42
|
+
|
|
43
|
+
/* fetch lifecycles */
|
|
44
|
+
/* before-fetch */
|
|
45
|
+
url(...args: Parameters<F>): string;
|
|
46
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#getRequestInit */
|
|
47
|
+
getRequestInit(
|
|
48
|
+
this: any,
|
|
49
|
+
body?: RequestInit['body'] | Record<string, unknown>,
|
|
50
|
+
): RequestInit;
|
|
51
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#getHeaders */
|
|
52
|
+
getHeaders(headers: HeadersInit): HeadersInit;
|
|
53
|
+
/* after-fetch */
|
|
54
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#fetchResponse */
|
|
55
|
+
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
56
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#parseResponse */
|
|
57
|
+
parseResponse(response: Response): Promise<any>;
|
|
58
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#process */
|
|
59
|
+
process(value: any, ...args: Parameters<F>): ResolveType<F>;
|
|
60
|
+
|
|
61
|
+
/* utilities */
|
|
62
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#testKey */
|
|
63
|
+
testKey(key: string): boolean;
|
|
64
|
+
|
|
65
|
+
/* extenders */
|
|
66
|
+
// TODO: figure out better way than wrapping whole options in Readonly<> + making O extend from {}
|
|
67
|
+
// this is just a hack to handle when no members of PartialRestGenerics are present
|
|
68
|
+
// Note: Using overloading (like paginated did) struggles because typescript does not have a clear way of distinguishing one
|
|
69
|
+
// should be used from the other (due to same problem with every member being partial)
|
|
70
|
+
extend<E extends RestInstanceBase, O extends PartialRestGenerics | {}>(
|
|
71
|
+
this: E,
|
|
72
|
+
options: Readonly<RestEndpointExtendOptions<O, E, F> & O>,
|
|
73
|
+
): RestExtendedEndpoint<O, E>;
|
|
74
|
+
paginated<
|
|
75
|
+
E extends RestInstanceBase<FetchFunction, any, undefined>,
|
|
76
|
+
A extends any[],
|
|
77
|
+
>(
|
|
78
|
+
this: E,
|
|
79
|
+
removeCursor: (...args: A) => readonly [...Parameters<E>],
|
|
80
|
+
): PaginationEndpoint<E, A>;
|
|
81
|
+
paginated<
|
|
82
|
+
E extends RestInstanceBase<FetchFunction, any, undefined>,
|
|
83
|
+
C extends string,
|
|
84
|
+
>(
|
|
85
|
+
this: E,
|
|
86
|
+
cursorField: C,
|
|
87
|
+
): PaginationFieldEndpoint<E, C>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface RestInstance<
|
|
91
|
+
F extends FetchFunction = FetchFunction,
|
|
92
|
+
S extends Schema | undefined = any,
|
|
93
|
+
M extends true | undefined = true | undefined,
|
|
94
|
+
O extends {
|
|
95
|
+
path: string;
|
|
96
|
+
body?: any;
|
|
97
|
+
searchParams?: any;
|
|
98
|
+
} = { path: string },
|
|
99
|
+
> extends RestInstanceBase<F, S, M, O> {
|
|
100
|
+
push: AddEndpoint<F, S, O>;
|
|
101
|
+
unshift: AddEndpoint<F, S, O>;
|
|
102
|
+
assign: AddEndpoint<F, S, O>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type ContainsCollectionArray =
|
|
106
|
+
| { push: any; unshift: any }
|
|
107
|
+
| { [K: string]: ContainsCollectionArray }
|
|
108
|
+
| { schema: { [K: string]: ContainsCollectionArray } };
|
|
109
|
+
export type ContainsCollectionValues =
|
|
110
|
+
| { assign: any }
|
|
111
|
+
| { [K: string]: ContainsCollectionValues }
|
|
112
|
+
| { schema: { [K: string]: ContainsCollectionValues } };
|
|
113
|
+
|
|
114
|
+
export type RestEndpointExtendOptions<
|
|
115
|
+
O extends PartialRestGenerics,
|
|
116
|
+
E extends RestInstanceBase,
|
|
117
|
+
F extends FetchFunction,
|
|
118
|
+
> = RestEndpointOptions<
|
|
119
|
+
OptionsToFunction<O, E, F>,
|
|
120
|
+
'schema' extends keyof O
|
|
121
|
+
? Extract<O['schema'], Schema | undefined>
|
|
122
|
+
: E['schema']
|
|
123
|
+
> &
|
|
124
|
+
Partial<Omit<E, KeyofRestEndpoint | keyof PartialRestGenerics>>;
|
|
125
|
+
|
|
126
|
+
type OptionsToRestEndpoint<
|
|
127
|
+
O extends PartialRestGenerics,
|
|
128
|
+
E extends RestInstanceBase & { body?: any },
|
|
129
|
+
F extends FetchFunction,
|
|
130
|
+
> = 'path' extends keyof O
|
|
131
|
+
? RestType<
|
|
132
|
+
'searchParams' extends keyof O
|
|
133
|
+
? O['searchParams'] extends undefined
|
|
134
|
+
? PathArgs<Exclude<O['path'], undefined>>
|
|
135
|
+
: O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
|
|
136
|
+
: PathArgs<Exclude<O['path'], undefined>>,
|
|
137
|
+
'body' extends keyof O ? O['body'] : E['body'],
|
|
138
|
+
'schema' extends keyof O ? O['schema'] : E['schema'],
|
|
139
|
+
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
|
|
140
|
+
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
|
|
141
|
+
{
|
|
142
|
+
path: Exclude<O['path'], undefined>;
|
|
143
|
+
body: 'body' extends keyof O ? O['body'] : E['body'];
|
|
144
|
+
searchParams: 'searchParams' extends keyof O
|
|
145
|
+
? O['searchParams']
|
|
146
|
+
: E['searchParams'];
|
|
147
|
+
}
|
|
148
|
+
>
|
|
149
|
+
: 'body' extends keyof O
|
|
150
|
+
? RestType<
|
|
151
|
+
'searchParams' extends keyof O
|
|
152
|
+
? O['searchParams'] extends undefined
|
|
153
|
+
? PathArgs<Exclude<O['path'], undefined>>
|
|
154
|
+
: O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
|
|
155
|
+
: PathArgs<Exclude<E['path'], undefined>>,
|
|
156
|
+
O['body'],
|
|
157
|
+
'schema' extends keyof O ? O['schema'] : E['schema'],
|
|
158
|
+
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
|
|
159
|
+
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
|
|
160
|
+
{
|
|
161
|
+
path: E['path'];
|
|
162
|
+
body: O['body'];
|
|
163
|
+
searchParams: 'searchParams' extends keyof O
|
|
164
|
+
? O['searchParams']
|
|
165
|
+
: E['searchParams'];
|
|
166
|
+
}
|
|
167
|
+
>
|
|
168
|
+
: 'searchParams' extends keyof O
|
|
169
|
+
? RestType<
|
|
170
|
+
O['searchParams'] extends undefined
|
|
171
|
+
? PathArgs<Exclude<O['path'], undefined>>
|
|
172
|
+
: O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
|
|
173
|
+
E['body'],
|
|
174
|
+
'schema' extends keyof O ? O['schema'] : E['schema'],
|
|
175
|
+
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
|
|
176
|
+
O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
|
|
177
|
+
{
|
|
178
|
+
path: E['path'];
|
|
179
|
+
body: E['body'];
|
|
180
|
+
searchParams: O['searchParams'];
|
|
181
|
+
}
|
|
182
|
+
>
|
|
183
|
+
: RestInstance<
|
|
184
|
+
F,
|
|
185
|
+
'schema' extends keyof O ? O['schema'] : E['schema'],
|
|
186
|
+
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
|
|
187
|
+
{
|
|
188
|
+
path: 'path' extends keyof O
|
|
189
|
+
? Exclude<O['path'], undefined>
|
|
190
|
+
: E['path'];
|
|
191
|
+
body: 'body' extends keyof O ? O['body'] : E['body'];
|
|
192
|
+
searchParams: 'searchParams' extends keyof O
|
|
193
|
+
? O['searchParams']
|
|
194
|
+
: E['searchParams'];
|
|
195
|
+
}
|
|
196
|
+
>;
|
|
197
|
+
|
|
198
|
+
export type RestExtendedEndpoint<
|
|
199
|
+
O extends PartialRestGenerics,
|
|
200
|
+
E extends RestInstanceBase,
|
|
201
|
+
> = OptionsToRestEndpoint<
|
|
202
|
+
O,
|
|
203
|
+
E,
|
|
204
|
+
RestInstance<
|
|
205
|
+
(
|
|
206
|
+
...args: Parameters<E>
|
|
207
|
+
) => O['process'] extends {}
|
|
208
|
+
? Promise<ReturnType<O['process']>>
|
|
209
|
+
: ReturnType<E>,
|
|
210
|
+
'schema' extends keyof O ? O['schema'] : E['schema'],
|
|
211
|
+
'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']
|
|
212
|
+
>
|
|
213
|
+
> &
|
|
214
|
+
Omit<O, KeyofRestEndpoint> &
|
|
215
|
+
Omit<E, KeyofRestEndpoint | keyof O>;
|
|
216
|
+
|
|
217
|
+
export interface PartialRestGenerics {
|
|
218
|
+
readonly path?: string;
|
|
219
|
+
readonly schema?: Schema | undefined;
|
|
220
|
+
readonly method?: string;
|
|
221
|
+
/** Only used for types */
|
|
222
|
+
readonly body?: any;
|
|
223
|
+
/** Only used for types */
|
|
224
|
+
readonly searchParams?: any;
|
|
225
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#process */
|
|
226
|
+
process?(value: any, ...args: any): any;
|
|
227
|
+
}
|
|
228
|
+
export interface RestGenerics extends PartialRestGenerics {
|
|
229
|
+
readonly path: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export type PaginationEndpoint<
|
|
233
|
+
E extends RestInstanceBase,
|
|
234
|
+
A extends any[],
|
|
235
|
+
> = RestInstance<
|
|
236
|
+
ParamFetchNoBody<A[0], ResolveType<E>>,
|
|
237
|
+
E['schema'],
|
|
238
|
+
E['sideEffect'],
|
|
239
|
+
Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
240
|
+
searchParams: Omit<A[0], keyof PathArgs<E['path']>>;
|
|
241
|
+
}
|
|
242
|
+
>;
|
|
243
|
+
export type PaginationFieldEndpoint<
|
|
244
|
+
E extends RestInstanceBase,
|
|
245
|
+
C extends string,
|
|
246
|
+
> = RestInstance<
|
|
247
|
+
ParamFetchNoBody<
|
|
248
|
+
{ [K in C]: string | number | boolean } & E['searchParams'] &
|
|
249
|
+
PathArgs<Exclude<E['path'], undefined>>,
|
|
250
|
+
ResolveType<E>
|
|
251
|
+
>,
|
|
252
|
+
E['schema'],
|
|
253
|
+
E['sideEffect'],
|
|
254
|
+
Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
255
|
+
searchParams: { [K in C]: string | number | boolean } & E['searchParams'];
|
|
256
|
+
}
|
|
257
|
+
>;
|
|
258
|
+
export type AddEndpoint<
|
|
259
|
+
F extends FetchFunction = FetchFunction,
|
|
260
|
+
S extends Schema | undefined = any,
|
|
261
|
+
O extends {
|
|
262
|
+
path: string;
|
|
263
|
+
body?: any;
|
|
264
|
+
searchParams?: any;
|
|
265
|
+
} = { path: string },
|
|
266
|
+
> = RestInstanceBase<
|
|
267
|
+
RestFetch<
|
|
268
|
+
'searchParams' extends keyof O
|
|
269
|
+
? O['searchParams'] extends undefined
|
|
270
|
+
? PathArgs<Exclude<O['path'], undefined>>
|
|
271
|
+
: O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
|
|
272
|
+
: PathArgs<Exclude<O['path'], undefined>>,
|
|
273
|
+
any,
|
|
274
|
+
ReturnType<F>
|
|
275
|
+
>,
|
|
276
|
+
ExtractCollection<S>,
|
|
277
|
+
true,
|
|
278
|
+
Omit<O, 'body'>
|
|
279
|
+
> & { method: 'POST' };
|
|
280
|
+
|
|
281
|
+
export type BodyDefault<O extends RestGenerics> = 'body' extends keyof O
|
|
282
|
+
? O['body']
|
|
283
|
+
: O['method'] extends 'POST' | 'PUT' | 'PATCH'
|
|
284
|
+
? Record<string, unknown> | FormData
|
|
285
|
+
: undefined;
|
|
286
|
+
|
|
287
|
+
type OptionsBodyDefault<O extends RestGenerics> = 'body' extends keyof O
|
|
288
|
+
? O
|
|
289
|
+
: O['method'] extends 'POST' | 'PUT' | 'PATCH'
|
|
290
|
+
? O & { body: any }
|
|
291
|
+
: O & { body: undefined };
|
|
292
|
+
|
|
293
|
+
export interface RestEndpointOptions<
|
|
294
|
+
F extends FetchFunction = FetchFunction,
|
|
295
|
+
S extends Schema | undefined = undefined,
|
|
296
|
+
> extends EndpointExtraOptions<F> {
|
|
297
|
+
urlPrefix?: string;
|
|
298
|
+
requestInit?: RequestInit;
|
|
299
|
+
getHeaders?(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
|
|
300
|
+
getRequestInit?(body: any): Promise<RequestInit> | RequestInit;
|
|
301
|
+
fetchResponse?(input: RequestInfo, init: RequestInit): Promise<any>;
|
|
302
|
+
parseResponse?(response: Response): Promise<any>;
|
|
303
|
+
|
|
304
|
+
sideEffect?: true | undefined;
|
|
305
|
+
name?: string;
|
|
306
|
+
signal?: AbortSignal;
|
|
307
|
+
fetch?: F;
|
|
308
|
+
key?(...args: Parameters<F>): string;
|
|
309
|
+
url?(...args: Parameters<F>): string;
|
|
310
|
+
update?: EndpointUpdateFunction<F, S>;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export type RestEndpointConstructorOptions<O extends RestGenerics = any> =
|
|
314
|
+
RestEndpointOptions<
|
|
315
|
+
RestFetch<
|
|
316
|
+
'searchParams' extends keyof O
|
|
317
|
+
? O['searchParams'] extends undefined
|
|
318
|
+
? PathArgs<O['path']>
|
|
319
|
+
: O['searchParams'] & PathArgs<O['path']>
|
|
320
|
+
: PathArgs<O['path']>,
|
|
321
|
+
BodyDefault<O>,
|
|
322
|
+
O['process'] extends {}
|
|
323
|
+
? ReturnType<O['process']>
|
|
324
|
+
: any /*Denormalize<O['schema']>*/
|
|
325
|
+
>,
|
|
326
|
+
O['schema']
|
|
327
|
+
>;
|
|
328
|
+
|
|
329
|
+
export interface RestEndpointConstructor {
|
|
330
|
+
new <O extends RestGenerics = any>({
|
|
331
|
+
method,
|
|
332
|
+
sideEffect,
|
|
333
|
+
name,
|
|
334
|
+
...options
|
|
335
|
+
}: RestEndpointConstructorOptions<O> & Readonly<O>): RestInstance<
|
|
336
|
+
RestFetch<
|
|
337
|
+
'searchParams' extends keyof O
|
|
338
|
+
? O['searchParams'] extends undefined
|
|
339
|
+
? PathArgs<O['path']>
|
|
340
|
+
: O['searchParams'] & PathArgs<O['path']>
|
|
341
|
+
: PathArgs<O['path']>,
|
|
342
|
+
BodyDefault<O>,
|
|
343
|
+
O['process'] extends {}
|
|
344
|
+
? ReturnType<O['process']>
|
|
345
|
+
: any /*Denormalize<O['schema']>*/
|
|
346
|
+
>,
|
|
347
|
+
'schema' extends keyof O ? O['schema'] : undefined,
|
|
348
|
+
MethodToSide<O['method']>,
|
|
349
|
+
OptionsBodyDefault<O>
|
|
350
|
+
>;
|
|
351
|
+
readonly prototype: RestInstanceBase;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Simplifies endpoint definitions that follow REST patterns
|
|
355
|
+
*
|
|
356
|
+
* @see https://resthooks.io/rest/api/RestEndpoint
|
|
357
|
+
*/
|
|
358
|
+
export declare let RestEndpoint: RestEndpointConstructor;
|
|
359
|
+
export default RestEndpoint;
|
|
360
|
+
|
|
361
|
+
export type MethodToSide<M> = M extends string
|
|
362
|
+
? M extends 'GET'
|
|
363
|
+
? undefined
|
|
364
|
+
: true
|
|
365
|
+
: undefined;
|
|
366
|
+
|
|
367
|
+
/** RestEndpoint types simplified */
|
|
368
|
+
export type RestType<
|
|
369
|
+
UrlParams = any,
|
|
370
|
+
Body = any,
|
|
371
|
+
S extends Schema | undefined = Schema | undefined,
|
|
372
|
+
M extends true | undefined = true | undefined,
|
|
373
|
+
R = any,
|
|
374
|
+
O extends {
|
|
375
|
+
path: string;
|
|
376
|
+
body?: any;
|
|
377
|
+
searchParams?: any;
|
|
378
|
+
} = { path: string },
|
|
379
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
380
|
+
> = IfTypeScriptLooseNull<
|
|
381
|
+
RestInstance<
|
|
382
|
+
keyof UrlParams extends never
|
|
383
|
+
? (this: EndpointInstanceInterface, body?: Body) => Promise<R>
|
|
384
|
+
: // even with loose null, this will only be true when all members are optional
|
|
385
|
+
{} extends UrlParams
|
|
386
|
+
?
|
|
387
|
+
| ((this: EndpointInstanceInterface, body?: Body) => Promise<R>)
|
|
388
|
+
| ((
|
|
389
|
+
this: EndpointInstanceInterface,
|
|
390
|
+
params: UrlParams,
|
|
391
|
+
body?: Body,
|
|
392
|
+
) => Promise<R>)
|
|
393
|
+
: (
|
|
394
|
+
this: EndpointInstanceInterface,
|
|
395
|
+
params: UrlParams,
|
|
396
|
+
body?: Body,
|
|
397
|
+
) => Promise<R>,
|
|
398
|
+
S,
|
|
399
|
+
M,
|
|
400
|
+
O
|
|
401
|
+
>,
|
|
402
|
+
Body extends {}
|
|
403
|
+
? RestTypeWithBody<UrlParams, S, M, Body, R, O>
|
|
404
|
+
: RestTypeNoBody<UrlParams, S, M, R, O>
|
|
405
|
+
>;
|
|
406
|
+
|
|
407
|
+
export type RestTypeWithBody<
|
|
408
|
+
UrlParams = any,
|
|
409
|
+
S extends Schema | undefined = Schema | undefined,
|
|
410
|
+
M extends true | undefined = true | undefined,
|
|
411
|
+
Body = any,
|
|
412
|
+
R = any /*Denormalize<S>*/,
|
|
413
|
+
O extends {
|
|
414
|
+
path: string;
|
|
415
|
+
body?: any;
|
|
416
|
+
searchParams?: any;
|
|
417
|
+
} = { path: string; body: any },
|
|
418
|
+
> = RestInstance<ParamFetchWithBody<UrlParams, Body, R>, S, M, O>;
|
|
419
|
+
|
|
420
|
+
export type RestTypeNoBody<
|
|
421
|
+
UrlParams = any,
|
|
422
|
+
S extends Schema | undefined = Schema | undefined,
|
|
423
|
+
M extends true | undefined = true | undefined,
|
|
424
|
+
R = any /*Denormalize<S>*/,
|
|
425
|
+
O extends {
|
|
426
|
+
path: string;
|
|
427
|
+
body?: undefined;
|
|
428
|
+
searchParams?: any;
|
|
429
|
+
} = { path: string; body: undefined },
|
|
430
|
+
> = RestInstance<ParamFetchNoBody<UrlParams, R>, S, M, O>;
|
|
431
|
+
|
|
432
|
+
/** Simple parameters, and body fetch functions */
|
|
433
|
+
export type RestFetch<
|
|
434
|
+
UrlParams,
|
|
435
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
436
|
+
Body = {},
|
|
437
|
+
Resolve = any,
|
|
438
|
+
> = IfTypeScriptLooseNull<
|
|
439
|
+
| ParamFetchNoBody<UrlParams, Resolve>
|
|
440
|
+
| ParamFetchWithBody<UrlParams, Body, Resolve>,
|
|
441
|
+
Body extends {}
|
|
442
|
+
? ParamFetchWithBody<UrlParams, Body, Resolve>
|
|
443
|
+
: ParamFetchNoBody<UrlParams, Resolve>
|
|
444
|
+
>;
|
|
445
|
+
|
|
446
|
+
export type ParamFetchWithBody<P, B = {}, R = any> =
|
|
447
|
+
// we must always allow undefined in a union and give it a type without params
|
|
448
|
+
P extends undefined
|
|
449
|
+
? (this: EndpointInstanceInterface, body: B) => Promise<R>
|
|
450
|
+
: // even with loose null, this will only be true when all members are optional
|
|
451
|
+
{} extends P
|
|
452
|
+
? // this safely handles PathArgs with no members that results in a simple `unknown` type
|
|
453
|
+
keyof P extends never
|
|
454
|
+
? (this: EndpointInstanceInterface, body: B) => Promise<R>
|
|
455
|
+
:
|
|
456
|
+
| ((
|
|
457
|
+
this: EndpointInstanceInterface,
|
|
458
|
+
params: P,
|
|
459
|
+
body: B,
|
|
460
|
+
) => Promise<R>)
|
|
461
|
+
| ((this: EndpointInstanceInterface, body: B) => Promise<R>)
|
|
462
|
+
: (this: EndpointInstanceInterface, params: P, body: B) => Promise<R>;
|
|
463
|
+
|
|
464
|
+
export type ParamFetchNoBody<P, R = any> =
|
|
465
|
+
// we must always allow undefined in a union and give it a type without params
|
|
466
|
+
P extends undefined
|
|
467
|
+
? (this: EndpointInstanceInterface) => Promise<R>
|
|
468
|
+
: // even with loose null, this will only be true when all members are optional
|
|
469
|
+
{} extends P
|
|
470
|
+
? // this safely handles PathArgs with no members that results in a simple `unknown` type
|
|
471
|
+
keyof P extends never
|
|
472
|
+
? (this: EndpointInstanceInterface) => Promise<R>
|
|
473
|
+
:
|
|
474
|
+
| ((this: EndpointInstanceInterface, params: P) => Promise<R>)
|
|
475
|
+
| ((this: EndpointInstanceInterface) => Promise<R>)
|
|
476
|
+
: (this: EndpointInstanceInterface, params: P) => Promise<R>;
|
|
477
|
+
|
|
478
|
+
type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;
|
|
479
|
+
|
|
480
|
+
export type KeyofRestEndpoint = keyof RestInstance;
|
|
481
|
+
|
|
482
|
+
export type FromFallBack<K extends keyof E, O, E> = K extends keyof O
|
|
483
|
+
? O[K]
|
|
484
|
+
: E[K];
|
|
485
|
+
|
|
486
|
+
export type FetchMutate<
|
|
487
|
+
A extends readonly any[] = // eslint-disable-next-line @typescript-eslint/ban-types
|
|
488
|
+
| [any, {}]
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
490
|
+
| [{}],
|
|
491
|
+
R = any,
|
|
492
|
+
> = (this: RestInstance, ...args: A) => Promise<R>;
|
|
493
|
+
|
|
494
|
+
export type FetchGet<A extends readonly any[] = [any], R = any> = (
|
|
495
|
+
this: RestInstance,
|
|
496
|
+
...args: A
|
|
497
|
+
) => Promise<R>;
|
|
498
|
+
|
|
499
|
+
export type GetEndpoint<
|
|
500
|
+
UrlParams = any,
|
|
501
|
+
S extends Schema | undefined = Schema | undefined,
|
|
502
|
+
> = RestTypeNoBody<UrlParams, S, undefined>;
|
|
503
|
+
|
|
504
|
+
export type MutateEndpoint<
|
|
505
|
+
UrlParams = any,
|
|
506
|
+
Body extends BodyInit | Record<string, any> = any,
|
|
507
|
+
S extends Schema | undefined = Schema | undefined,
|
|
508
|
+
> = RestTypeWithBody<UrlParams, S, true, Body>;
|
|
509
|
+
|
|
510
|
+
export type Defaults<O, D> = {
|
|
511
|
+
[K in keyof O | keyof D]: K extends keyof O
|
|
512
|
+
? Exclude<O[K], undefined>
|
|
513
|
+
: D[Extract<K, keyof D>];
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
export type NewGetEndpoint<
|
|
517
|
+
O extends {
|
|
518
|
+
path: string;
|
|
519
|
+
searchParams?: any;
|
|
520
|
+
} = { path: string },
|
|
521
|
+
S extends Schema | undefined = Schema | undefined,
|
|
522
|
+
> = RestTypeNoBody<
|
|
523
|
+
'searchParams' extends keyof O
|
|
524
|
+
? O['searchParams'] & PathArgs<O['path']>
|
|
525
|
+
: PathArgs<O['path']>,
|
|
526
|
+
S,
|
|
527
|
+
undefined,
|
|
528
|
+
any,
|
|
529
|
+
O & { body: undefined }
|
|
530
|
+
>;
|
|
531
|
+
|
|
532
|
+
export type NewMutateEndpoint<
|
|
533
|
+
O extends {
|
|
534
|
+
path: string;
|
|
535
|
+
body?: any;
|
|
536
|
+
searchParams?: any;
|
|
537
|
+
} = { path: string; body: any },
|
|
538
|
+
S extends Schema | undefined = Schema | undefined,
|
|
539
|
+
> = RestTypeWithBody<
|
|
540
|
+
'searchParams' extends keyof O
|
|
541
|
+
? O['searchParams'] & PathArgs<O['path']>
|
|
542
|
+
: PathArgs<O['path']>,
|
|
543
|
+
S,
|
|
544
|
+
true,
|
|
545
|
+
O['body'],
|
|
546
|
+
any,
|
|
547
|
+
O
|
|
548
|
+
>;
|