@data-client/rest 0.1.0 → 0.2.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 +10 -14
- package/dist/index.umd.min.js +1 -1
- package/legacy/OptionsToFunction.js +1 -1
- package/legacy/RestEndpoint.js +5 -5
- package/legacy/createResource.js +8 -10
- package/legacy/index.js +2 -1
- package/legacy/next/index.js +4 -4
- package/legacy/resourceTypes.js +2 -0
- package/lib/OptionsToFunction.d.ts.map +1 -1
- package/lib/OptionsToFunction.js +1 -1
- package/lib/RestEndpoint.d.ts +29 -35
- package/lib/RestEndpoint.js +5 -5
- package/lib/createResource.d.ts +51 -31
- package/lib/createResource.d.ts.map +1 -1
- package/lib/createResource.js +7 -11
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/next/index.d.ts +5 -5
- package/lib/next/index.d.ts.map +1 -1
- package/lib/next/index.js +4 -4
- package/lib/resourceTypes.d.ts.map +1 -0
- package/lib/resourceTypes.js +2 -0
- package/package.json +3 -3
- package/src/OptionsToFunction.ts +0 -1
- package/src/RestEndpoint.d.ts +29 -35
- package/src/RestEndpoint.js +4 -4
- package/src/__tests__/RestEndpoint.ts +38 -9
- package/src/__tests__/createResource.test.ts +3 -4
- package/src/__tests__/hookifyResource.ts +7 -3
- package/src/__tests__/types.test.ts +332 -212
- package/src/createResource.ts +81 -60
- package/src/index.ts +2 -2
- package/src/next/index.ts +5 -5
- package/ts4.0/RestEndpoint.d.ts +18 -32
- package/ts4.0/createResource.d.ts +59 -31
- package/ts4.0/index.d.ts +3 -1
- package/ts4.0/next/index.d.ts +5 -5
- package/legacy/next/OptionsToFunction.js +0 -2
- package/legacy/next/RestEndpoint.js +0 -225
- package/legacy/next/createResource.js +0 -86
- package/legacy/next/resourceTypes.js +0 -2
- package/lib/next/OptionsToFunction.d.ts +0 -7
- package/lib/next/OptionsToFunction.d.ts.map +0 -1
- package/lib/next/OptionsToFunction.js +0 -2
- package/lib/next/RestEndpoint.d.ts +0 -542
- package/lib/next/RestEndpoint.js +0 -229
- package/lib/next/createResource.d.ts +0 -86
- package/lib/next/createResource.d.ts.map +0 -1
- package/lib/next/createResource.js +0 -100
- package/lib/next/resourceTypes.d.ts.map +0 -1
- package/lib/next/resourceTypes.js +0 -2
- package/src/next/OptionsToFunction.ts +0 -41
- package/src/next/RestEndpoint.d.ts +0 -542
- package/src/next/RestEndpoint.js +0 -262
- package/src/next/__tests__/RestEndpoint.ts +0 -1333
- package/src/next/__tests__/__snapshots__/RestEndpoint.ts.snap +0 -18
- package/src/next/__tests__/types.test.ts +0 -429
- package/src/next/createResource.ts +0 -194
- package/ts4.0/next/OptionsToFunction.d.ts +0 -16
- package/ts4.0/next/RestEndpoint.d.ts +0 -226
- package/ts4.0/next/createResource.d.ts +0 -94
- /package/lib/{next/resourceTypes.d.ts → resourceTypes.d.ts} +0 -0
- /package/src/{next/resourceTypes.ts → resourceTypes.ts} +0 -0
- /package/ts4.0/{next/resourceTypes.d.ts → resourceTypes.d.ts} +0 -0
package/src/createResource.ts
CHANGED
|
@@ -1,72 +1,57 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbortOptimistic,
|
|
3
|
-
schema,
|
|
4
3
|
SnapshotInterface,
|
|
4
|
+
schema,
|
|
5
5
|
} from '@data-client/endpoint';
|
|
6
|
-
import type {
|
|
7
|
-
Schema,
|
|
8
|
-
Denormalize,
|
|
9
|
-
EndpointExtraOptions,
|
|
10
|
-
} from '@data-client/endpoint';
|
|
6
|
+
import type { Denormalize } from '@data-client/endpoint';
|
|
11
7
|
|
|
12
8
|
import { PathArgs, ShortenPath } from './pathTypes.js';
|
|
9
|
+
import { ResourceGenerics, ResourceOptions } from './resourceTypes.js';
|
|
13
10
|
import RestEndpoint, {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
RestInstance,
|
|
11
|
+
GetEndpoint,
|
|
12
|
+
MutateEndpoint,
|
|
17
13
|
RestTypeNoBody,
|
|
18
14
|
} from './RestEndpoint.js';
|
|
19
15
|
import { shortenPath } from './RestHelpers.js';
|
|
20
16
|
|
|
21
|
-
const {
|
|
17
|
+
const { Invalidate, Collection } = schema;
|
|
22
18
|
|
|
23
19
|
/** Creates collection of Endpoints for common operations on a given data/schema.
|
|
24
20
|
*
|
|
25
21
|
* @see https://resthooks.io/rest/api/createResource
|
|
26
22
|
*/
|
|
27
|
-
export default function createResource<
|
|
23
|
+
export default function createResource<O extends ResourceGenerics>({
|
|
28
24
|
path,
|
|
29
25
|
schema,
|
|
30
26
|
Endpoint = RestEndpoint,
|
|
31
27
|
optimistic,
|
|
32
28
|
...extraOptions
|
|
33
|
-
}: {
|
|
34
|
-
readonly path: U;
|
|
35
|
-
readonly schema: S;
|
|
36
|
-
readonly Endpoint?: typeof RestEndpoint;
|
|
37
|
-
urlPrefix?: string;
|
|
38
|
-
optimistic?: boolean;
|
|
39
|
-
} & EndpointExtraOptions): Resource<U, S> {
|
|
29
|
+
}: Readonly<O> & ResourceOptions): Resource<O> {
|
|
40
30
|
const shortenedPath = shortenPath(path);
|
|
41
31
|
const getName = (name: string) => `${(schema as any)?.name}.${name}`;
|
|
42
32
|
const extraMutateOptions = { ...extraOptions };
|
|
43
33
|
const extraPartialOptions = { ...extraOptions };
|
|
44
|
-
const get:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
const get: GetEndpoint<{ path: O['path']; schema: O['schema'] }> =
|
|
35
|
+
new Endpoint({
|
|
36
|
+
...extraOptions,
|
|
37
|
+
path,
|
|
38
|
+
schema,
|
|
39
|
+
name: getName('get'),
|
|
40
|
+
}) as any;
|
|
50
41
|
if (optimistic) {
|
|
51
42
|
(extraMutateOptions as any).getOptimisticResponse = optimisticUpdate;
|
|
52
43
|
(extraPartialOptions as any).getOptimisticResponse = optimisticPartial(get);
|
|
53
44
|
}
|
|
54
45
|
const getList = new Endpoint({
|
|
55
|
-
...
|
|
46
|
+
...extraMutateOptions,
|
|
56
47
|
path: shortenedPath,
|
|
57
|
-
schema: [schema],
|
|
48
|
+
schema: new Collection([schema as any]),
|
|
58
49
|
name: getName('getList'),
|
|
59
50
|
});
|
|
60
51
|
return {
|
|
61
52
|
get,
|
|
62
53
|
getList,
|
|
63
|
-
create:
|
|
64
|
-
...extraMutateOptions,
|
|
65
|
-
path: shortenedPath,
|
|
66
|
-
schema,
|
|
67
|
-
method: 'POST',
|
|
68
|
-
name: getName('create'),
|
|
69
|
-
}),
|
|
54
|
+
create: getList.push.extend({ name: getName('create') }),
|
|
70
55
|
update: new Endpoint({
|
|
71
56
|
...extraMutateOptions,
|
|
72
57
|
path,
|
|
@@ -84,10 +69,10 @@ export default function createResource<U extends string, S extends Schema>({
|
|
|
84
69
|
delete: new Endpoint({
|
|
85
70
|
...extraMutateOptions,
|
|
86
71
|
path,
|
|
87
|
-
schema: (schema as any).process ? new
|
|
72
|
+
schema: (schema as any).process ? new Invalidate(schema as any) : schema,
|
|
88
73
|
method: 'DELETE',
|
|
89
74
|
name: getName('delete'),
|
|
90
|
-
process(res, params) {
|
|
75
|
+
process(res: any, params: any) {
|
|
91
76
|
return res && Object.keys(res).length ? res : params;
|
|
92
77
|
},
|
|
93
78
|
getOptimisticResponse: optimistic ? (optimisticDelete as any) : undefined,
|
|
@@ -98,13 +83,12 @@ export default function createResource<U extends string, S extends Schema>({
|
|
|
98
83
|
function optimisticUpdate(snap: SnapshotInterface, params: any, body: any) {
|
|
99
84
|
return {
|
|
100
85
|
...params,
|
|
101
|
-
// even tho we don't always have two arguments, the extra one will simply be undefined which spreads fine
|
|
102
86
|
...body,
|
|
103
87
|
};
|
|
104
88
|
}
|
|
105
|
-
function optimisticPartial(getEndpoint:
|
|
89
|
+
function optimisticPartial(getEndpoint: GetEndpoint) {
|
|
106
90
|
return function (snap: SnapshotInterface, params: any, body: any) {
|
|
107
|
-
const { data } = snap.getResponse(getEndpoint, params);
|
|
91
|
+
const { data } = snap.getResponse(getEndpoint, params) as { data: any };
|
|
108
92
|
if (!data) throw new AbortOptimistic();
|
|
109
93
|
return {
|
|
110
94
|
...params,
|
|
@@ -118,55 +102,92 @@ function optimisticDelete(snap: SnapshotInterface, params: any) {
|
|
|
118
102
|
return params;
|
|
119
103
|
}
|
|
120
104
|
|
|
121
|
-
export interface Resource<
|
|
105
|
+
export interface Resource<
|
|
106
|
+
O extends ResourceGenerics = { path: string; schema: any },
|
|
107
|
+
> {
|
|
122
108
|
/** Get a singular item
|
|
123
109
|
*
|
|
124
110
|
* @see https://resthooks.io/rest/api/createResource#get
|
|
125
111
|
*/
|
|
126
|
-
get:
|
|
112
|
+
get: GetEndpoint<{ path: O['path']; schema: O['schema'] }>;
|
|
127
113
|
/** Get a list of item
|
|
128
114
|
*
|
|
129
115
|
* @see https://resthooks.io/rest/api/createResource#getlist
|
|
130
116
|
*/
|
|
131
|
-
getList:
|
|
132
|
-
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
117
|
+
getList: 'searchParams' extends keyof O
|
|
118
|
+
? GetEndpoint<{
|
|
119
|
+
path: ShortenPath<O['path']>;
|
|
120
|
+
schema: schema.Collection<[O['schema']]>;
|
|
121
|
+
searchParams: O['searchParams'];
|
|
122
|
+
}>
|
|
123
|
+
: GetEndpoint<{
|
|
124
|
+
path: ShortenPath<O['path']>;
|
|
125
|
+
schema: schema.Collection<[O['schema']]>;
|
|
126
|
+
searchParams: Record<string, number | string | boolean> | undefined;
|
|
127
|
+
}>;
|
|
138
128
|
/** Create a new item (POST)
|
|
139
129
|
*
|
|
140
130
|
* @see https://resthooks.io/rest/api/createResource#create
|
|
141
131
|
*/
|
|
142
|
-
create:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
create: 'searchParams' extends keyof O
|
|
133
|
+
? MutateEndpoint<{
|
|
134
|
+
path: ShortenPath<O['path']>;
|
|
135
|
+
schema: schema.Collection<[O['schema']]>['push'];
|
|
136
|
+
body: 'body' extends keyof O
|
|
137
|
+
? O['body']
|
|
138
|
+
: Partial<Denormalize<O['schema']>>;
|
|
139
|
+
searchParams: O['searchParams'];
|
|
140
|
+
}>
|
|
141
|
+
: MutateEndpoint<{
|
|
142
|
+
path: ShortenPath<O['path']>;
|
|
143
|
+
schema: schema.Collection<[O['schema']]>['push'];
|
|
144
|
+
body: 'body' extends keyof O
|
|
145
|
+
? O['body']
|
|
146
|
+
: Partial<Denormalize<O['schema']>>;
|
|
147
|
+
}>;
|
|
146
148
|
/** Update an item (PUT)
|
|
147
149
|
*
|
|
148
150
|
* @see https://resthooks.io/rest/api/createResource#update
|
|
149
151
|
*/
|
|
150
|
-
update:
|
|
152
|
+
update: 'body' extends keyof O
|
|
153
|
+
? MutateEndpoint<{
|
|
154
|
+
path: O['path'];
|
|
155
|
+
body: O['body'];
|
|
156
|
+
schema: O['schema'];
|
|
157
|
+
}>
|
|
158
|
+
: MutateEndpoint<{
|
|
159
|
+
path: O['path'];
|
|
160
|
+
body: Partial<Denormalize<O['schema']>>;
|
|
161
|
+
schema: O['schema'];
|
|
162
|
+
}>;
|
|
151
163
|
/** Update an item (PATCH)
|
|
152
164
|
*
|
|
153
165
|
* @see https://resthooks.io/rest/api/createResource#partialupdate
|
|
154
166
|
*/
|
|
155
|
-
partialUpdate:
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
167
|
+
partialUpdate: 'body' extends keyof O
|
|
168
|
+
? MutateEndpoint<{
|
|
169
|
+
path: O['path'];
|
|
170
|
+
body: Partial<O['body']>;
|
|
171
|
+
schema: O['schema'];
|
|
172
|
+
}>
|
|
173
|
+
: MutateEndpoint<{
|
|
174
|
+
path: O['path'];
|
|
175
|
+
body: Partial<Denormalize<O['schema']>>;
|
|
176
|
+
schema: O['schema'];
|
|
177
|
+
}>;
|
|
159
178
|
/** Delete an item (DELETE)
|
|
160
179
|
*
|
|
161
180
|
* @see https://resthooks.io/rest/api/createResource#delete
|
|
162
181
|
*/
|
|
163
182
|
delete: RestTypeNoBody<
|
|
164
|
-
PathArgs<
|
|
165
|
-
|
|
183
|
+
PathArgs<O['path']>,
|
|
184
|
+
O['schema'] extends schema.EntityInterface & { process: any }
|
|
185
|
+
? schema.Invalidate<O['schema']>
|
|
186
|
+
: O['schema'],
|
|
166
187
|
undefined,
|
|
167
|
-
Partial<PathArgs<
|
|
188
|
+
Partial<PathArgs<O['path']>>,
|
|
168
189
|
{
|
|
169
|
-
path:
|
|
190
|
+
path: O['path'];
|
|
170
191
|
}
|
|
171
192
|
>;
|
|
172
193
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,8 +7,6 @@ export { default as RestEndpoint } from './RestEndpoint.js';
|
|
|
7
7
|
export type {
|
|
8
8
|
GetEndpoint,
|
|
9
9
|
MutateEndpoint,
|
|
10
|
-
NewGetEndpoint,
|
|
11
|
-
NewMutateEndpoint,
|
|
12
10
|
Defaults,
|
|
13
11
|
RestGenerics,
|
|
14
12
|
FetchGet,
|
|
@@ -23,6 +21,7 @@ export type {
|
|
|
23
21
|
} from './RestEndpoint.js';
|
|
24
22
|
export { default as createResource } from './createResource.js';
|
|
25
23
|
export type { Resource } from './createResource.js';
|
|
24
|
+
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
|
26
25
|
export { default as hookifyResource } from './hookifyResource.js';
|
|
27
26
|
export type {
|
|
28
27
|
HookResource,
|
|
@@ -40,3 +39,4 @@ export type {
|
|
|
40
39
|
} from './pathTypes.js';
|
|
41
40
|
|
|
42
41
|
export * from '@data-client/endpoint';
|
|
42
|
+
export * from './RestEndpoint.js';
|
package/src/next/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export { default as RestEndpoint } from '
|
|
3
|
-
export { default as createResource } from '
|
|
4
|
-
export type { Resource } from '
|
|
5
|
-
export type { ResourceOptions, ResourceGenerics } from '
|
|
1
|
+
export * from '../RestEndpoint.js';
|
|
2
|
+
export { default as RestEndpoint } from '../RestEndpoint.js';
|
|
3
|
+
export { default as createResource } from '../createResource.js';
|
|
4
|
+
export type { Resource } from '../createResource.js';
|
|
5
|
+
export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
|
package/ts4.0/RestEndpoint.d.ts
CHANGED
|
@@ -28,9 +28,9 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
28
28
|
/* before-fetch */
|
|
29
29
|
url(...args: Parameters<F>): string;
|
|
30
30
|
/** @see https://resthooks.io/rest/api/RestEndpoint#getRequestInit */
|
|
31
|
-
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): RequestInit;
|
|
31
|
+
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
|
|
32
32
|
/** @see https://resthooks.io/rest/api/RestEndpoint#getHeaders */
|
|
33
|
-
getHeaders(headers: HeadersInit): HeadersInit;
|
|
33
|
+
getHeaders(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
|
|
34
34
|
/* after-fetch */
|
|
35
35
|
/** @see https://resthooks.io/rest/api/RestEndpoint#fetchResponse */
|
|
36
36
|
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
@@ -63,25 +63,6 @@ export interface RestInstance<F extends FetchFunction = FetchFunction, S extends
|
|
|
63
63
|
unshift: AddEndpoint<F, S, O>;
|
|
64
64
|
assign: AddEndpoint<F, S, O>;
|
|
65
65
|
}
|
|
66
|
-
export type ContainsCollectionArray = {
|
|
67
|
-
push: any;
|
|
68
|
-
unshift: any;
|
|
69
|
-
} | {
|
|
70
|
-
[K: string]: ContainsCollectionArray;
|
|
71
|
-
} | {
|
|
72
|
-
schema: {
|
|
73
|
-
[K: string]: ContainsCollectionArray;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
export type ContainsCollectionValues = {
|
|
77
|
-
assign: any;
|
|
78
|
-
} | {
|
|
79
|
-
[K: string]: ContainsCollectionValues;
|
|
80
|
-
} | {
|
|
81
|
-
schema: {
|
|
82
|
-
[K: string]: ContainsCollectionValues;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
66
|
export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends RestInstanceBase, 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>>;
|
|
86
67
|
type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
|
|
87
68
|
body?: any;
|
|
@@ -217,24 +198,29 @@ export type FetchMutate<A extends readonly any[] = [
|
|
|
217
198
|
export type FetchGet<A extends readonly any[] = [
|
|
218
199
|
any
|
|
219
200
|
], R = any> = (this: RestInstance, ...args: A) => Promise<R>;
|
|
220
|
-
export type GetEndpoint<UrlParams = any, S extends Schema | undefined = Schema | undefined> = RestTypeNoBody<UrlParams, S, undefined>;
|
|
221
|
-
export type MutateEndpoint<UrlParams = any, Body extends BodyInit | Record<string, any> = any, S extends Schema | undefined = Schema | undefined> = RestTypeWithBody<UrlParams, S, true, Body>;
|
|
222
201
|
export type Defaults<O, D> = {
|
|
223
202
|
[K in keyof O | keyof D]: K extends keyof O ? Exclude<O[K], undefined> : D[Extract<K, keyof D>];
|
|
224
203
|
};
|
|
225
|
-
export type
|
|
226
|
-
path: string;
|
|
227
|
-
|
|
204
|
+
export type GetEndpoint<O extends {
|
|
205
|
+
readonly path: string;
|
|
206
|
+
readonly schema: Schema;
|
|
207
|
+
/** Only used for types */
|
|
208
|
+
readonly searchParams?: any;
|
|
228
209
|
} = {
|
|
229
210
|
path: string;
|
|
230
|
-
|
|
211
|
+
schema: Schema;
|
|
212
|
+
}> = RestTypeNoBody<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<O['path']> : O['searchParams'] & PathArgs<O['path']> : PathArgs<O['path']>, O['schema'], undefined, any, O & {
|
|
231
213
|
body: undefined;
|
|
232
214
|
}>;
|
|
233
|
-
export type
|
|
234
|
-
path: string;
|
|
235
|
-
|
|
236
|
-
|
|
215
|
+
export type MutateEndpoint<O extends {
|
|
216
|
+
readonly path: string;
|
|
217
|
+
readonly schema: Schema;
|
|
218
|
+
/** Only used for types */
|
|
219
|
+
readonly searchParams?: any;
|
|
220
|
+
/** Only used for types */
|
|
221
|
+
readonly body?: any;
|
|
237
222
|
} = {
|
|
238
223
|
path: string;
|
|
239
224
|
body: any;
|
|
240
|
-
|
|
225
|
+
schema: Schema;
|
|
226
|
+
}> = RestTypeWithBody<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<O['path']> : O['searchParams'] & PathArgs<O['path']> : PathArgs<O['path']>, O['schema'], true, O['body'], any, O>;
|
|
@@ -1,66 +1,94 @@
|
|
|
1
1
|
import { schema } from '@data-client/endpoint';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Denormalize } from '@data-client/endpoint';
|
|
3
3
|
import { PathArgs, ShortenPath } from './pathTypes.js';
|
|
4
|
-
import
|
|
4
|
+
import { ResourceGenerics, ResourceOptions } from './resourceTypes.js';
|
|
5
|
+
import { GetEndpoint, MutateEndpoint, RestTypeNoBody } from './RestEndpoint.js';
|
|
5
6
|
/** Creates collection of Endpoints for common operations on a given data/schema.
|
|
6
7
|
*
|
|
7
8
|
* @see https://resthooks.io/rest/api/createResource
|
|
8
9
|
*/
|
|
9
|
-
export default function createResource<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
optimistic?: boolean;
|
|
15
|
-
} & EndpointExtraOptions): Resource<U, S>;
|
|
16
|
-
export interface Resource<U extends string, S extends Schema> {
|
|
10
|
+
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, optimistic, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
11
|
+
export interface Resource<O extends ResourceGenerics = {
|
|
12
|
+
path: string;
|
|
13
|
+
schema: any;
|
|
14
|
+
}> {
|
|
17
15
|
/** Get a singular item
|
|
18
16
|
*
|
|
19
17
|
* @see https://resthooks.io/rest/api/createResource#get
|
|
20
18
|
*/
|
|
21
|
-
get:
|
|
22
|
-
path:
|
|
23
|
-
|
|
19
|
+
get: GetEndpoint<{
|
|
20
|
+
path: O['path'];
|
|
21
|
+
schema: O['schema'];
|
|
22
|
+
}>;
|
|
24
23
|
/** Get a list of item
|
|
25
24
|
*
|
|
26
25
|
* @see https://resthooks.io/rest/api/createResource#getlist
|
|
27
26
|
*/
|
|
28
|
-
getList:
|
|
29
|
-
path: ShortenPath<
|
|
27
|
+
getList: 'searchParams' extends keyof O ? GetEndpoint<{
|
|
28
|
+
path: ShortenPath<O['path']>;
|
|
29
|
+
schema: schema.Collection<[
|
|
30
|
+
O['schema']
|
|
31
|
+
]>;
|
|
32
|
+
searchParams: O['searchParams'];
|
|
33
|
+
}> : GetEndpoint<{
|
|
34
|
+
path: ShortenPath<O['path']>;
|
|
35
|
+
schema: schema.Collection<[
|
|
36
|
+
O['schema']
|
|
37
|
+
]>;
|
|
30
38
|
searchParams: Record<string, number | string | boolean> | undefined;
|
|
31
|
-
}
|
|
39
|
+
}>;
|
|
32
40
|
/** Create a new item (POST)
|
|
33
41
|
*
|
|
34
42
|
* @see https://resthooks.io/rest/api/createResource#create
|
|
35
43
|
*/
|
|
36
|
-
create:
|
|
37
|
-
path: ShortenPath<
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
create: 'searchParams' extends keyof O ? MutateEndpoint<{
|
|
45
|
+
path: ShortenPath<O['path']>;
|
|
46
|
+
schema: schema.Collection<[
|
|
47
|
+
O['schema']
|
|
48
|
+
]>['push'];
|
|
49
|
+
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
50
|
+
searchParams: O['searchParams'];
|
|
51
|
+
}> : MutateEndpoint<{
|
|
52
|
+
path: ShortenPath<O['path']>;
|
|
53
|
+
schema: schema.Collection<[
|
|
54
|
+
O['schema']
|
|
55
|
+
]>['push'];
|
|
56
|
+
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
57
|
+
}>;
|
|
40
58
|
/** Update an item (PUT)
|
|
41
59
|
*
|
|
42
60
|
* @see https://resthooks.io/rest/api/createResource#update
|
|
43
61
|
*/
|
|
44
|
-
update:
|
|
45
|
-
path:
|
|
46
|
-
body:
|
|
47
|
-
|
|
62
|
+
update: 'body' extends keyof O ? MutateEndpoint<{
|
|
63
|
+
path: O['path'];
|
|
64
|
+
body: O['body'];
|
|
65
|
+
schema: O['schema'];
|
|
66
|
+
}> : MutateEndpoint<{
|
|
67
|
+
path: O['path'];
|
|
68
|
+
body: Partial<Denormalize<O['schema']>>;
|
|
69
|
+
schema: O['schema'];
|
|
70
|
+
}>;
|
|
48
71
|
/** Update an item (PATCH)
|
|
49
72
|
*
|
|
50
73
|
* @see https://resthooks.io/rest/api/createResource#partialupdate
|
|
51
74
|
*/
|
|
52
|
-
partialUpdate:
|
|
53
|
-
path:
|
|
54
|
-
body: Partial<
|
|
55
|
-
|
|
75
|
+
partialUpdate: 'body' extends keyof O ? MutateEndpoint<{
|
|
76
|
+
path: O['path'];
|
|
77
|
+
body: Partial<O['body']>;
|
|
78
|
+
schema: O['schema'];
|
|
79
|
+
}> : MutateEndpoint<{
|
|
80
|
+
path: O['path'];
|
|
81
|
+
body: Partial<Denormalize<O['schema']>>;
|
|
82
|
+
schema: O['schema'];
|
|
83
|
+
}>;
|
|
56
84
|
/** Delete an item (DELETE)
|
|
57
85
|
*
|
|
58
86
|
* @see https://resthooks.io/rest/api/createResource#delete
|
|
59
87
|
*/
|
|
60
|
-
delete: RestTypeNoBody<PathArgs<
|
|
88
|
+
delete: RestTypeNoBody<PathArgs<O['path']>, O['schema'] extends schema.EntityInterface & {
|
|
61
89
|
process: any;
|
|
62
|
-
} ? schema.
|
|
63
|
-
path:
|
|
90
|
+
} ? schema.Invalidate<O['schema']> : O['schema'], undefined, Partial<PathArgs<O['path']>>, {
|
|
91
|
+
path: O['path'];
|
|
64
92
|
}>;
|
|
65
93
|
}
|
|
66
94
|
//# sourceMappingURL=createResource.d.ts.map
|
package/ts4.0/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { default as RestEndpoint } from './RestEndpoint.js';
|
|
2
|
-
export type { GetEndpoint, MutateEndpoint,
|
|
2
|
+
export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, } from './RestEndpoint.js';
|
|
3
3
|
export { default as createResource } from './createResource.js';
|
|
4
4
|
export type { Resource } from './createResource.js';
|
|
5
|
+
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
|
5
6
|
export { default as hookifyResource } from './hookifyResource.js';
|
|
6
7
|
export type { HookResource, HookableEndpointInterface, } from './hookifyResource.js';
|
|
7
8
|
export { default as NetworkError } from './NetworkError.js';
|
|
@@ -9,4 +10,5 @@ export { default as paginationUpdate } from './paginationUpdate.js';
|
|
|
9
10
|
export type { OptionsToFunction } from './OptionsToFunction.js';
|
|
10
11
|
export type { ShortenPath, PathArgs, PathKeys, KeysToArgs, PathArgsAndSearch, } from './pathTypes.js';
|
|
11
12
|
export * from '@data-client/endpoint';
|
|
13
|
+
export * from './RestEndpoint.js';
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
package/ts4.0/next/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export { default as RestEndpoint } from '
|
|
3
|
-
export { default as createResource } from '
|
|
4
|
-
export type { Resource } from '
|
|
5
|
-
export type { ResourceOptions, ResourceGenerics } from '
|
|
1
|
+
export * from '../RestEndpoint.js';
|
|
2
|
+
export { default as RestEndpoint } from '../RestEndpoint.js';
|
|
3
|
+
export { default as createResource } from '../createResource.js';
|
|
4
|
+
export type { Resource } from '../createResource.js';
|
|
5
|
+
export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vc3JjL25leHQvT3B0aW9uc1RvRnVuY3Rpb24udHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUgeyBGZXRjaEZ1bmN0aW9uLCBSZXNvbHZlVHlwZSB9IGZyb20gJ0BkYXRhLWNsaWVudC9lbmRwb2ludCc7XG5cbmltcG9ydCB7XG4gIFBhcnRpYWxSZXN0R2VuZXJpY3MsXG4gIFJlc3RJbnN0YW5jZUJhc2UsXG4gIFJlc3RGZXRjaCxcbn0gZnJvbSAnLi9SZXN0RW5kcG9pbnQuanMnO1xuaW1wb3J0IHsgUGF0aEFyZ3MgfSBmcm9tICcuLi9wYXRoVHlwZXMuanMnO1xuXG5leHBvcnQgdHlwZSBPcHRpb25zVG9GdW5jdGlvbjxcbiAgTyBleHRlbmRzIFBhcnRpYWxSZXN0R2VuZXJpY3MsXG4gIEUgZXh0ZW5kcyBSZXN0SW5zdGFuY2VCYXNlICYgeyBib2R5PzogYW55IH0sXG4gIEYgZXh0ZW5kcyBGZXRjaEZ1bmN0aW9uLFxuPiA9ICdwYXRoJyBleHRlbmRzIGtleW9mIE9cbiAgPyBSZXN0RmV0Y2g8XG4gICAgICAnc2VhcmNoUGFyYW1zJyBleHRlbmRzIGtleW9mIE9cbiAgICAgICAgPyBPWydzZWFyY2hQYXJhbXMnXSAmIFBhdGhBcmdzPEV4Y2x1ZGU8T1sncGF0aCddLCB1bmRlZmluZWQ+PlxuICAgICAgICA6IFBhdGhBcmdzPEV4Y2x1ZGU8T1sncGF0aCddLCB1bmRlZmluZWQ+PixcbiAgICAgICdib2R5JyBleHRlbmRzIGtleW9mIE8gPyBPWydib2R5J10gOiBFWydib2R5J10sXG4gICAgICBPWydwcm9jZXNzJ10gZXh0ZW5kcyB7fSA/IFJldHVyblR5cGU8T1sncHJvY2VzcyddPiA6IFJlc29sdmVUeXBlPEY+XG4gICAgPlxuICA6ICdib2R5JyBleHRlbmRzIGtleW9mIE9cbiAgPyBSZXN0RmV0Y2g8XG4gICAgICAnc2VhcmNoUGFyYW1zJyBleHRlbmRzIGtleW9mIE9cbiAgICAgICAgPyBPWydzZWFyY2hQYXJhbXMnXSAmIFBhdGhBcmdzPEV4Y2x1ZGU8RVsncGF0aCddLCB1bmRlZmluZWQ+PlxuICAgICAgICA6IFBhdGhBcmdzPEV4Y2x1ZGU8RVsncGF0aCddLCB1bmRlZmluZWQ+PixcbiAgICAgIE9bJ2JvZHknXSxcbiAgICAgIE9bJ3Byb2Nlc3MnXSBleHRlbmRzIHt9ID8gUmV0dXJuVHlwZTxPWydwcm9jZXNzJ10+IDogUmVzb2x2ZVR5cGU8Rj5cbiAgICA+XG4gIDogJ3NlYXJjaFBhcmFtcycgZXh0ZW5kcyBrZXlvZiBPXG4gID8gUmVzdEZldGNoPFxuICAgICAgT1snc2VhcmNoUGFyYW1zJ10gJiBQYXRoQXJnczxFeGNsdWRlPEVbJ3BhdGgnXSwgdW5kZWZpbmVkPj4sXG4gICAgICBFWydib2R5J10sXG4gICAgICBPWydwcm9jZXNzJ10gZXh0ZW5kcyB7fSA/IFJldHVyblR5cGU8T1sncHJvY2VzcyddPiA6IFJlc29sdmVUeXBlPEY+XG4gICAgPlxuICA6IChcbiAgICAgIHRoaXM6IFRoaXNQYXJhbWV0ZXJUeXBlPEY+LFxuICAgICAgLi4uYXJnczogUGFyYW1ldGVyczxGPlxuICAgICkgPT4gUHJvbWlzZTxcbiAgICAgIE9bJ3Byb2Nlc3MnXSBleHRlbmRzIHt9ID8gUmV0dXJuVHlwZTxPWydwcm9jZXNzJ10+IDogUmVzb2x2ZVR5cGU8Rj5cbiAgICA+O1xuIl0sIm1hcHBpbmdzIjoiIn0=
|