@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.
Files changed (74) hide show
  1. package/README.md +16 -0
  2. package/dist/index.js +8 -1
  3. package/dist/index.umd.min.js +1 -1
  4. package/legacy/OptionsToFunction.js +1 -1
  5. package/legacy/RestEndpoint.js +7 -2
  6. package/legacy/RestEndpointTypeHelp.js +1 -1
  7. package/legacy/RestEndpointTypes.js +1 -1
  8. package/legacy/createResource.js +1 -1
  9. package/legacy/extractCollection.js +1 -1
  10. package/legacy/index.js +2 -1
  11. package/legacy/mapCollection.js +1 -1
  12. package/legacy/paramsToString.js +1 -1
  13. package/legacy/paramsToString.native.js +1 -1
  14. package/legacy/pathTypes.js +1 -1
  15. package/legacy/resourceExtensionTypes.js +1 -1
  16. package/legacy/resourceTypes.js +1 -1
  17. package/legacy/utiltypes.js +1 -1
  18. package/lib/OptionsToFunction.d.ts.map +1 -1
  19. package/lib/OptionsToFunction.js +1 -1
  20. package/lib/RestEndpoint.js +7 -2
  21. package/lib/RestEndpointTypeHelp.d.ts.map +1 -1
  22. package/lib/RestEndpointTypeHelp.js +1 -1
  23. package/lib/RestEndpointTypes.d.ts +29 -7
  24. package/lib/RestEndpointTypes.d.ts.map +1 -1
  25. package/lib/RestEndpointTypes.js +1 -1
  26. package/lib/createResource.js +1 -1
  27. package/lib/extractCollection.d.ts +2 -2
  28. package/lib/extractCollection.d.ts.map +1 -1
  29. package/lib/extractCollection.js +1 -1
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.d.ts.map +1 -1
  32. package/lib/index.js +2 -1
  33. package/lib/mapCollection.d.ts.map +1 -1
  34. package/lib/mapCollection.js +1 -1
  35. package/lib/paramsToString.d.ts +1 -1
  36. package/lib/paramsToString.d.ts.map +1 -1
  37. package/lib/paramsToString.js +1 -1
  38. package/lib/paramsToString.native.d.ts +1 -1
  39. package/lib/paramsToString.native.d.ts.map +1 -1
  40. package/lib/paramsToString.native.js +1 -1
  41. package/lib/pathTypes.d.ts.map +1 -1
  42. package/lib/pathTypes.js +1 -1
  43. package/lib/resourceExtensionTypes.d.ts.map +1 -1
  44. package/lib/resourceExtensionTypes.js +1 -1
  45. package/lib/resourceTypes.d.ts.map +1 -1
  46. package/lib/resourceTypes.js +1 -1
  47. package/lib/utiltypes.d.ts.map +1 -1
  48. package/lib/utiltypes.js +1 -1
  49. package/package.json +4 -2
  50. package/src/OptionsToFunction.ts +17 -15
  51. package/src/RestEndpoint.js +9 -4
  52. package/src/RestEndpointTypeHelp.ts +2 -3
  53. package/src/RestEndpointTypes.ts +173 -178
  54. package/src/__tests__/RestEndpoint.ts +54 -2
  55. package/src/createResource.ts +2 -2
  56. package/src/extractCollection.ts +13 -13
  57. package/src/index.ts +1 -0
  58. package/src/mapCollection.ts +14 -21
  59. package/src/paramsToString.native.ts +6 -1
  60. package/src/paramsToString.ts +7 -2
  61. package/src/pathTypes.ts +27 -36
  62. package/src/resourceExtensionTypes.ts +33 -48
  63. package/src/resourceTypes.ts +76 -80
  64. package/src/utiltypes.ts +3 -3
  65. package/ts4.0/RestEndpointTypes.d.ts +29 -7
  66. package/ts4.0/extractCollection.d.ts +2 -2
  67. package/ts4.0/index.d.ts +1 -0
  68. package/ts4.0/paramsToString.d.ts +1 -1
  69. package/ts4.0/paramsToString.native.d.ts +1 -1
  70. package/ts4.1/RestEndpointTypes.d.ts +29 -7
  71. package/ts4.1/extractCollection.d.ts +2 -2
  72. package/ts4.1/index.d.ts +1 -0
  73. package/ts4.1/paramsToString.d.ts +1 -1
  74. 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' });
@@ -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
- ? Object.fromEntries((body as any).entries())
162
+ return body instanceof FormData ?
163
+ Object.fromEntries((body as any).entries())
164
164
  : body;
165
165
  }
@@ -20,17 +20,17 @@ export default function extractCollection<
20
20
  }
21
21
  }
22
22
 
23
- export type ExtractCollection<S extends Schema | undefined> = S extends {
24
- push: any;
25
- unshift: any;
26
- assign: any;
27
- schema: Schema;
28
- }
29
- ? S
30
- : S extends schema.Object<infer T>
31
- ? ExtractObject<T>
32
- : S extends Exclude<Schema, { [K: string]: any }>
33
- ? never
34
- : S extends { [K: string]: Schema }
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';
@@ -6,21 +6,16 @@ export default function mapCollection<
6
6
  >(
7
7
  s: S,
8
8
  mapper: M,
9
- ): S extends schema.Collection
10
- ? ReturnType<typeof mapper<S>>
11
- : S extends schema.Object<infer T>
12
- ? {
13
- [K in keyof T]: T[K] extends Schema
14
- ? typeof mapCollection<M, T[K]>
15
- : T[K];
16
- }
17
- : S extends { [K: string]: any }
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
- > = S extends schema.Collection
42
- ? ReturnType<M>
43
- : S extends schema.Object<infer T>
44
- ? MapCollection<M, T>
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: Readonly<Record<string, string | number>>,
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 {
@@ -1,7 +1,12 @@
1
1
  export default function paramsToString(
2
- searchParams: Readonly<Record<string, string | number | boolean>>,
2
+ searchParams?:
3
+ | string
4
+ | URLSearchParams
5
+ | Record<string, string>
6
+ | string[][]
7
+ | undefined,
3
8
  ) {
4
- const params = new URLSearchParams(searchParams as any);
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> = string extends S
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> = S extends `${string}:${infer K}${
14
- | '/'
15
- | ','
16
- | '%'
17
- | '&'}${infer R}`
18
- ? PathSplits<`:${K}`> | PathSplits<R>
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> = PathKeys<S> extends never
27
- ? // unknown is identity for intersection ('&')
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
- ? unknown
35
- : {
36
- [K in Key as OnlyRequired<K>]: string | number;
37
- });
38
-
39
- export type PathArgsAndSearch<S extends string> = OnlyRequired<
40
- PathKeys<S>
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> = string extends S
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> = string extends S
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
- ? R['get']
40
- : PartialRestGenerics extends Get
41
- ? R['get']
42
- : RestExtendedEndpoint<Get, R['get']>;
43
- getList: unknown extends GetList
44
- ? R['getList']
45
- : PartialRestGenerics extends GetList
46
- ? R['getList']
47
- : RestExtendedEndpoint<GetList, R['getList']>;
48
- update: unknown extends Update
49
- ? R['update']
50
- : PartialRestGenerics extends Update
51
- ? R['update']
52
- : RestExtendedEndpoint<Update, R['update']>;
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
- ? EndpointToFunction<R['get']>
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
- ? EndpointToFunction<R['getList']>
88
- : OptionsToFunction<
89
- GetList,
90
- R['getList'],
91
- EndpointToFunction<R['getList']>
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
- ? EndpointToFunction<R['update']>
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
- ? EndpointToFunction<R['partialUpdate']>
106
- : OptionsToFunction<
107
- PartialUpdate,
108
- R['partialUpdate'],
109
- EndpointToFunction<R['partialUpdate']>
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
- ? EndpointToFunction<R['delete']>
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>;
@@ -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
- ? 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
86
- ? O['body']
87
- : Partial<Denormalize<O['schema']>>;
88
- searchParams: O['searchParams'];
89
- } & Pick<O, 'paginationField'>
90
- >
91
- : GetEndpoint<
92
- {
93
- path: ShortenPath<O['path']>;
94
- schema: schema.Collection<
95
- [O['schema']],
96
- [
97
- 'searchParams' extends keyof O
98
- ? O['searchParams'] extends undefined
99
- ? PathArgs<ShortenPath<O['path']>>
100
- : O['searchParams'] & PathArgs<ShortenPath<O['path']>>
101
- : PathArgs<ShortenPath<O['path']>>,
102
- ]
103
- >;
104
- body: 'body' extends keyof O
105
- ? O['body']
106
- : Partial<Denormalize<O['schema']>>;
107
- searchParams: Record<string, number | string | boolean> | undefined;
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
- ? MutateEndpoint<{
116
- path: ShortenPath<O['path']>;
117
- schema: schema.Collection<[O['schema']]>['push'];
118
- body: 'body' extends keyof O
119
- ? O['body']
120
- : Partial<Denormalize<O['schema']>>;
121
- searchParams: O['searchParams'];
122
- }>
123
- : MutateEndpoint<{
124
- path: ShortenPath<O['path']>;
125
- schema: schema.Collection<[O['schema']]>['push'];
126
- body: 'body' extends keyof O
127
- ? O['body']
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
- ? MutateEndpoint<{
136
- path: O['path'];
137
- body: O['body'];
138
- schema: O['schema'];
139
- }>
140
- : MutateEndpoint<{
141
- path: O['path'];
142
- body: Partial<Denormalize<O['schema']>> | FormData;
143
- schema: O['schema'];
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
- ? MutateEndpoint<{
151
- path: O['path'];
152
- body: Partial<O['body']>;
153
- schema: O['schema'];
154
- }>
155
- : MutateEndpoint<{
156
- path: O['path'];
157
- body: Partial<Denormalize<O['schema']>> | FormData;
158
- schema: O['schema'];
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
- ? schema.Invalidate<O['schema']>
168
- : O['schema'],
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
- ? never
20
- : K;
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