@data-client/rest 0.10.0 → 0.11.1

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 (63) hide show
  1. package/README.md +4 -3
  2. package/dist/index.js +5 -6
  3. package/dist/index.umd.min.js +1 -1
  4. package/legacy/NetworkError.js +1 -1
  5. package/legacy/OptionsToFunction.js +1 -1
  6. package/legacy/RestEndpoint.js +1 -1
  7. package/legacy/RestEndpointTypeHelp.js +1 -1
  8. package/legacy/RestEndpointTypes.js +1 -1
  9. package/legacy/RestHelpers.js +1 -1
  10. package/legacy/createResource.js +7 -8
  11. package/legacy/extractCollection.js +1 -1
  12. package/legacy/extractObject.js +1 -1
  13. package/legacy/hookifyResource.js +1 -1
  14. package/legacy/index.js +1 -1
  15. package/legacy/mapCollection.js +1 -1
  16. package/legacy/next/index.js +1 -1
  17. package/legacy/paginatedCollections.js +1 -1
  18. package/legacy/paramsToString.js +1 -1
  19. package/legacy/paramsToString.native.js +1 -1
  20. package/legacy/pathTypes.js +1 -1
  21. package/legacy/resourceExtendable.js +1 -1
  22. package/legacy/resourceExtensionTypes.js +1 -1
  23. package/legacy/resourceTypes.js +1 -1
  24. package/legacy/test-fixtures.js +1 -1
  25. package/legacy/utiltypes.js +1 -1
  26. package/lib/NetworkError.js +1 -1
  27. package/lib/OptionsToFunction.js +1 -1
  28. package/lib/RestEndpoint.js +1 -1
  29. package/lib/RestEndpointTypeHelp.js +1 -1
  30. package/lib/RestEndpointTypes.d.ts +15 -13
  31. package/lib/RestEndpointTypes.d.ts.map +1 -1
  32. package/lib/RestEndpointTypes.js +1 -1
  33. package/lib/RestHelpers.js +1 -1
  34. package/lib/createResource.d.ts.map +1 -1
  35. package/lib/createResource.js +7 -8
  36. package/lib/extractCollection.js +1 -1
  37. package/lib/extractObject.js +1 -1
  38. package/lib/hookifyResource.js +1 -1
  39. package/lib/index.js +1 -1
  40. package/lib/mapCollection.js +1 -1
  41. package/lib/next/index.js +1 -1
  42. package/lib/paginatedCollections.js +1 -1
  43. package/lib/paramsToString.js +1 -1
  44. package/lib/paramsToString.native.js +1 -1
  45. package/lib/pathTypes.js +1 -1
  46. package/lib/resourceExtendable.js +1 -1
  47. package/lib/resourceExtensionTypes.js +1 -1
  48. package/lib/resourceTypes.d.ts +4 -8
  49. package/lib/resourceTypes.d.ts.map +1 -1
  50. package/lib/resourceTypes.js +1 -1
  51. package/lib/test-fixtures.js +1 -1
  52. package/lib/utiltypes.js +1 -1
  53. package/package.json +2 -2
  54. package/src/RestEndpointTypes.ts +30 -32
  55. package/src/__tests__/RestEndpoint.ts +5 -4
  56. package/src/__tests__/createResource.test.ts +42 -2
  57. package/src/__tests__/types.test.ts +112 -1
  58. package/src/createResource.ts +7 -12
  59. package/src/resourceTypes.ts +16 -15
  60. package/ts4.0/RestEndpointTypes.d.ts +21 -13
  61. package/ts4.0/resourceTypes.d.ts +4 -8
  62. package/ts4.1/RestEndpointTypes.d.ts +21 -13
  63. package/ts4.1/resourceTypes.d.ts +4 -8
@@ -3,7 +3,7 @@ import type { ExtractCollection } from './extractCollection.js';
3
3
  import { OptionsToBodyArgument, OptionsToFunction } from './OptionsToFunction.js';
4
4
  import { PathArgs } from './pathTypes.js';
5
5
  import { EndpointUpdateFunction } from './RestEndpointTypeHelp.js';
6
- export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
6
+ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
7
7
  path: string;
8
8
  body?: any;
9
9
  searchParams?: any;
@@ -70,7 +70,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
70
70
  */
71
71
  extend<E extends RestInstanceBase, ExtendOptions extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
72
72
  }
73
- export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
73
+ export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
74
74
  path: string;
75
75
  body?: any;
76
76
  searchParams?: any;
@@ -121,25 +121,25 @@ export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends {
121
121
  type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
122
122
  body?: any;
123
123
  paginationField?: string;
124
- }, F extends FetchFunction> = 'path' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
124
+ }, F extends FetchFunction> = 'path' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
125
125
  path: Exclude<O['path'], undefined>;
126
126
  body: 'body' extends keyof O ? O['body'] : E['body'];
127
127
  searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
128
128
  method: 'method' extends keyof O ? O['method'] : E['method'];
129
129
  paginationField: 'paginationField' extends keyof O ? O['paginationField'] : E['paginationField'];
130
- }> : 'body' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
130
+ }> : 'body' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
131
131
  path: E['path'];
132
132
  body: O['body'];
133
133
  searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
134
134
  method: 'method' extends keyof O ? O['method'] : E['method'];
135
135
  paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
136
- }> : 'searchParams' extends keyof O ? RestType<O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
136
+ }> : 'searchParams' extends keyof O ? RestType<O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
137
137
  path: E['path'];
138
138
  body: E['body'];
139
139
  searchParams: O['searchParams'];
140
140
  method: 'method' extends keyof O ? O['method'] : E['method'];
141
141
  paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
142
- }> : RestInstance<F, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], {
142
+ }> : RestInstance<F, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], {
143
143
  path: 'path' extends keyof O ? Exclude<O['path'], undefined> : E['path'];
144
144
  body: 'body' extends keyof O ? O['body'] : E['body'];
145
145
  searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
@@ -177,12 +177,12 @@ export interface RestGenerics extends PartialRestGenerics {
177
177
  readonly path: string;
178
178
  }
179
179
  export type PaginationEndpoint<E extends FetchFunction & RestGenerics & {
180
- sideEffect?: true | undefined;
180
+ sideEffect?: boolean | undefined;
181
181
  }, A extends any[]> = RestInstanceBase<ParamFetchNoBody<A[0], ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
182
182
  searchParams: Omit<A[0], keyof PathArgs<E['path']>>;
183
183
  }>;
184
184
  export type PaginationFieldEndpoint<E extends FetchFunction & RestGenerics & {
185
- sideEffect?: true | undefined;
185
+ sideEffect?: boolean | undefined;
186
186
  }, C extends string> = RestInstanceBase<ParamFetchNoBody<{
187
187
  [K in C]: string | number | boolean;
188
188
  } & E['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
@@ -212,7 +212,7 @@ export interface RestEndpointOptions<F extends FetchFunction = FetchFunction, S
212
212
  getRequestInit?(body: any): Promise<RequestInit> | RequestInit;
213
213
  fetchResponse?(input: RequestInfo, init: RequestInit): Promise<any>;
214
214
  parseResponse?(response: Response): Promise<any>;
215
- sideEffect?: true | undefined;
215
+ sideEffect?: boolean | undefined;
216
216
  name?: string;
217
217
  signal?: AbortSignal;
218
218
  fetch?: F;
@@ -235,7 +235,7 @@ export interface RestEndpointConstructor {
235
235
  }
236
236
  export type MethodToSide<M> = M extends string ? M extends 'GET' ? undefined : true : undefined;
237
237
  /** RestEndpoint types simplified */
238
- export type RestType<UrlParams = any, Body = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, R = any, O extends {
238
+ export type RestType<UrlParams = any, Body = any, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, R = any, O extends {
239
239
  path: string;
240
240
  body?: any;
241
241
  searchParams?: any;
@@ -243,8 +243,8 @@ export type RestType<UrlParams = any, Body = any, S extends Schema | undefined =
243
243
  } = {
244
244
  path: string;
245
245
  paginationField: string;
246
- }> = IfTypeScriptLooseNull<RestInstance<keyof UrlParams extends never ? (this: EndpointInstanceInterface, body?: Body) => Promise<R> : {} extends UrlParams ? ((this: EndpointInstanceInterface, body?: Body) => Promise<R>) | ((this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>) : (this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>, S, M, O>, Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O> : RestTypeNoBody<UrlParams, S, M, R, O>>;
247
- export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, Body = any, R = any, O extends {
246
+ }> = IfTypeScriptLooseNull<RestInstance<RestFetch<UrlParams, Body, R>, S, M, O>, Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O> : RestTypeNoBody<UrlParams, S, M, R, O>>;
247
+ export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, Body = any, R = any, O extends {
248
248
  path: string;
249
249
  body?: any;
250
250
  searchParams?: any;
@@ -252,7 +252,7 @@ export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Sch
252
252
  path: string;
253
253
  body: any;
254
254
  }> = RestInstance<ParamFetchWithBody<UrlParams, Body, R>, S, M, O>;
255
- export type RestTypeNoBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, R = any, O extends {
255
+ export type RestTypeNoBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, R = any, O extends {
256
256
  path: string;
257
257
  body?: undefined;
258
258
  searchParams?: any;
@@ -264,6 +264,14 @@ export type RestTypeNoBody<UrlParams = any, S extends Schema | undefined = Schem
264
264
  export type RestFetch<UrlParams, Body = {}, Resolve = any> = IfTypeScriptLooseNull<ParamFetchNoBody<UrlParams, Resolve> | ParamFetchWithBody<UrlParams, Body, Resolve>, Body extends {} ? ParamFetchWithBody<UrlParams, Body, Resolve> : ParamFetchNoBody<UrlParams, Resolve>>;
265
265
  export type ParamFetchWithBody<P, B = {}, R = any> = P extends undefined ? (this: EndpointInstanceInterface, body: B) => Promise<R> : {} extends P ? keyof P extends never ? (this: EndpointInstanceInterface, body: B) => Promise<R> : ((this: EndpointInstanceInterface, params: P, body: B) => Promise<R>) | ((this: EndpointInstanceInterface, body: B) => Promise<R>) : (this: EndpointInstanceInterface, params: P, body: B) => Promise<R>;
266
266
  export type ParamFetchNoBody<P, R = any> = P extends undefined ? (this: EndpointInstanceInterface) => Promise<R> : {} extends P ? keyof P extends never ? (this: EndpointInstanceInterface) => Promise<R> : ((this: EndpointInstanceInterface, params: P) => Promise<R>) | ((this: EndpointInstanceInterface) => Promise<R>) : (this: EndpointInstanceInterface, params: P) => Promise<R>;
267
+ export type ParamToArgs<P> = P extends undefined ? [
268
+ ] : {} extends P ? keyof P extends never ? [
269
+ ] : [
270
+ ] | [
271
+ P
272
+ ] : [
273
+ P
274
+ ];
267
275
  type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;
268
276
  export type KeyofRestEndpoint = keyof RestInstance;
269
277
  export type FromFallBack<K extends keyof E, O, E> = K extends keyof O ? O[K] : E[K];
@@ -1,9 +1,9 @@
1
1
  import type { Collection, schema } from '@data-client/endpoint';
2
2
  import type { Schema } from '@data-client/endpoint';
3
3
  import type { Denormalize } from '@data-client/endpoint';
4
- import type { PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
4
+ import type { KeysToArgs, PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
5
5
  import { Extendable } from './resourceExtendable.js';
6
- import RestEndpoint, { GetEndpoint, MutateEndpoint, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
6
+ import RestEndpoint, { GetEndpoint, MutateEndpoint, ParamToArgs, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
7
7
  /** The typed (generic) options for a Resource */
8
8
  export interface ResourceGenerics {
9
9
  /** @see https://dataclient.io/rest/api/createResource#path */
@@ -68,18 +68,14 @@ 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']>>
73
- ]>;
71
+ ], ParamToArgs<O['searchParams'] extends undefined ? KeysToArgs<ShortenPath<O['path']>> : O['searchParams'] & PathArgs<ShortenPath<O['path']>>>>;
74
72
  body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
75
73
  searchParams: O['searchParams'];
76
74
  } & Pick<O, 'paginationField'>> : GetEndpoint<{
77
75
  path: ShortenPath<O['path']>;
78
76
  schema: schema.Collection<[
79
77
  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']>>
82
- ]>;
78
+ ], ParamToArgs<(Record<string, number | string | boolean> | undefined) & PathArgs<ShortenPath<O['path']>>>>;
83
79
  body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
84
80
  searchParams: Record<string, number | string | boolean> | undefined;
85
81
  } & Pick<O, 'paginationField'>>;
@@ -3,7 +3,7 @@ import type { ExtractCollection } from './extractCollection.js';
3
3
  import { OptionsToBodyArgument, OptionsToFunction } from './OptionsToFunction.js';
4
4
  import { PathArgs } from './pathTypes.js';
5
5
  import { EndpointUpdateFunction } from './RestEndpointTypeHelp.js';
6
- export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
6
+ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
7
7
  path: string;
8
8
  body?: any;
9
9
  searchParams?: any;
@@ -70,7 +70,7 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
70
70
  */
71
71
  extend<E extends RestInstanceBase, ExtendOptions extends PartialRestGenerics | {}>(this: E, options: Readonly<RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions>): RestExtendedEndpoint<ExtendOptions, E>;
72
72
  }
73
- export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends true | undefined = true | undefined, O extends {
73
+ export interface RestInstance<F extends FetchFunction = FetchFunction, S extends Schema | undefined = any, M extends boolean | undefined = boolean | undefined, O extends {
74
74
  path: string;
75
75
  body?: any;
76
76
  searchParams?: any;
@@ -121,25 +121,25 @@ export type RestEndpointExtendOptions<O extends PartialRestGenerics, E extends {
121
121
  type OptionsToRestEndpoint<O extends PartialRestGenerics, E extends RestInstanceBase & {
122
122
  body?: any;
123
123
  paginationField?: string;
124
- }, F extends FetchFunction> = 'path' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
124
+ }, F extends FetchFunction> = 'path' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>> : PathArgs<Exclude<O['path'], undefined>>, OptionsToBodyArgument<'body' extends keyof O ? O : E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
125
125
  path: Exclude<O['path'], undefined>;
126
126
  body: 'body' extends keyof O ? O['body'] : E['body'];
127
127
  searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
128
128
  method: 'method' extends keyof O ? O['method'] : E['method'];
129
129
  paginationField: 'paginationField' extends keyof O ? O['paginationField'] : E['paginationField'];
130
- }> : 'body' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
130
+ }> : 'body' extends keyof O ? RestType<'searchParams' extends keyof O ? O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>> : PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<O, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
131
131
  path: E['path'];
132
132
  body: O['body'];
133
133
  searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
134
134
  method: 'method' extends keyof O ? O['method'] : E['method'];
135
135
  paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
136
- }> : 'searchParams' extends keyof O ? RestType<O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
136
+ }> : 'searchParams' extends keyof O ? RestType<O['searchParams'] extends undefined ? PathArgs<Exclude<O['path'], undefined>> : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, OptionsToBodyArgument<E, 'method' extends keyof O ? O['method'] : E['method']>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>, {
137
137
  path: E['path'];
138
138
  body: E['body'];
139
139
  searchParams: O['searchParams'];
140
140
  method: 'method' extends keyof O ? O['method'] : E['method'];
141
141
  paginationField: 'paginationField' extends keyof O ? O['paginationField'] : Extract<E['paginationField'], string>;
142
- }> : RestInstance<F, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], {
142
+ }> : RestInstance<F, 'schema' extends keyof O ? O['schema'] : E['schema'], 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true> : 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'], {
143
143
  path: 'path' extends keyof O ? Exclude<O['path'], undefined> : E['path'];
144
144
  body: 'body' extends keyof O ? O['body'] : E['body'];
145
145
  searchParams: 'searchParams' extends keyof O ? O['searchParams'] : E['searchParams'];
@@ -177,12 +177,12 @@ export interface RestGenerics extends PartialRestGenerics {
177
177
  readonly path: string;
178
178
  }
179
179
  export type PaginationEndpoint<E extends FetchFunction & RestGenerics & {
180
- sideEffect?: true | undefined;
180
+ sideEffect?: boolean | undefined;
181
181
  }, A extends any[]> = RestInstanceBase<ParamFetchNoBody<A[0], ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
182
182
  searchParams: Omit<A[0], keyof PathArgs<E['path']>>;
183
183
  }>;
184
184
  export type PaginationFieldEndpoint<E extends FetchFunction & RestGenerics & {
185
- sideEffect?: true | undefined;
185
+ sideEffect?: boolean | undefined;
186
186
  }, C extends string> = RestInstanceBase<ParamFetchNoBody<{
187
187
  [K in C]: string | number | boolean;
188
188
  } & E['searchParams'] & PathArgs<Exclude<E['path'], undefined>>, ResolveType<E>>, E['schema'], E['sideEffect'], Pick<E, 'path' | 'searchParams' | 'body'> & {
@@ -212,7 +212,7 @@ export interface RestEndpointOptions<F extends FetchFunction = FetchFunction, S
212
212
  getRequestInit?(body: any): Promise<RequestInit> | RequestInit;
213
213
  fetchResponse?(input: RequestInfo, init: RequestInit): Promise<any>;
214
214
  parseResponse?(response: Response): Promise<any>;
215
- sideEffect?: true | undefined;
215
+ sideEffect?: boolean | undefined;
216
216
  name?: string;
217
217
  signal?: AbortSignal;
218
218
  fetch?: F;
@@ -235,7 +235,7 @@ export interface RestEndpointConstructor {
235
235
  }
236
236
  export type MethodToSide<M> = M extends string ? M extends 'GET' ? undefined : true : undefined;
237
237
  /** RestEndpoint types simplified */
238
- export type RestType<UrlParams = any, Body = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, R = any, O extends {
238
+ export type RestType<UrlParams = any, Body = any, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, R = any, O extends {
239
239
  path: string;
240
240
  body?: any;
241
241
  searchParams?: any;
@@ -243,8 +243,8 @@ export type RestType<UrlParams = any, Body = any, S extends Schema | undefined =
243
243
  } = {
244
244
  path: string;
245
245
  paginationField: string;
246
- }> = IfTypeScriptLooseNull<RestInstance<keyof UrlParams extends never ? (this: EndpointInstanceInterface, body?: Body) => Promise<R> : {} extends UrlParams ? ((this: EndpointInstanceInterface, body?: Body) => Promise<R>) | ((this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>) : (this: EndpointInstanceInterface, params: UrlParams, body?: Body) => Promise<R>, S, M, O>, Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O> : RestTypeNoBody<UrlParams, S, M, R, O>>;
247
- export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, Body = any, R = any, O extends {
246
+ }> = IfTypeScriptLooseNull<RestInstance<RestFetch<UrlParams, Body, R>, S, M, O>, Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O> : RestTypeNoBody<UrlParams, S, M, R, O>>;
247
+ export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, Body = any, R = any, O extends {
248
248
  path: string;
249
249
  body?: any;
250
250
  searchParams?: any;
@@ -252,7 +252,7 @@ export type RestTypeWithBody<UrlParams = any, S extends Schema | undefined = Sch
252
252
  path: string;
253
253
  body: any;
254
254
  }> = RestInstance<ParamFetchWithBody<UrlParams, Body, R>, S, M, O>;
255
- export type RestTypeNoBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends true | undefined = true | undefined, R = any, O extends {
255
+ export type RestTypeNoBody<UrlParams = any, S extends Schema | undefined = Schema | undefined, M extends boolean | undefined = boolean | undefined, R = any, O extends {
256
256
  path: string;
257
257
  body?: undefined;
258
258
  searchParams?: any;
@@ -264,6 +264,14 @@ export type RestTypeNoBody<UrlParams = any, S extends Schema | undefined = Schem
264
264
  export type RestFetch<UrlParams, Body = {}, Resolve = any> = IfTypeScriptLooseNull<ParamFetchNoBody<UrlParams, Resolve> | ParamFetchWithBody<UrlParams, Body, Resolve>, Body extends {} ? ParamFetchWithBody<UrlParams, Body, Resolve> : ParamFetchNoBody<UrlParams, Resolve>>;
265
265
  export type ParamFetchWithBody<P, B = {}, R = any> = P extends undefined ? (this: EndpointInstanceInterface, body: B) => Promise<R> : {} extends P ? keyof P extends never ? (this: EndpointInstanceInterface, body: B) => Promise<R> : ((this: EndpointInstanceInterface, params: P, body: B) => Promise<R>) | ((this: EndpointInstanceInterface, body: B) => Promise<R>) : (this: EndpointInstanceInterface, params: P, body: B) => Promise<R>;
266
266
  export type ParamFetchNoBody<P, R = any> = P extends undefined ? (this: EndpointInstanceInterface) => Promise<R> : {} extends P ? keyof P extends never ? (this: EndpointInstanceInterface) => Promise<R> : ((this: EndpointInstanceInterface, params: P) => Promise<R>) | ((this: EndpointInstanceInterface) => Promise<R>) : (this: EndpointInstanceInterface, params: P) => Promise<R>;
267
+ export type ParamToArgs<P> = P extends undefined ? [
268
+ ] : {} extends P ? keyof P extends never ? [
269
+ ] : [
270
+ ] | [
271
+ P
272
+ ] : [
273
+ P
274
+ ];
267
275
  type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;
268
276
  export type KeyofRestEndpoint = keyof RestInstance;
269
277
  export type FromFallBack<K extends keyof E, O, E> = K extends keyof O ? O[K] : E[K];
@@ -1,9 +1,9 @@
1
1
  import type { Collection, schema } from '@data-client/endpoint';
2
2
  import type { Schema } from '@data-client/endpoint';
3
3
  import type { Denormalize } from '@data-client/endpoint';
4
- import type { PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
4
+ import type { KeysToArgs, PathArgs, ResourcePath, ShortenPath } from './pathTypes.js';
5
5
  import { Extendable } from './resourceExtendable.js';
6
- import RestEndpoint, { GetEndpoint, MutateEndpoint, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
6
+ import RestEndpoint, { GetEndpoint, MutateEndpoint, ParamToArgs, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
7
7
  /** The typed (generic) options for a Resource */
8
8
  export interface ResourceGenerics {
9
9
  /** @see https://dataclient.io/rest/api/createResource#path */
@@ -68,18 +68,14 @@ 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']>>
73
- ]>;
71
+ ], ParamToArgs<O['searchParams'] extends undefined ? KeysToArgs<ShortenPath<O['path']>> : O['searchParams'] & PathArgs<ShortenPath<O['path']>>>>;
74
72
  body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
75
73
  searchParams: O['searchParams'];
76
74
  } & Pick<O, 'paginationField'>> : GetEndpoint<{
77
75
  path: ShortenPath<O['path']>;
78
76
  schema: schema.Collection<[
79
77
  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']>>
82
- ]>;
78
+ ], ParamToArgs<(Record<string, number | string | boolean> | undefined) & PathArgs<ShortenPath<O['path']>>>>;
83
79
  body: 'body' extends keyof O ? O['body'] : Partial<Denormalize<O['schema']>>;
84
80
  searchParams: Record<string, number | string | boolean> | undefined;
85
81
  } & Pick<O, 'paginationField'>>;