@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
@@ -24,24 +24,46 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
24
24
  */
25
25
  readonly urlPrefix: string;
26
26
  readonly requestInit: RequestInit;
27
- /** @see https://dataclient.io/rest/api/RestEndpoint#method */
27
+ /** HTTP request method
28
+ * @see https://dataclient.io/rest/api/RestEndpoint#method
29
+ */
28
30
  readonly method: (O & {
29
31
  method: string;
30
32
  })['method'];
31
33
  readonly signal: AbortSignal | undefined;
34
+ /** @see https://dataclient.io/rest/api/RestEndpoint#paginationField */
32
35
  readonly paginationField?: string;
36
+ /** Builds the URL to fetch
37
+ * @see https://dataclient.io/rest/api/RestEndpoint#url
38
+ */
33
39
  url(...args: Parameters<F>): string;
34
- /** @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit */
40
+ /** Encode the searchParams component of the url
41
+ * @see https://dataclient.io/rest/api/RestEndpoint#searchToString
42
+ */
43
+ searchToString(searchParams: Record<string, any>): string;
44
+ /** Prepares RequestInit used in fetch. This is sent to fetchResponse()
45
+ * @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit
46
+ */
35
47
  getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
36
- /** @see https://dataclient.io/rest/api/RestEndpoint#getHeaders */
48
+ /** Called by getRequestInit to determine HTTP Headers
49
+ * @see https://dataclient.io/rest/api/RestEndpoint#getHeaders
50
+ */
37
51
  getHeaders(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
38
- /** @see https://dataclient.io/rest/api/RestEndpoint#fetchResponse */
52
+ /** Performs the fetch call
53
+ * @see https://dataclient.io/rest/api/RestEndpoint#fetchResponse
54
+ */
39
55
  fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
40
- /** @see https://dataclient.io/rest/api/RestEndpoint#parseResponse */
56
+ /** Takes the Response and parses via .text() or .json()
57
+ * @see https://dataclient.io/rest/api/RestEndpoint#parseResponse
58
+ */
41
59
  parseResponse(response: Response): Promise<any>;
42
- /** @see https://dataclient.io/rest/api/RestEndpoint#process */
60
+ /** Perform any transforms with the parsed result.
61
+ * @see https://dataclient.io/rest/api/RestEndpoint#process
62
+ */
43
63
  process(value: any, ...args: Parameters<F>): ResolveType<F>;
44
- /** @see https://dataclient.io/rest/api/RestEndpoint#testKey */
64
+ /** Returns true if the provided (fetch) key matches this endpoint.
65
+ * @see https://dataclient.io/rest/api/RestEndpoint#testKey
66
+ */
45
67
  testKey(key: string): boolean;
46
68
  /** Creates a child endpoint that inherits from this while overriding provided `options`.
47
69
  * @see https://dataclient.io/rest/api/RestEndpoint#extend
@@ -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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as RestEndpoint } from './RestEndpoint.js';
2
2
  export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, PaginationEndpoint, } from './RestEndpoint.js';
3
+ export { getUrlBase, getUrlTokens } from './RestHelpers.js';
3
4
  export { default as createResource } from './createResource.js';
4
5
  export type { Resource } from './resourceTypes.js';
5
6
  export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
@@ -1,2 +1,2 @@
1
- export default function paramsToString(searchParams: Readonly<Record<string, string | number | boolean>>): string;
1
+ export default function paramsToString(searchParams?: string | URLSearchParams | Record<string, string> | string[][] | undefined): string;
2
2
  //# sourceMappingURL=paramsToString.d.ts.map
@@ -1,2 +1,2 @@
1
- export default function paramsToString(searchParams: Readonly<Record<string, string | number>>): string;
1
+ export default function paramsToString(searchParams?: string | URLSearchParams | Record<string, string> | string[][] | undefined): string;
2
2
  //# sourceMappingURL=paramsToString.native.d.ts.map
@@ -24,24 +24,46 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
24
24
  */
25
25
  readonly urlPrefix: string;
26
26
  readonly requestInit: RequestInit;
27
- /** @see https://dataclient.io/rest/api/RestEndpoint#method */
27
+ /** HTTP request method
28
+ * @see https://dataclient.io/rest/api/RestEndpoint#method
29
+ */
28
30
  readonly method: (O & {
29
31
  method: string;
30
32
  })['method'];
31
33
  readonly signal: AbortSignal | undefined;
34
+ /** @see https://dataclient.io/rest/api/RestEndpoint#paginationField */
32
35
  readonly paginationField?: string;
36
+ /** Builds the URL to fetch
37
+ * @see https://dataclient.io/rest/api/RestEndpoint#url
38
+ */
33
39
  url(...args: Parameters<F>): string;
34
- /** @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit */
40
+ /** Encode the searchParams component of the url
41
+ * @see https://dataclient.io/rest/api/RestEndpoint#searchToString
42
+ */
43
+ searchToString(searchParams: Record<string, any>): string;
44
+ /** Prepares RequestInit used in fetch. This is sent to fetchResponse()
45
+ * @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit
46
+ */
35
47
  getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
36
- /** @see https://dataclient.io/rest/api/RestEndpoint#getHeaders */
48
+ /** Called by getRequestInit to determine HTTP Headers
49
+ * @see https://dataclient.io/rest/api/RestEndpoint#getHeaders
50
+ */
37
51
  getHeaders(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
38
- /** @see https://dataclient.io/rest/api/RestEndpoint#fetchResponse */
52
+ /** Performs the fetch call
53
+ * @see https://dataclient.io/rest/api/RestEndpoint#fetchResponse
54
+ */
39
55
  fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
40
- /** @see https://dataclient.io/rest/api/RestEndpoint#parseResponse */
56
+ /** Takes the Response and parses via .text() or .json()
57
+ * @see https://dataclient.io/rest/api/RestEndpoint#parseResponse
58
+ */
41
59
  parseResponse(response: Response): Promise<any>;
42
- /** @see https://dataclient.io/rest/api/RestEndpoint#process */
60
+ /** Perform any transforms with the parsed result.
61
+ * @see https://dataclient.io/rest/api/RestEndpoint#process
62
+ */
43
63
  process(value: any, ...args: Parameters<F>): ResolveType<F>;
44
- /** @see https://dataclient.io/rest/api/RestEndpoint#testKey */
64
+ /** Returns true if the provided (fetch) key matches this endpoint.
65
+ * @see https://dataclient.io/rest/api/RestEndpoint#testKey
66
+ */
45
67
  testKey(key: string): boolean;
46
68
  /** Creates a child endpoint that inherits from this while overriding provided `options`.
47
69
  * @see https://dataclient.io/rest/api/RestEndpoint#extend
@@ -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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as RestEndpoint } from './RestEndpoint.js';
2
2
  export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, FetchMutate, RestFetch, RestType, RestInstance, KeyofRestEndpoint, RestEndpointConstructorOptions, AddEndpoint, PaginationFieldEndpoint, PaginationEndpoint, } from './RestEndpoint.js';
3
+ export { getUrlBase, getUrlTokens } from './RestHelpers.js';
3
4
  export { default as createResource } from './createResource.js';
4
5
  export type { Resource } from './resourceTypes.js';
5
6
  export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
@@ -1,2 +1,2 @@
1
- export default function paramsToString(searchParams: Readonly<Record<string, string | number | boolean>>): string;
1
+ export default function paramsToString(searchParams?: string | URLSearchParams | Record<string, string> | string[][] | undefined): string;
2
2
  //# sourceMappingURL=paramsToString.d.ts.map
@@ -1,2 +1,2 @@
1
- export default function paramsToString(searchParams: Readonly<Record<string, string | number>>): string;
1
+ export default function paramsToString(searchParams?: string | URLSearchParams | Record<string, string> | string[][] | undefined): string;
2
2
  //# sourceMappingURL=paramsToString.native.d.ts.map