@data-client/rest 0.9.5 → 0.9.9
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 +1 -1
- package/dist/index.umd.min.js +1 -1
- package/legacy/OptionsToFunction.js +1 -1
- package/legacy/RestEndpoint.js +1 -1
- 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/mapCollection.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 +1 -1
- package/lib/RestEndpointTypeHelp.d.ts.map +1 -1
- package/lib/RestEndpointTypeHelp.js +1 -1
- 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/mapCollection.d.ts.map +1 -1
- package/lib/mapCollection.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 +10 -2
- 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 +42 -42
- package/src/RestEndpoint.js +3 -3
- package/src/RestEndpointTypeHelp.ts +2 -3
- package/src/RestEndpointTypes.ts +187 -220
- package/src/createResource.ts +2 -2
- package/src/extractCollection.ts +13 -13
- package/src/mapCollection.ts +14 -22
- package/src/pathTypes.ts +27 -36
- package/src/resourceExtensionTypes.ts +33 -48
- package/src/resourceTypes.ts +76 -62
- package/src/utiltypes.ts +3 -3
- package/ts4.0/extractCollection.d.ts +2 -2
- package/ts4.0/resourceTypes.d.ts +4 -0
- package/ts4.1/extractCollection.d.ts +2 -2
- package/ts4.1/resourceTypes.d.ts +4 -0
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,86 +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
|
-
|
|
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
|
+
>;
|
|
92
108
|
/** Create a new item (POST)
|
|
93
109
|
*
|
|
94
110
|
* @deprecated use Resource.getList.push instead
|
|
95
111
|
*/
|
|
96
|
-
create: 'searchParams' extends keyof O
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: Partial<Denormalize<O['schema']>>;
|
|
111
|
-
}>;
|
|
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
|
+
}>;
|
|
112
126
|
/** Update an item (PUT)
|
|
113
127
|
*
|
|
114
128
|
* @see https://dataclient.io/rest/api/createResource#update
|
|
115
129
|
*/
|
|
116
|
-
update: 'body' extends keyof O
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
}>;
|
|
127
141
|
/** Update an item (PATCH)
|
|
128
142
|
*
|
|
129
143
|
* @see https://dataclient.io/rest/api/createResource#partialupdate
|
|
130
144
|
*/
|
|
131
|
-
partialUpdate: 'body' extends keyof O
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
}>;
|
|
142
156
|
/** Delete an item (DELETE)
|
|
143
157
|
*
|
|
144
158
|
* @see https://dataclient.io/rest/api/createResource#delete
|
|
145
159
|
*/
|
|
146
160
|
delete: RestTypeNoBody<
|
|
147
161
|
PathArgs<O['path']>,
|
|
148
|
-
O['schema'] extends schema.EntityInterface & { process: any }
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
O['schema'] extends schema.EntityInterface & { process: any } ?
|
|
163
|
+
schema.Invalidate<O['schema']>
|
|
164
|
+
: O['schema'],
|
|
151
165
|
undefined,
|
|
152
166
|
Partial<PathArgs<O['path']>>,
|
|
153
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
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Schema, schema } from '@data-client/endpoint';
|
|
2
2
|
import { ExtractObject } from './extractObject.js';
|
|
3
3
|
export default function extractCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): ExtractCollection<S> | undefined;
|
|
4
|
-
export type ExtractCollection<S extends Schema | undefined> = S extends {
|
|
4
|
+
export type ExtractCollection<S extends Schema | undefined> = S extends ({
|
|
5
5
|
push: any;
|
|
6
6
|
unshift: any;
|
|
7
7
|
assign: any;
|
|
8
8
|
schema: Schema;
|
|
9
|
-
} ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends Exclude<Schema, {
|
|
9
|
+
}) ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends Exclude<Schema, {
|
|
10
10
|
[K: string]: any;
|
|
11
11
|
}> ? never : S extends {
|
|
12
12
|
[K: string]: Schema;
|
package/ts4.0/resourceTypes.d.ts
CHANGED
|
@@ -68,6 +68,8 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
68
68
|
path: ShortenPath<O['path']>;
|
|
69
69
|
schema: schema.Collection<[
|
|
70
70
|
O['schema']
|
|
71
|
+
], [
|
|
72
|
+
'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<ShortenPath<O['path']>> : O['searchParams'] & PathArgs<ShortenPath<O['path']>> : PathArgs<ShortenPath<O['path']>>
|
|
71
73
|
]>;
|
|
72
74
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
73
75
|
searchParams: O['searchParams'];
|
|
@@ -75,6 +77,8 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
75
77
|
path: ShortenPath<O['path']>;
|
|
76
78
|
schema: schema.Collection<[
|
|
77
79
|
O['schema']
|
|
80
|
+
], [
|
|
81
|
+
'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<ShortenPath<O['path']>> : O['searchParams'] & PathArgs<ShortenPath<O['path']>> : PathArgs<ShortenPath<O['path']>>
|
|
78
82
|
]>;
|
|
79
83
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
80
84
|
searchParams: Record<string, number | string | boolean> | undefined;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Schema, schema } from '@data-client/endpoint';
|
|
2
2
|
import { ExtractObject } from './extractObject.js';
|
|
3
3
|
export default function extractCollection<M extends <C extends schema.Collection>(collection: C) => any, S extends Schema | undefined>(s: S, mapper: M): ExtractCollection<S> | undefined;
|
|
4
|
-
export type ExtractCollection<S extends Schema | undefined> = S extends {
|
|
4
|
+
export type ExtractCollection<S extends Schema | undefined> = S extends ({
|
|
5
5
|
push: any;
|
|
6
6
|
unshift: any;
|
|
7
7
|
assign: any;
|
|
8
8
|
schema: Schema;
|
|
9
|
-
} ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends Exclude<Schema, {
|
|
9
|
+
}) ? S : S extends schema.Object<infer T> ? ExtractObject<T> : S extends Exclude<Schema, {
|
|
10
10
|
[K: string]: any;
|
|
11
11
|
}> ? never : S extends {
|
|
12
12
|
[K: string]: Schema;
|
package/ts4.1/resourceTypes.d.ts
CHANGED
|
@@ -68,6 +68,8 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
68
68
|
path: ShortenPath<O['path']>;
|
|
69
69
|
schema: schema.Collection<[
|
|
70
70
|
O['schema']
|
|
71
|
+
], [
|
|
72
|
+
'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<ShortenPath<O['path']>> : O['searchParams'] & PathArgs<ShortenPath<O['path']>> : PathArgs<ShortenPath<O['path']>>
|
|
71
73
|
]>;
|
|
72
74
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
73
75
|
searchParams: O['searchParams'];
|
|
@@ -75,6 +77,8 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
75
77
|
path: ShortenPath<O['path']>;
|
|
76
78
|
schema: schema.Collection<[
|
|
77
79
|
O['schema']
|
|
80
|
+
], [
|
|
81
|
+
'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<ShortenPath<O['path']>> : O['searchParams'] & PathArgs<ShortenPath<O['path']>> : PathArgs<ShortenPath<O['path']>>
|
|
78
82
|
]>;
|
|
79
83
|
body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
|
|
80
84
|
searchParams: Record<string, number | string | boolean> | undefined;
|