@data-client/rest 0.4.0 → 0.5.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 (60) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +39 -3
  3. package/dist/index.umd.min.js +1 -1
  4. package/dist/next.js +39 -3
  5. package/legacy/OptionsToFunction.js +1 -1
  6. package/legacy/createResource.js +34 -6
  7. package/legacy/index.js +1 -1
  8. package/legacy/next/index.js +1 -1
  9. package/legacy/resourceExtendable.js +2 -0
  10. package/legacy/resourceExtensionTypes.js +2 -0
  11. package/legacy/resourceTypes.js +1 -1
  12. package/lib/OptionsToFunction.d.ts +1 -1
  13. package/lib/OptionsToFunction.d.ts.map +1 -1
  14. package/lib/OptionsToFunction.js +1 -1
  15. package/lib/RestEndpoint.d.ts +33 -16
  16. package/lib/createResource.d.ts +2 -96
  17. package/lib/createResource.d.ts.map +1 -1
  18. package/lib/createResource.js +40 -4
  19. package/lib/index.d.ts +2 -2
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +1 -1
  22. package/lib/next/index.d.ts +1 -1
  23. package/lib/next/index.d.ts.map +1 -1
  24. package/lib/next/index.js +1 -1
  25. package/lib/resourceExtendable.d.ts +25 -0
  26. package/lib/resourceExtendable.d.ts.map +1 -0
  27. package/lib/resourceExtendable.js +2 -0
  28. package/lib/resourceExtensionTypes.d.ts +33 -0
  29. package/lib/resourceExtensionTypes.d.ts.map +1 -0
  30. package/lib/resourceExtensionTypes.js +2 -0
  31. package/lib/resourceTypes.d.ts +94 -4
  32. package/lib/resourceTypes.d.ts.map +1 -1
  33. package/lib/resourceTypes.js +1 -1
  34. package/package.json +1 -1
  35. package/src/OptionsToFunction.ts +1 -1
  36. package/src/RestEndpoint.d.ts +33 -16
  37. package/src/__tests__/createResource.test.ts +490 -19
  38. package/src/createResource.ts +54 -126
  39. package/src/index.ts +2 -1
  40. package/src/next/index.ts +1 -1
  41. package/src/resourceExtendable.ts +95 -0
  42. package/src/resourceExtensionTypes.ts +109 -0
  43. package/src/resourceTypes.ts +119 -4
  44. package/ts4.0/RestEndpoint.d.ts +25 -7
  45. package/ts4.0/createResource.d.ts +2 -108
  46. package/ts4.0/index.d.ts +2 -2
  47. package/ts4.0/next/index.d.ts +1 -1
  48. package/ts4.0/resourceExtendable.d.ts +21 -0
  49. package/ts4.0/resourceExtensionTypes.d.ts +33 -0
  50. package/ts4.0/resourceTypes.d.ts +102 -4
  51. package/ts4.1/OptionsToFunction.d.ts +1 -1
  52. package/ts4.1/RestEndpoint.d.ts +25 -7
  53. package/ts4.1/createResource.d.ts +2 -108
  54. package/ts4.1/index.d.ts +2 -2
  55. package/ts4.1/next/index.d.ts +1 -1
  56. package/ts4.1/resourceExtendable.d.ts +21 -0
  57. package/ts4.1/resourceExtensionTypes.d.ts +33 -0
  58. package/ts4.1/resourceTypes.d.ts +102 -4
  59. package/ts4.0/deleteme.d.ts +0 -0
  60. package/ts4.1/deleteme.d.ts +0 -0
@@ -5,7 +5,6 @@ import type {
5
5
  Schema,
6
6
  FetchFunction,
7
7
  ResolveType,
8
- schema,
9
8
  } from '@data-client/endpoint';
10
9
 
11
10
  import type { ExtractCollection } from './extractCollection.js';
@@ -27,7 +26,9 @@ export interface RestInstanceBase<
27
26
  method?: string;
28
27
  } = { path: string },
29
28
  > extends EndpointInstanceInterface<F, S, M> {
29
+ /** @see https://resthooks.io/rest/api/RestEndpoint#body */
30
30
  readonly body?: 'body' extends keyof O ? O['body'] : any;
31
+ /** @see https://resthooks.io/rest/api/RestEndpoint#searchParams */
31
32
  readonly searchParams?: 'searchParams' extends keyof O
32
33
  ? O['searchParams']
33
34
  : // unknown is identity with '&' type operator
@@ -42,6 +43,7 @@ export interface RestInstanceBase<
42
43
  */
43
44
  readonly urlPrefix: string;
44
45
  readonly requestInit: RequestInit;
46
+ /** @see https://resthooks.io/rest/api/RestEndpoint#method */
45
47
  readonly method: (O & { method: string })['method'];
46
48
  readonly signal: AbortSignal | undefined;
47
49
 
@@ -72,10 +74,29 @@ export interface RestInstanceBase<
72
74
  // this is just a hack to handle when no members of PartialRestGenerics are present
73
75
  // Note: Using overloading (like paginated did) struggles because typescript does not have a clear way of distinguishing one
74
76
  // should be used from the other (due to same problem with every member being partial)
77
+ /** Creates a child endpoint that inherits from this while overriding provided `options`.
78
+ * @see https://dataclient.io/rest/api/RestEndpoint#extend
79
+ */
75
80
  extend<E extends RestInstanceBase, O extends PartialRestGenerics | {}>(
76
81
  this: E,
77
82
  options: Readonly<RestEndpointExtendOptions<O, E, F> & O>,
78
83
  ): RestExtendedEndpoint<O, E>;
84
+ }
85
+
86
+ export interface RestInstance<
87
+ F extends FetchFunction = FetchFunction,
88
+ S extends Schema | undefined = any,
89
+ M extends true | undefined = true | undefined,
90
+ O extends {
91
+ path: string;
92
+ body?: any;
93
+ searchParams?: any;
94
+ method?: string;
95
+ } = { path: string },
96
+ > extends RestInstanceBase<F, S, M, O> {
97
+ /** Endpoint to append the next page extending a list for pagination
98
+ * @see https://dataclient.io/rest/api/RestEndpoint#paginated
99
+ */
79
100
  paginated<
80
101
  E extends RestInstanceBase<FetchFunction, any, undefined>,
81
102
  A extends any[],
@@ -90,19 +111,9 @@ export interface RestInstanceBase<
90
111
  this: E,
91
112
  cursorField: C,
92
113
  ): PaginationFieldEndpoint<E, C>;
93
- }
94
-
95
- export interface RestInstance<
96
- F extends FetchFunction = FetchFunction,
97
- S extends Schema | undefined = any,
98
- M extends true | undefined = true | undefined,
99
- O extends {
100
- path: string;
101
- body?: any;
102
- searchParams?: any;
103
- method?: string;
104
- } = { path: string },
105
- > extends RestInstanceBase<F, S, M, O> {
114
+ /** Endpoint that pushes (place at end) a newly created entity to this Collection
115
+ * @see https://dataclient.io/rest/api/RestEndpoint#push
116
+ */
106
117
  push: AddEndpoint<
107
118
  F,
108
119
  ExtractCollection<S>['push'],
@@ -113,6 +124,9 @@ export interface RestInstance<
113
124
  | FormData;
114
125
  }
115
126
  >;
127
+ /** Endpoint that unshifts (place at start) a newly created entity to this Collection
128
+ * @see https://dataclient.io/rest/api/RestEndpoint#unshift
129
+ */
116
130
  unshift: AddEndpoint<
117
131
  F,
118
132
  ExtractCollection<S>['unshift'],
@@ -123,6 +137,9 @@ export interface RestInstance<
123
137
  | FormData;
124
138
  }
125
139
  >;
140
+ /** Endpoint that assigns newly created entities to their respective keys in this Collection
141
+ * @see https://dataclient.io/rest/api/RestEndpoint#assign
142
+ */
126
143
  assign: AddEndpoint<
127
144
  F,
128
145
  ExtractCollection<S>,
@@ -309,7 +326,7 @@ export type AddEndpoint<
309
326
  >,
310
327
  S,
311
328
  true,
312
- O & { method: 'POST' }
329
+ Omit<O, 'method'> & { method: 'POST' }
313
330
  >;
314
331
 
315
332
  type OptionsBodyDefault<O extends RestGenerics> = 'body' extends keyof O
@@ -598,5 +615,5 @@ export type MutateEndpoint<
598
615
  true,
599
616
  O['body'],
600
617
  any,
601
- O & { body: any; method: 'POST' | 'PUT' | 'PATCH' }
618
+ O & { body: any; method: 'POST' | 'PUT' | 'PATCH' | 'DELETE' }
602
619
  >;