@data-client/rest 0.5.0 → 0.7.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/dist/index.js +22 -12
- package/dist/index.umd.min.js +1 -1
- package/dist/next.js +22 -12
- package/legacy/RestEndpoint.js +4 -1
- package/legacy/createResource.js +10 -5
- package/legacy/paginatedCollections.js +13 -11
- package/legacy/resourceTypes.js +1 -1
- package/lib/RestEndpoint.d.ts +59 -12
- package/lib/RestEndpoint.js +4 -1
- package/lib/createResource.d.ts +1 -1
- package/lib/createResource.d.ts.map +1 -1
- package/lib/createResource.js +8 -3
- package/lib/paginatedCollections.js +13 -11
- package/lib/resourceTypes.d.ts +6 -4
- package/lib/resourceTypes.d.ts.map +1 -1
- package/lib/resourceTypes.js +1 -1
- package/package.json +2 -2
- package/src/RestEndpoint.d.ts +59 -12
- package/src/RestEndpoint.js +4 -0
- package/src/__tests__/RestEndpoint.ts +95 -9
- package/src/__tests__/createResource.test.ts +77 -72
- package/src/createResource.ts +12 -3
- package/src/paginatedCollections.ts +11 -7
- package/src/resourceTypes.ts +24 -18
- package/ts4.0/RestEndpoint.d.ts +41 -7
- package/ts4.0/createResource.d.ts +1 -1
- package/ts4.0/resourceTypes.d.ts +6 -4
- package/ts4.1/RestEndpoint.d.ts +41 -7
- package/ts4.1/createResource.d.ts +1 -1
- package/ts4.1/resourceTypes.d.ts +6 -4
package/src/resourceTypes.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface ResourceGenerics {
|
|
|
23
23
|
/** Only used for types */
|
|
24
24
|
/** @see https://resthooks.io/rest/api/createResource#searchParams */
|
|
25
25
|
readonly searchParams?: any;
|
|
26
|
+
/** @see https://resthooks.io/rest/api/createResource#paginationfield */
|
|
27
|
+
readonly paginationField?: string;
|
|
26
28
|
}
|
|
27
29
|
/** The untyped options for createResource() */
|
|
28
30
|
export interface ResourceOptions {
|
|
@@ -65,22 +67,26 @@ export interface Resource<
|
|
|
65
67
|
* @see https://resthooks.io/rest/api/createResource#getlist
|
|
66
68
|
*/
|
|
67
69
|
getList: 'searchParams' extends keyof O
|
|
68
|
-
? GetEndpoint<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
:
|
|
82
|
-
|
|
83
|
-
|
|
70
|
+
? GetEndpoint<
|
|
71
|
+
{
|
|
72
|
+
path: ShortenPath<O['path']>;
|
|
73
|
+
schema: schema.Collection<[O['schema']]>;
|
|
74
|
+
body: 'body' extends keyof O
|
|
75
|
+
? O['body']
|
|
76
|
+
: Partial<Denormalize<O['schema']>>;
|
|
77
|
+
searchParams: O['searchParams'];
|
|
78
|
+
} & Pick<O, 'paginationField'>
|
|
79
|
+
>
|
|
80
|
+
: GetEndpoint<
|
|
81
|
+
{
|
|
82
|
+
path: ShortenPath<O['path']>;
|
|
83
|
+
schema: schema.Collection<[O['schema']]>;
|
|
84
|
+
body: 'body' extends keyof O
|
|
85
|
+
? O['body']
|
|
86
|
+
: Partial<Denormalize<O['schema']>>;
|
|
87
|
+
searchParams: Record<string, number | string | boolean> | undefined;
|
|
88
|
+
} & Pick<O, 'paginationField'>
|
|
89
|
+
>;
|
|
84
90
|
/** Create a new item (POST)
|
|
85
91
|
*
|
|
86
92
|
* @deprecated use Resource.getList.push instead
|
|
@@ -113,7 +119,7 @@ export interface Resource<
|
|
|
113
119
|
}>
|
|
114
120
|
: MutateEndpoint<{
|
|
115
121
|
path: O['path'];
|
|
116
|
-
body: Partial<Denormalize<O['schema']
|
|
122
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
117
123
|
schema: O['schema'];
|
|
118
124
|
}>;
|
|
119
125
|
/** Update an item (PATCH)
|
|
@@ -128,7 +134,7 @@ export interface Resource<
|
|
|
128
134
|
}>
|
|
129
135
|
: MutateEndpoint<{
|
|
130
136
|
path: O['path'];
|
|
131
|
-
body: Partial<Denormalize<O['schema']
|
|
137
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
132
138
|
schema: O['schema'];
|
|
133
139
|
}>;
|
|
134
140
|
/** Delete an item (DELETE)
|
package/ts4.0/RestEndpoint.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
30
30
|
method: string;
|
|
31
31
|
})['method'];
|
|
32
32
|
readonly signal: AbortSignal | undefined;
|
|
33
|
+
readonly paginationField?: string;
|
|
33
34
|
/* fetch lifecycles */
|
|
34
35
|
/* before-fetch */
|
|
35
36
|
url(...args: Parameters<F>): string;
|
|
@@ -55,23 +56,31 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
55
56
|
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
56
57
|
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
57
58
|
*/
|
|
58
|
-
extend<E extends RestInstanceBase,
|
|
59
|
+
extend<E extends RestInstanceBase, ExtendOptions extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
|
|
59
60
|
}
|
|
60
61
|
export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
|
|
61
62
|
path: string;
|
|
62
63
|
body?: any;
|
|
63
64
|
searchParams?: any;
|
|
64
65
|
method?: string;
|
|
66
|
+
paginationField?: string;
|
|
65
67
|
} = {
|
|
66
68
|
path: string;
|
|
67
69
|
}> extends RestInstanceBase<F, S, M, O> {
|
|
68
|
-
/** Endpoint to append the next page extending a list for pagination
|
|
70
|
+
/** Creates an Endpoint to append the next page extending a list for pagination
|
|
69
71
|
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
70
72
|
*/
|
|
71
73
|
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
72
74
|
...Parameters<E>
|
|
73
75
|
]): PaginationEndpoint<E, A>;
|
|
74
76
|
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
77
|
+
/** Endpoint to append the next page extending a list for pagination
|
|
78
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#getPage
|
|
79
|
+
*/
|
|
80
|
+
getPage: 'paginationField' extends keyof O ? O['paginationField'] extends string ? PaginationFieldEndpoint<F & {
|
|
81
|
+
schema: S;
|
|
82
|
+
sideEffect: M;
|
|
83
|
+
} & O, O['paginationField']> : undefined : undefined;
|
|
75
84
|
/** Endpoint that pushes (place at end) a newly created entity to this Collection
|
|
76
85
|
* @see https://dataclient.io/rest/api/RestEndpoint#push
|
|
77
86
|
*/
|
|
@@ -96,39 +105,59 @@ export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends {
|
|
|
96
105
|
path?: string;
|
|
97
106
|
schema?: Schema;
|
|
98
107
|
method?: string;
|
|
99
|
-
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> & Partial<Omit<E, KeyofRestEndpoint | keyof PartialRestGenerics>>;
|
|
108
|
+
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> & Partial<Omit<E, KeyofRestEndpoint | keyof PartialRestGenerics | keyof RestEndpointOptions>>;
|
|
100
109
|
type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
101
110
|
body?: any;
|
|
111
|
+
paginationField?: string;
|
|
102
112
|
}, F extends FetchFunction> = 'path' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
|
|
103
113
|
path: Exclude<O['path'], undefined>;
|
|
104
114
|
body: 'body' extends keyof O ? O['body'] : E['body'];
|
|
105
115
|
searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
|
|
106
116
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
117
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : E['paginationField'];
|
|
107
118
|
}> : 'body' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
|
|
108
119
|
path: E['path'];
|
|
109
120
|
body: O['body'];
|
|
110
121
|
searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
|
|
111
122
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
123
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
|
|
112
124
|
}> : 'searchParams' extends keyof O ? RestType<O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
|
|
113
125
|
path: E['path'];
|
|
114
126
|
body: E['body'];
|
|
115
127
|
searchParams: O['searchParams'];
|
|
116
128
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
129
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
|
|
117
130
|
}> : RestInstance<F, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], {
|
|
118
131
|
path: 'path' extends keyof O ? Exclude<O['path'], undefined> : E['path'];
|
|
119
132
|
body: 'body' extends keyof O ? O['body'] : E['body'];
|
|
120
133
|
searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
|
|
121
134
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
135
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : E['paginationField'];
|
|
122
136
|
}>;
|
|
123
|
-
export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase
|
|
137
|
+
export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
138
|
+
getPage?: unknown;
|
|
139
|
+
}> = OptionsToRestEndpoint<O, E & (E extends {
|
|
140
|
+
getPage: {
|
|
141
|
+
paginationField: string;
|
|
142
|
+
};
|
|
143
|
+
} ? {
|
|
144
|
+
paginationField: E['getPage']['paginationField'];
|
|
145
|
+
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & Omit<O, KeyofRestEndpoint> & Omit<E, KeyofRestEndpoint | keyof O>;
|
|
124
146
|
export interface PartialRestGenerics {
|
|
147
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#path */
|
|
125
148
|
readonly path?: string;
|
|
149
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#schema */
|
|
126
150
|
readonly schema?: Schema | undefined;
|
|
151
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#method */
|
|
127
152
|
readonly method?: string;
|
|
128
153
|
/** Only used for types */
|
|
154
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#body */
|
|
129
155
|
body?: any;
|
|
130
156
|
/** Only used for types */
|
|
157
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
|
|
131
158
|
searchParams?: any;
|
|
159
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
|
|
160
|
+
readonly paginationField?: string;
|
|
132
161
|
/** @see https://resthooks.io/rest/api/RestEndpoint#process */
|
|
133
162
|
process?(value: any, ...args: any): any;
|
|
134
163
|
}
|
|
@@ -137,18 +166,20 @@ export interface RestGenerics extends PartialRestGenerics {
|
|
|
137
166
|
}
|
|
138
167
|
export type PaginationEndpoint<E extends FetchFunction & RestGenerics & {
|
|
139
168
|
sideEffect?: true | undefined;
|
|
140
|
-
}, A extends any[]> =
|
|
169
|
+
}, A extends any[]> = RestInstanceBase<ParamFetchNoBody<A[0], ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
141
170
|
searchParams: Omit<A[0], keyof PathArgs<E['path']>>;
|
|
142
171
|
}>;
|
|
143
172
|
export type PaginationFieldEndpoint<E extends FetchFunction & RestGenerics & {
|
|
144
173
|
sideEffect?: true | undefined;
|
|
145
|
-
}, C extends string> =
|
|
174
|
+
}, C extends string> = RestInstanceBase<ParamFetchNoBody<{
|
|
146
175
|
[K in C]: string | number | boolean;
|
|
147
176
|
} & E['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
148
177
|
searchParams: {
|
|
149
178
|
[K in C]: string | number | boolean;
|
|
150
179
|
} & E['searchParams'];
|
|
151
|
-
}
|
|
180
|
+
}> & {
|
|
181
|
+
paginationField: C;
|
|
182
|
+
};
|
|
152
183
|
export type AddEndpoint<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, O extends {
|
|
153
184
|
path: string;
|
|
154
185
|
body: any;
|
|
@@ -207,8 +238,10 @@ export type RestType<UrlParams = any, Body = any, S extends Schema | undefined =
|
|
|
207
238
|
path: string;
|
|
208
239
|
body?: any;
|
|
209
240
|
searchParams?: any;
|
|
241
|
+
paginationField?: string;
|
|
210
242
|
} = {
|
|
211
243
|
path: string;
|
|
244
|
+
paginationField: string;
|
|
212
245
|
}> = IfTypeScriptLooseNull<RestInstance<keyof UrlParams extends never ? (this: EndpointInstanceInterface, body?: Body) => Promise<R> : {} extends UrlParams ? ((this: EndpointInstanceInterface, body?: Body) => Promise<R>) | ((this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>) : (this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>, S, M, O>, Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O> : RestTypeNoBody<UrlParams, S, M, R, O>>;
|
|
213
246
|
export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, Body = any, R = any /*Denormalize<S>*/, O extends {
|
|
214
247
|
path: string;
|
|
@@ -258,6 +291,7 @@ export type GetEndpoint<O extends {
|
|
|
258
291
|
readonly schema: Schema;
|
|
259
292
|
/** Only used for types */
|
|
260
293
|
readonly searchParams?: any;
|
|
294
|
+
readonly paginationField?: string;
|
|
261
295
|
} = {
|
|
262
296
|
path: string;
|
|
263
297
|
schema: Schema;
|
|
@@ -3,5 +3,5 @@ import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js'
|
|
|
3
3
|
*
|
|
4
4
|
* @see https://resthooks.io/rest/api/createResource
|
|
5
5
|
*/
|
|
6
|
-
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
6
|
+
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, paginationField, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
7
7
|
//# sourceMappingURL=createResource.d.ts.map
|
package/ts4.0/resourceTypes.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface ResourceGenerics {
|
|
|
16
16
|
/** Only used for types */
|
|
17
17
|
/** @see https://resthooks.io/rest/api/createResource#searchParams */
|
|
18
18
|
readonly searchParams?: any;
|
|
19
|
+
/** @see https://resthooks.io/rest/api/createResource#paginationfield */
|
|
20
|
+
readonly paginationField?: string;
|
|
19
21
|
}
|
|
20
22
|
/** The untyped options for createResource() */
|
|
21
23
|
export interface ResourceOptions {
|
|
@@ -67,14 +69,14 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
67
69
|
]>;
|
|
68
70
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
69
71
|
searchParams: O['searchParams'];
|
|
70
|
-
}
|
|
72
|
+
} & Pick<O, 'paginationField'>> : GetEndpoint<{
|
|
71
73
|
path: ShortenPath<O['path']>;
|
|
72
74
|
schema: schema.Collection<[
|
|
73
75
|
O['schema']
|
|
74
76
|
]>;
|
|
75
77
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
76
78
|
searchParams: Record<string, number | string | boolean> | undefined;
|
|
77
|
-
}
|
|
79
|
+
} & Pick<O, 'paginationField'>>;
|
|
78
80
|
/** Create a new item (POST)
|
|
79
81
|
*
|
|
80
82
|
* @deprecated use Resource.getList.push instead
|
|
@@ -103,7 +105,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
103
105
|
schema: O['schema'];
|
|
104
106
|
}> : MutateEndpoint<{
|
|
105
107
|
path: O['path'];
|
|
106
|
-
body: Partial<Denormalize<O['schema']
|
|
108
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
107
109
|
schema: O['schema'];
|
|
108
110
|
}>;
|
|
109
111
|
/** Update an item (PATCH)
|
|
@@ -116,7 +118,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
116
118
|
schema: O['schema'];
|
|
117
119
|
}> : MutateEndpoint<{
|
|
118
120
|
path: O['path'];
|
|
119
|
-
body: Partial<Denormalize<O['schema']
|
|
121
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
120
122
|
schema: O['schema'];
|
|
121
123
|
}>;
|
|
122
124
|
/** Delete an item (DELETE)
|
package/ts4.1/RestEndpoint.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
30
30
|
method: string;
|
|
31
31
|
})['method'];
|
|
32
32
|
readonly signal: AbortSignal | undefined;
|
|
33
|
+
readonly paginationField?: string;
|
|
33
34
|
/* fetch lifecycles */
|
|
34
35
|
/* before-fetch */
|
|
35
36
|
url(...args: Parameters<F>): string;
|
|
@@ -55,23 +56,31 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
55
56
|
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
56
57
|
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
57
58
|
*/
|
|
58
|
-
extend<E extends RestInstanceBase,
|
|
59
|
+
extend<E extends RestInstanceBase, ExtendOptions extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
|
|
59
60
|
}
|
|
60
61
|
export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
|
|
61
62
|
path: string;
|
|
62
63
|
body?: any;
|
|
63
64
|
searchParams?: any;
|
|
64
65
|
method?: string;
|
|
66
|
+
paginationField?: string;
|
|
65
67
|
} = {
|
|
66
68
|
path: string;
|
|
67
69
|
}> extends RestInstanceBase<F, S, M, O> {
|
|
68
|
-
/** Endpoint to append the next page extending a list for pagination
|
|
70
|
+
/** Creates an Endpoint to append the next page extending a list for pagination
|
|
69
71
|
* @see https://dataclient.io/rest/api/RestEndpoint#paginated
|
|
70
72
|
*/
|
|
71
73
|
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, A extends any[]>(this: E, removeCursor: (...args: A) => readonly [
|
|
72
74
|
...Parameters<E>
|
|
73
75
|
]): PaginationEndpoint<E, A>;
|
|
74
76
|
paginated<E extends RestInstanceBase<FetchFunction, any, undefined>, C extends string>(this: E, cursorField: C): PaginationFieldEndpoint<E, C>;
|
|
77
|
+
/** Endpoint to append the next page extending a list for pagination
|
|
78
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#getPage
|
|
79
|
+
*/
|
|
80
|
+
getPage: 'paginationField' extends keyof O ? O['paginationField'] extends string ? PaginationFieldEndpoint<F & {
|
|
81
|
+
schema: S;
|
|
82
|
+
sideEffect: M;
|
|
83
|
+
} & O, O['paginationField']> : undefined : undefined;
|
|
75
84
|
/** Endpoint that pushes (place at end) a newly created entity to this Collection
|
|
76
85
|
* @see https://dataclient.io/rest/api/RestEndpoint#push
|
|
77
86
|
*/
|
|
@@ -96,39 +105,59 @@ export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends {
|
|
|
96
105
|
path?: string;
|
|
97
106
|
schema?: Schema;
|
|
98
107
|
method?: string;
|
|
99
|
-
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> & Partial<Omit<E, KeyofRestEndpoint | keyof PartialRestGenerics>>;
|
|
108
|
+
}, F extends FetchFunction> = RestEndpointOptions<OptionsToFunction<O, E, F>, 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined> : E['schema']> & Partial<Omit<E, KeyofRestEndpoint | keyof PartialRestGenerics | keyof RestEndpointOptions>>;
|
|
100
109
|
type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
101
110
|
body?: any;
|
|
111
|
+
paginationField?: string;
|
|
102
112
|
}, F extends FetchFunction> = 'path' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
|
|
103
113
|
path: Exclude<O['path'], undefined>;
|
|
104
114
|
body: 'body' extends keyof O ? O['body'] : E['body'];
|
|
105
115
|
searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
|
|
106
116
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
117
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : E['paginationField'];
|
|
107
118
|
}> : 'body' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
|
|
108
119
|
path: E['path'];
|
|
109
120
|
body: O['body'];
|
|
110
121
|
searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
|
|
111
122
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
123
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
|
|
112
124
|
}> : 'searchParams' extends keyof O ? RestType<O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
|
|
113
125
|
path: E['path'];
|
|
114
126
|
body: E['body'];
|
|
115
127
|
searchParams: O['searchParams'];
|
|
116
128
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
129
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
|
|
117
130
|
}> : RestInstance<F, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], {
|
|
118
131
|
path: 'path' extends keyof O ? Exclude<O['path'], undefined> : E['path'];
|
|
119
132
|
body: 'body' extends keyof O ? O['body'] : E['body'];
|
|
120
133
|
searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
|
|
121
134
|
method: 'method' extends keyof O ? O['method'] : E['method'];
|
|
135
|
+
paginationField: 'paginationField' extends keyof O ? O['paginationField'] : E['paginationField'];
|
|
122
136
|
}>;
|
|
123
|
-
export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase
|
|
137
|
+
export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
138
|
+
getPage?: unknown;
|
|
139
|
+
}> = OptionsToRestEndpoint<O, E & (E extends {
|
|
140
|
+
getPage: {
|
|
141
|
+
paginationField: string;
|
|
142
|
+
};
|
|
143
|
+
} ? {
|
|
144
|
+
paginationField: E['getPage']['paginationField'];
|
|
145
|
+
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & Omit<O, KeyofRestEndpoint> & Omit<E, KeyofRestEndpoint | keyof O>;
|
|
124
146
|
export interface PartialRestGenerics {
|
|
147
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#path */
|
|
125
148
|
readonly path?: string;
|
|
149
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#schema */
|
|
126
150
|
readonly schema?: Schema | undefined;
|
|
151
|
+
/** @see https://resthooks.io/rest/api/RestEndpoint#method */
|
|
127
152
|
readonly method?: string;
|
|
128
153
|
/** Only used for types */
|
|
154
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#body */
|
|
129
155
|
body?: any;
|
|
130
156
|
/** Only used for types */
|
|
157
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
|
|
131
158
|
searchParams?: any;
|
|
159
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
|
|
160
|
+
readonly paginationField?: string;
|
|
132
161
|
/** @see https://resthooks.io/rest/api/RestEndpoint#process */
|
|
133
162
|
process?(value: any, ...args: any): any;
|
|
134
163
|
}
|
|
@@ -137,18 +166,20 @@ export interface RestGenerics extends PartialRestGenerics {
|
|
|
137
166
|
}
|
|
138
167
|
export type PaginationEndpoint<E extends FetchFunction & RestGenerics & {
|
|
139
168
|
sideEffect?: true | undefined;
|
|
140
|
-
}, A extends any[]> =
|
|
169
|
+
}, A extends any[]> = RestInstanceBase<ParamFetchNoBody<A[0], ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
141
170
|
searchParams: Omit<A[0], keyof PathArgs<E['path']>>;
|
|
142
171
|
}>;
|
|
143
172
|
export type PaginationFieldEndpoint<E extends FetchFunction & RestGenerics & {
|
|
144
173
|
sideEffect?: true | undefined;
|
|
145
|
-
}, C extends string> =
|
|
174
|
+
}, C extends string> = RestInstanceBase<ParamFetchNoBody<{
|
|
146
175
|
[K in C]: string | number | boolean;
|
|
147
176
|
} & E['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
|
|
148
177
|
searchParams: {
|
|
149
178
|
[K in C]: string | number | boolean;
|
|
150
179
|
} & E['searchParams'];
|
|
151
|
-
}
|
|
180
|
+
}> & {
|
|
181
|
+
paginationField: C;
|
|
182
|
+
};
|
|
152
183
|
export type AddEndpoint<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, O extends {
|
|
153
184
|
path: string;
|
|
154
185
|
body: any;
|
|
@@ -207,8 +238,10 @@ export type RestType<UrlParams = any, Body = any, S extends Schema | undefined =
|
|
|
207
238
|
path: string;
|
|
208
239
|
body?: any;
|
|
209
240
|
searchParams?: any;
|
|
241
|
+
paginationField?: string;
|
|
210
242
|
} = {
|
|
211
243
|
path: string;
|
|
244
|
+
paginationField: string;
|
|
212
245
|
}> = IfTypeScriptLooseNull<RestInstance<keyof UrlParams extends never ? (this: EndpointInstanceInterface, body?: Body) => Promise<R> : {} extends UrlParams ? ((this: EndpointInstanceInterface, body?: Body) => Promise<R>) | ((this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>) : (this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>, S, M, O>, Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O> : RestTypeNoBody<UrlParams, S, M, R, O>>;
|
|
213
246
|
export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, Body = any, R = any /*Denormalize<S>*/, O extends {
|
|
214
247
|
path: string;
|
|
@@ -258,6 +291,7 @@ export type GetEndpoint<O extends {
|
|
|
258
291
|
readonly schema: Schema;
|
|
259
292
|
/** Only used for types */
|
|
260
293
|
readonly searchParams?: any;
|
|
294
|
+
readonly paginationField?: string;
|
|
261
295
|
} = {
|
|
262
296
|
path: string;
|
|
263
297
|
schema: Schema;
|
|
@@ -3,5 +3,5 @@ import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js'
|
|
|
3
3
|
*
|
|
4
4
|
* @see https://resthooks.io/rest/api/createResource
|
|
5
5
|
*/
|
|
6
|
-
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
6
|
+
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, paginationField, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
7
7
|
//# sourceMappingURL=createResource.d.ts.map
|
package/ts4.1/resourceTypes.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface ResourceGenerics {
|
|
|
16
16
|
/** Only used for types */
|
|
17
17
|
/** @see https://resthooks.io/rest/api/createResource#searchParams */
|
|
18
18
|
readonly searchParams?: any;
|
|
19
|
+
/** @see https://resthooks.io/rest/api/createResource#paginationfield */
|
|
20
|
+
readonly paginationField?: string;
|
|
19
21
|
}
|
|
20
22
|
/** The untyped options for createResource() */
|
|
21
23
|
export interface ResourceOptions {
|
|
@@ -67,14 +69,14 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
67
69
|
]>;
|
|
68
70
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
69
71
|
searchParams: O['searchParams'];
|
|
70
|
-
}
|
|
72
|
+
} & Pick<O, 'paginationField'>> : GetEndpoint<{
|
|
71
73
|
path: ShortenPath<O['path']>;
|
|
72
74
|
schema: schema.Collection<[
|
|
73
75
|
O['schema']
|
|
74
76
|
]>;
|
|
75
77
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
76
78
|
searchParams: Record<string, number | string | boolean> | undefined;
|
|
77
|
-
}
|
|
79
|
+
} & Pick<O, 'paginationField'>>;
|
|
78
80
|
/** Create a new item (POST)
|
|
79
81
|
*
|
|
80
82
|
* @deprecated use Resource.getList.push instead
|
|
@@ -103,7 +105,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
103
105
|
schema: O['schema'];
|
|
104
106
|
}> : MutateEndpoint<{
|
|
105
107
|
path: O['path'];
|
|
106
|
-
body: Partial<Denormalize<O['schema']
|
|
108
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
107
109
|
schema: O['schema'];
|
|
108
110
|
}>;
|
|
109
111
|
/** Update an item (PATCH)
|
|
@@ -116,7 +118,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
116
118
|
schema: O['schema'];
|
|
117
119
|
}> : MutateEndpoint<{
|
|
118
120
|
path: O['path'];
|
|
119
|
-
body: Partial<Denormalize<O['schema']
|
|
121
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
120
122
|
schema: O['schema'];
|
|
121
123
|
}>;
|
|
122
124
|
/** Delete an item (DELETE)
|