@data-client/rest 0.9.8 → 0.10.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/README.md +16 -0
- package/dist/index.js +8 -1
- package/dist/index.umd.min.js +1 -1
- package/legacy/OptionsToFunction.js +1 -1
- package/legacy/RestEndpoint.js +7 -2
- package/legacy/RestEndpointTypeHelp.js +1 -1
- package/legacy/RestEndpointTypes.js +1 -1
- package/legacy/createResource.js +1 -1
- package/legacy/extractCollection.js +1 -1
- package/legacy/index.js +2 -1
- package/legacy/mapCollection.js +1 -1
- package/legacy/paramsToString.js +1 -1
- package/legacy/paramsToString.native.js +1 -1
- package/legacy/pathTypes.js +1 -1
- package/legacy/resourceExtensionTypes.js +1 -1
- package/legacy/resourceTypes.js +1 -1
- package/legacy/utiltypes.js +1 -1
- package/lib/OptionsToFunction.d.ts.map +1 -1
- package/lib/OptionsToFunction.js +1 -1
- package/lib/RestEndpoint.js +7 -2
- package/lib/RestEndpointTypeHelp.d.ts.map +1 -1
- package/lib/RestEndpointTypeHelp.js +1 -1
- package/lib/RestEndpointTypes.d.ts +29 -7
- package/lib/RestEndpointTypes.d.ts.map +1 -1
- package/lib/RestEndpointTypes.js +1 -1
- package/lib/createResource.js +1 -1
- package/lib/extractCollection.d.ts +2 -2
- package/lib/extractCollection.d.ts.map +1 -1
- package/lib/extractCollection.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/mapCollection.d.ts.map +1 -1
- package/lib/mapCollection.js +1 -1
- package/lib/paramsToString.d.ts +1 -1
- package/lib/paramsToString.d.ts.map +1 -1
- package/lib/paramsToString.js +1 -1
- package/lib/paramsToString.native.d.ts +1 -1
- package/lib/paramsToString.native.d.ts.map +1 -1
- package/lib/paramsToString.native.js +1 -1
- package/lib/pathTypes.d.ts.map +1 -1
- package/lib/pathTypes.js +1 -1
- package/lib/resourceExtensionTypes.d.ts.map +1 -1
- package/lib/resourceExtensionTypes.js +1 -1
- package/lib/resourceTypes.d.ts.map +1 -1
- package/lib/resourceTypes.js +1 -1
- package/lib/utiltypes.d.ts.map +1 -1
- package/lib/utiltypes.js +1 -1
- package/package.json +4 -2
- package/src/OptionsToFunction.ts +17 -15
- package/src/RestEndpoint.js +9 -4
- package/src/RestEndpointTypeHelp.ts +2 -3
- package/src/RestEndpointTypes.ts +173 -178
- package/src/__tests__/RestEndpoint.ts +54 -2
- package/src/createResource.ts +2 -2
- package/src/extractCollection.ts +13 -13
- package/src/index.ts +1 -0
- package/src/mapCollection.ts +14 -21
- package/src/paramsToString.native.ts +6 -1
- package/src/paramsToString.ts +7 -2
- package/src/pathTypes.ts +27 -36
- package/src/resourceExtensionTypes.ts +33 -48
- package/src/resourceTypes.ts +76 -80
- package/src/utiltypes.ts +3 -3
- package/ts4.0/RestEndpointTypes.d.ts +29 -7
- package/ts4.0/extractCollection.d.ts +2 -2
- package/ts4.0/index.d.ts +1 -0
- package/ts4.0/paramsToString.d.ts +1 -1
- package/ts4.0/paramsToString.native.d.ts +1 -1
- package/ts4.1/RestEndpointTypes.d.ts +29 -7
- package/ts4.1/extractCollection.d.ts +2 -2
- package/ts4.1/index.d.ts +1 -0
- package/ts4.1/paramsToString.d.ts +1 -1
- package/ts4.1/paramsToString.native.d.ts +1 -1
|
@@ -761,7 +761,7 @@ describe('RestEndpoint', () => {
|
|
|
761
761
|
() => useSuspense(getUser);
|
|
762
762
|
});
|
|
763
763
|
|
|
764
|
-
it('should work with extends', async () => {
|
|
764
|
+
it('update should work with extends', async () => {
|
|
765
765
|
mynock.put('/6/user/5').reply(200, (uri, body: any) => ({
|
|
766
766
|
id: 5,
|
|
767
767
|
username: 'charles',
|
|
@@ -792,7 +792,7 @@ describe('RestEndpoint', () => {
|
|
|
792
792
|
`);
|
|
793
793
|
});
|
|
794
794
|
|
|
795
|
-
it('should work with extends', async () => {
|
|
795
|
+
it('get should work with extends', async () => {
|
|
796
796
|
mynock.get('/6/user/5').reply(200, (uri, body: any) => ({
|
|
797
797
|
id: 5,
|
|
798
798
|
username2: 'charles',
|
|
@@ -961,7 +961,59 @@ describe('RestEndpoint', () => {
|
|
|
961
961
|
).toMatchInlineSnapshot(`"/users?bigger=true"`);
|
|
962
962
|
expect(searchParams4.url()).toMatchInlineSnapshot(`"/users"`);
|
|
963
963
|
});
|
|
964
|
+
|
|
965
|
+
it('should work with custom searchToString', async () => {
|
|
966
|
+
class SearchEndpoint<O extends RestGenerics = any> extends MyEndpoint<O> {
|
|
967
|
+
searchToString(searchParams: Record<string, any>) {
|
|
968
|
+
return super.searchToString({ ...searchParams, bob: 5 });
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
mynock.get('/6/user/5').reply(200, (uri, body: any) => ({
|
|
973
|
+
id: 5,
|
|
974
|
+
username2: 'charles',
|
|
975
|
+
...body,
|
|
976
|
+
}));
|
|
977
|
+
class User2 extends Entity {
|
|
978
|
+
readonly id: number | undefined = undefined;
|
|
979
|
+
readonly username2: string = '';
|
|
980
|
+
readonly email: string = '';
|
|
981
|
+
readonly isAdmin: boolean = false;
|
|
982
|
+
|
|
983
|
+
pk() {
|
|
984
|
+
return this.id?.toString();
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
const getUserBase = new SearchEndpoint({
|
|
989
|
+
method: 'GET',
|
|
990
|
+
path: 'http\\://test.com/user/:id',
|
|
991
|
+
name: 'getuser',
|
|
992
|
+
schema: User,
|
|
993
|
+
});
|
|
994
|
+
const getUser = getUserBase.extend({
|
|
995
|
+
path: 'http\\://test.com/:group/user/:id',
|
|
996
|
+
schema: User2,
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
const searchParams = getUser.extend({
|
|
1000
|
+
path: 'http\\://test.com/:group/user/:id',
|
|
1001
|
+
searchParams: {} as { isAdmin?: boolean; sort: 'asc' | 'desc' },
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
expect(
|
|
1005
|
+
searchParams.url({
|
|
1006
|
+
group: 'hi',
|
|
1007
|
+
id: 'what',
|
|
1008
|
+
sort: 'desc',
|
|
1009
|
+
isAdmin: true,
|
|
1010
|
+
}),
|
|
1011
|
+
).toMatchInlineSnapshot(
|
|
1012
|
+
`"http://test.com/hi/user/what?bob=5&isAdmin=true&sort=desc"`,
|
|
1013
|
+
);
|
|
1014
|
+
});
|
|
964
1015
|
});
|
|
1016
|
+
|
|
965
1017
|
it('extending with name should work', () => {
|
|
966
1018
|
const endpoint = CoolerArticleResource.get.extend({ name: 'mything' });
|
|
967
1019
|
const endpoint2 = CoolerArticleResource.get.extend({ path: '/:bob' });
|
package/src/createResource.ts
CHANGED
|
@@ -159,7 +159,7 @@ function optimisticDelete(snap: SnapshotInterface, params: any) {
|
|
|
159
159
|
return params;
|
|
160
160
|
}
|
|
161
161
|
function ensurePojo(body: any) {
|
|
162
|
-
return body instanceof FormData
|
|
163
|
-
|
|
162
|
+
return body instanceof FormData ?
|
|
163
|
+
Object.fromEntries((body as any).entries())
|
|
164
164
|
: body;
|
|
165
165
|
}
|
package/src/extractCollection.ts
CHANGED
|
@@ -20,17 +20,17 @@ export default function extractCollection<
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export type ExtractCollection<S extends Schema | undefined> =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
?
|
|
32
|
-
|
|
33
|
-
?
|
|
34
|
-
: S extends { [K: string]:
|
|
35
|
-
? ExtractObject<S>
|
|
23
|
+
export type ExtractCollection<S extends Schema | undefined> =
|
|
24
|
+
S extends (
|
|
25
|
+
{
|
|
26
|
+
push: any;
|
|
27
|
+
unshift: any;
|
|
28
|
+
assign: any;
|
|
29
|
+
schema: Schema;
|
|
30
|
+
}
|
|
31
|
+
) ?
|
|
32
|
+
S
|
|
33
|
+
: S extends schema.Object<infer T> ? ExtractObject<T>
|
|
34
|
+
: S extends Exclude<Schema, { [K: string]: any }> ? never
|
|
35
|
+
: S extends { [K: string]: Schema } ? ExtractObject<S>
|
|
36
36
|
: never;
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type {
|
|
|
20
20
|
PaginationFieldEndpoint,
|
|
21
21
|
PaginationEndpoint,
|
|
22
22
|
} from './RestEndpoint.js';
|
|
23
|
+
export { getUrlBase, getUrlTokens } from './RestHelpers.js';
|
|
23
24
|
export { default as createResource } from './createResource.js';
|
|
24
25
|
export type { Resource } from './resourceTypes.js';
|
|
25
26
|
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
package/src/mapCollection.ts
CHANGED
|
@@ -6,21 +6,16 @@ export default function mapCollection<
|
|
|
6
6
|
>(
|
|
7
7
|
s: S,
|
|
8
8
|
mapper: M,
|
|
9
|
-
): S extends schema.Collection
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[K in keyof S]: S[K] extends Schema
|
|
20
|
-
? typeof mapCollection<M, S[K]>
|
|
21
|
-
: S[K];
|
|
22
|
-
}
|
|
23
|
-
: S {
|
|
9
|
+
): S extends schema.Collection ? ReturnType<typeof mapper<S>>
|
|
10
|
+
: S extends schema.Object<infer T> ?
|
|
11
|
+
{
|
|
12
|
+
[K in keyof T]: T[K] extends Schema ? typeof mapCollection<M, T[K]> : T[K];
|
|
13
|
+
}
|
|
14
|
+
: S extends { [K: string]: any } ?
|
|
15
|
+
{
|
|
16
|
+
[K in keyof S]: S[K] extends Schema ? typeof mapCollection<M, S[K]> : S[K];
|
|
17
|
+
}
|
|
18
|
+
: S {
|
|
24
19
|
if (typeof s !== 'object' || s === undefined) return s as any;
|
|
25
20
|
if (s instanceof schema.Collection) {
|
|
26
21
|
return mapper(s as any);
|
|
@@ -38,12 +33,10 @@ export default function mapCollection<
|
|
|
38
33
|
type MapCollection<
|
|
39
34
|
M extends <C extends schema.Collection>(collection: C) => any,
|
|
40
35
|
S extends Schema | undefined,
|
|
41
|
-
> =
|
|
42
|
-
? ReturnType<M>
|
|
43
|
-
: S extends schema.Object<infer T>
|
|
44
|
-
?
|
|
45
|
-
: S extends { [K: string]: any }
|
|
46
|
-
? MapObject<M, S>
|
|
36
|
+
> =
|
|
37
|
+
S extends schema.Collection ? ReturnType<M>
|
|
38
|
+
: S extends schema.Object<infer T> ? MapCollection<M, T>
|
|
39
|
+
: S extends { [K: string]: any } ? MapObject<M, S>
|
|
47
40
|
: never;
|
|
48
41
|
|
|
49
42
|
export type MapObject<
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export default function paramsToString(
|
|
2
|
-
searchParams
|
|
2
|
+
searchParams?:
|
|
3
|
+
| string
|
|
4
|
+
| URLSearchParams
|
|
5
|
+
| Record<string, string>
|
|
6
|
+
| string[][]
|
|
7
|
+
| undefined,
|
|
3
8
|
) {
|
|
4
9
|
const params = new URLSearchParams(searchParams as any);
|
|
5
10
|
try {
|
package/src/paramsToString.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export default function paramsToString(
|
|
2
|
-
searchParams
|
|
2
|
+
searchParams?:
|
|
3
|
+
| string
|
|
4
|
+
| URLSearchParams
|
|
5
|
+
| Record<string, string>
|
|
6
|
+
| string[][]
|
|
7
|
+
| undefined,
|
|
3
8
|
) {
|
|
4
|
-
const params = new URLSearchParams(searchParams
|
|
9
|
+
const params = new URLSearchParams(searchParams);
|
|
5
10
|
params.sort();
|
|
6
11
|
return params.toString();
|
|
7
12
|
}
|
package/src/pathTypes.ts
CHANGED
|
@@ -2,59 +2,50 @@ type OnlyOptional<S extends string> = S extends `${infer K}?` ? K : never;
|
|
|
2
2
|
type OnlyRequired<S extends string> = S extends `${string}?` ? never : S;
|
|
3
3
|
|
|
4
4
|
/** Computes the union of keys for a path string */
|
|
5
|
-
export type PathKeys<S extends string> =
|
|
6
|
-
? string
|
|
7
|
-
: S extends `${infer A}\\:${infer B}`
|
|
8
|
-
? PathKeys<A> | PathKeys<B>
|
|
9
|
-
: S extends `${infer A}\\?${infer B}`
|
|
10
|
-
? PathKeys<A> | PathKeys<B>
|
|
5
|
+
export type PathKeys<S extends string> =
|
|
6
|
+
string extends S ? string
|
|
7
|
+
: S extends `${infer A}\\:${infer B}` ? PathKeys<A> | PathKeys<B>
|
|
8
|
+
: S extends `${infer A}\\?${infer B}` ? PathKeys<A> | PathKeys<B>
|
|
11
9
|
: PathSplits<S>;
|
|
12
10
|
|
|
13
|
-
type PathSplits<S extends string> =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
: S extends `${string}:${infer K}:${infer R}`
|
|
20
|
-
? PathSplits<`:${K}`> | PathSplits<`:${R}`>
|
|
21
|
-
: S extends `${string}:${infer K}`
|
|
22
|
-
? K
|
|
11
|
+
type PathSplits<S extends string> =
|
|
12
|
+
S extends `${string}:${infer K}${'/' | ',' | '%' | '&'}${infer R}` ?
|
|
13
|
+
PathSplits<`:${K}`> | PathSplits<R>
|
|
14
|
+
: S extends `${string}:${infer K}:${infer R}` ?
|
|
15
|
+
PathSplits<`:${K}`> | PathSplits<`:${R}`>
|
|
16
|
+
: S extends `${string}:${infer K}` ? K
|
|
23
17
|
: never;
|
|
24
18
|
|
|
25
19
|
/** Parameters for a given path */
|
|
26
|
-
export type PathArgs<S extends string> =
|
|
27
|
-
|
|
20
|
+
export type PathArgs<S extends string> =
|
|
21
|
+
PathKeys<S> extends never ?
|
|
22
|
+
// unknown is identity for intersection ('&')
|
|
28
23
|
unknown
|
|
29
24
|
: KeysToArgs<PathKeys<S>>;
|
|
30
25
|
|
|
31
26
|
export type KeysToArgs<Key extends string> = {
|
|
32
27
|
[K in Key as OnlyOptional<K>]?: string | number;
|
|
33
|
-
} & (OnlyRequired<Key> extends never
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
> extends never
|
|
42
|
-
? Record<string, number | string | boolean> | undefined
|
|
28
|
+
} & (OnlyRequired<Key> extends never ? unknown
|
|
29
|
+
: {
|
|
30
|
+
[K in Key as OnlyRequired<K>]: string | number;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export type PathArgsAndSearch<S extends string> =
|
|
34
|
+
OnlyRequired<PathKeys<S>> extends never ?
|
|
35
|
+
Record<string, number | string | boolean> | undefined
|
|
43
36
|
: {
|
|
44
37
|
[K in PathKeys<S> as OnlyRequired<K>]: string | number;
|
|
45
38
|
} & Record<string, number | string>;
|
|
46
39
|
|
|
47
40
|
/** Removes the last :token */
|
|
48
|
-
export type ShortenPath<S extends string> =
|
|
49
|
-
? string
|
|
50
|
-
: S extends `${infer B}:${infer R}`
|
|
51
|
-
? TrimColon<`${B}:${ShortenPath<R>}`>
|
|
41
|
+
export type ShortenPath<S extends string> =
|
|
42
|
+
string extends S ? string
|
|
43
|
+
: S extends `${infer B}:${infer R}` ? TrimColon<`${B}:${ShortenPath<R>}`>
|
|
52
44
|
: '';
|
|
53
45
|
|
|
54
|
-
type TrimColon<S extends string> =
|
|
55
|
-
? string
|
|
56
|
-
: S extends `${infer R}:`
|
|
57
|
-
? R
|
|
46
|
+
type TrimColon<S extends string> =
|
|
47
|
+
string extends S ? string
|
|
48
|
+
: S extends `${infer R}:` ? R
|
|
58
49
|
: S;
|
|
59
50
|
|
|
60
51
|
export type ResourcePath = string; // `${string}:${string}`; TODO: Maybe do this in the future? Seems to hard to understand for now
|
|
@@ -35,31 +35,21 @@ export interface CustomResource<
|
|
|
35
35
|
Delete extends PartialRestGenerics | {} = any,
|
|
36
36
|
> extends Extendable<O> {
|
|
37
37
|
// unknown only extends any. this allows us to match exclusively on members not set
|
|
38
|
-
get: unknown extends Get
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
partialUpdate: unknown extends PartialUpdate
|
|
54
|
-
? R['partialUpdate']
|
|
55
|
-
: PartialRestGenerics extends PartialUpdate
|
|
56
|
-
? R['partialUpdate']
|
|
57
|
-
: RestExtendedEndpoint<PartialUpdate, R['partialUpdate']>;
|
|
58
|
-
delete: unknown extends Delete
|
|
59
|
-
? R['delete']
|
|
60
|
-
: PartialRestGenerics extends Delete
|
|
61
|
-
? R['delete']
|
|
62
|
-
: RestExtendedEndpoint<Delete, R['delete']>;
|
|
38
|
+
get: unknown extends Get ? R['get']
|
|
39
|
+
: PartialRestGenerics extends Get ? R['get']
|
|
40
|
+
: RestExtendedEndpoint<Get, R['get']>;
|
|
41
|
+
getList: unknown extends GetList ? R['getList']
|
|
42
|
+
: PartialRestGenerics extends GetList ? R['getList']
|
|
43
|
+
: RestExtendedEndpoint<GetList, R['getList']>;
|
|
44
|
+
update: unknown extends Update ? R['update']
|
|
45
|
+
: PartialRestGenerics extends Update ? R['update']
|
|
46
|
+
: RestExtendedEndpoint<Update, R['update']>;
|
|
47
|
+
partialUpdate: unknown extends PartialUpdate ? R['partialUpdate']
|
|
48
|
+
: PartialRestGenerics extends PartialUpdate ? R['partialUpdate']
|
|
49
|
+
: RestExtendedEndpoint<PartialUpdate, R['partialUpdate']>;
|
|
50
|
+
delete: unknown extends Delete ? R['delete']
|
|
51
|
+
: PartialRestGenerics extends Delete ? R['delete']
|
|
52
|
+
: RestExtendedEndpoint<Delete, R['delete']>;
|
|
63
53
|
}
|
|
64
54
|
|
|
65
55
|
export type ExtendedResource<
|
|
@@ -76,45 +66,40 @@ export interface ResourceEndpointExtensions<
|
|
|
76
66
|
Delete extends PartialRestGenerics = any,
|
|
77
67
|
> {
|
|
78
68
|
readonly get?: RestEndpointOptions<
|
|
79
|
-
unknown extends Get
|
|
80
|
-
|
|
81
|
-
: OptionsToFunction<Get, R['get'], EndpointToFunction<R['get']>>,
|
|
69
|
+
unknown extends Get ? EndpointToFunction<R['get']>
|
|
70
|
+
: OptionsToFunction<Get, R['get'], EndpointToFunction<R['get']>>,
|
|
82
71
|
R['get']['schema']
|
|
83
72
|
> &
|
|
84
73
|
Readonly<Get>;
|
|
85
74
|
readonly getList?: RestEndpointOptions<
|
|
86
|
-
unknown extends GetList
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
>,
|
|
75
|
+
unknown extends GetList ? EndpointToFunction<R['getList']>
|
|
76
|
+
: OptionsToFunction<
|
|
77
|
+
GetList,
|
|
78
|
+
R['getList'],
|
|
79
|
+
EndpointToFunction<R['getList']>
|
|
80
|
+
>,
|
|
93
81
|
R['getList']['schema']
|
|
94
82
|
> &
|
|
95
83
|
Readonly<GetList>;
|
|
96
84
|
readonly update?: RestEndpointOptions<
|
|
97
|
-
unknown extends Update
|
|
98
|
-
|
|
99
|
-
: OptionsToFunction<Update, R['update'], EndpointToFunction<R['update']>>,
|
|
85
|
+
unknown extends Update ? EndpointToFunction<R['update']>
|
|
86
|
+
: OptionsToFunction<Update, R['update'], EndpointToFunction<R['update']>>,
|
|
100
87
|
R['update']['schema']
|
|
101
88
|
> &
|
|
102
89
|
Readonly<Update>;
|
|
103
90
|
readonly partialUpdate?: RestEndpointOptions<
|
|
104
|
-
unknown extends PartialUpdate
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
>,
|
|
91
|
+
unknown extends PartialUpdate ? EndpointToFunction<R['partialUpdate']>
|
|
92
|
+
: OptionsToFunction<
|
|
93
|
+
PartialUpdate,
|
|
94
|
+
R['partialUpdate'],
|
|
95
|
+
EndpointToFunction<R['partialUpdate']>
|
|
96
|
+
>,
|
|
111
97
|
R['partialUpdate']['schema']
|
|
112
98
|
> &
|
|
113
99
|
Readonly<PartialUpdate>;
|
|
114
100
|
readonly delete?: RestEndpointOptions<
|
|
115
|
-
unknown extends Delete
|
|
116
|
-
|
|
117
|
-
: OptionsToFunction<Delete, R['delete'], EndpointToFunction<R['delete']>>,
|
|
101
|
+
unknown extends Delete ? EndpointToFunction<R['delete']>
|
|
102
|
+
: OptionsToFunction<Delete, R['delete'], EndpointToFunction<R['delete']>>,
|
|
118
103
|
R['delete']['schema']
|
|
119
104
|
> &
|
|
120
105
|
Readonly<Delete>;
|
package/src/resourceTypes.ts
CHANGED
|
@@ -68,104 +68,100 @@ export interface Resource<
|
|
|
68
68
|
*
|
|
69
69
|
* @see https://dataclient.io/rest/api/createResource#getlist
|
|
70
70
|
*/
|
|
71
|
-
getList: 'searchParams' extends keyof O
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
schema
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
'searchParams' extends
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} & Pick<O, 'paginationField'>
|
|
109
|
-
>;
|
|
71
|
+
getList: 'searchParams' extends keyof O ?
|
|
72
|
+
GetEndpoint<
|
|
73
|
+
{
|
|
74
|
+
path: ShortenPath<O['path']>;
|
|
75
|
+
schema: schema.Collection<
|
|
76
|
+
[O['schema']],
|
|
77
|
+
[
|
|
78
|
+
'searchParams' extends keyof O ?
|
|
79
|
+
O['searchParams'] extends undefined ?
|
|
80
|
+
PathArgs<ShortenPath<O['path']>>
|
|
81
|
+
: O['searchParams'] & PathArgs<ShortenPath<O['path']>>
|
|
82
|
+
: PathArgs<ShortenPath<O['path']>>,
|
|
83
|
+
]
|
|
84
|
+
>;
|
|
85
|
+
body: 'body' extends keyof O ? O['body']
|
|
86
|
+
: Partial<Denormalize<O['schema']>>;
|
|
87
|
+
searchParams: O['searchParams'];
|
|
88
|
+
} & Pick<O, 'paginationField'>
|
|
89
|
+
>
|
|
90
|
+
: GetEndpoint<
|
|
91
|
+
{
|
|
92
|
+
path: ShortenPath<O['path']>;
|
|
93
|
+
schema: schema.Collection<
|
|
94
|
+
[O['schema']],
|
|
95
|
+
[
|
|
96
|
+
'searchParams' extends keyof O ?
|
|
97
|
+
O['searchParams'] extends undefined ?
|
|
98
|
+
PathArgs<ShortenPath<O['path']>>
|
|
99
|
+
: O['searchParams'] & PathArgs<ShortenPath<O['path']>>
|
|
100
|
+
: PathArgs<ShortenPath<O['path']>>,
|
|
101
|
+
]
|
|
102
|
+
>;
|
|
103
|
+
body: 'body' extends keyof O ? O['body']
|
|
104
|
+
: Partial<Denormalize<O['schema']>>;
|
|
105
|
+
searchParams: Record<string, number | string | boolean> | undefined;
|
|
106
|
+
} & Pick<O, 'paginationField'>
|
|
107
|
+
>;
|
|
110
108
|
/** Create a new item (POST)
|
|
111
109
|
*
|
|
112
110
|
* @deprecated use Resource.getList.push instead
|
|
113
111
|
*/
|
|
114
|
-
create: 'searchParams' extends keyof O
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: Partial<Denormalize<O['schema']>>;
|
|
129
|
-
}>;
|
|
112
|
+
create: 'searchParams' extends keyof O ?
|
|
113
|
+
MutateEndpoint<{
|
|
114
|
+
path: ShortenPath<O['path']>;
|
|
115
|
+
schema: schema.Collection<[O['schema']]>['push'];
|
|
116
|
+
body: 'body' extends keyof O ? O['body']
|
|
117
|
+
: Partial<Denormalize<O['schema']>>;
|
|
118
|
+
searchParams: O['searchParams'];
|
|
119
|
+
}>
|
|
120
|
+
: MutateEndpoint<{
|
|
121
|
+
path: ShortenPath<O['path']>;
|
|
122
|
+
schema: schema.Collection<[O['schema']]>['push'];
|
|
123
|
+
body: 'body' extends keyof O ? O['body']
|
|
124
|
+
: Partial<Denormalize<O['schema']>>;
|
|
125
|
+
}>;
|
|
130
126
|
/** Update an item (PUT)
|
|
131
127
|
*
|
|
132
128
|
* @see https://dataclient.io/rest/api/createResource#update
|
|
133
129
|
*/
|
|
134
|
-
update: 'body' extends keyof O
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
130
|
+
update: 'body' extends keyof O ?
|
|
131
|
+
MutateEndpoint<{
|
|
132
|
+
path: O['path'];
|
|
133
|
+
body: O['body'];
|
|
134
|
+
schema: O['schema'];
|
|
135
|
+
}>
|
|
136
|
+
: MutateEndpoint<{
|
|
137
|
+
path: O['path'];
|
|
138
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
139
|
+
schema: O['schema'];
|
|
140
|
+
}>;
|
|
145
141
|
/** Update an item (PATCH)
|
|
146
142
|
*
|
|
147
143
|
* @see https://dataclient.io/rest/api/createResource#partialupdate
|
|
148
144
|
*/
|
|
149
|
-
partialUpdate: 'body' extends keyof O
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
145
|
+
partialUpdate: 'body' extends keyof O ?
|
|
146
|
+
MutateEndpoint<{
|
|
147
|
+
path: O['path'];
|
|
148
|
+
body: Partial<O['body']>;
|
|
149
|
+
schema: O['schema'];
|
|
150
|
+
}>
|
|
151
|
+
: MutateEndpoint<{
|
|
152
|
+
path: O['path'];
|
|
153
|
+
body: Partial<Denormalize<O['schema']>> | FormData;
|
|
154
|
+
schema: O['schema'];
|
|
155
|
+
}>;
|
|
160
156
|
/** Delete an item (DELETE)
|
|
161
157
|
*
|
|
162
158
|
* @see https://dataclient.io/rest/api/createResource#delete
|
|
163
159
|
*/
|
|
164
160
|
delete: RestTypeNoBody<
|
|
165
161
|
PathArgs<O['path']>,
|
|
166
|
-
O['schema'] extends schema.EntityInterface & { process: any }
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
O['schema'] extends schema.EntityInterface & { process: any } ?
|
|
163
|
+
schema.Invalidate<O['schema']>
|
|
164
|
+
: O['schema'],
|
|
169
165
|
undefined,
|
|
170
166
|
Partial<PathArgs<O['path']>>,
|
|
171
167
|
{
|
package/src/utiltypes.ts
CHANGED
|
@@ -15,9 +15,9 @@ RequiredKeys<{
|
|
|
15
15
|
export type RequiredKeys<T> = Values<OnlyRequired<T>>;
|
|
16
16
|
|
|
17
17
|
type OnlyRequired<T> = {
|
|
18
|
-
[K in keyof T as string extends K ? never : K]-?: {} extends Pick<T, K>
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
[K in keyof T as string extends K ? never : K]-?: {} extends Pick<T, K> ?
|
|
19
|
+
never
|
|
20
|
+
: K;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
// exclude number only required for typescript 4.4 and below
|