@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.
- package/README.md +16 -0
- package/dist/index.js +8 -1
- package/dist/index.umd.min.js +1 -1
- package/legacy/OptionsToFunction.js +1 -1
- package/legacy/RestEndpoint.js +7 -2
- 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/index.js +2 -1
- package/legacy/mapCollection.js +1 -1
- package/legacy/paramsToString.js +1 -1
- package/legacy/paramsToString.native.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 +7 -2
- package/lib/RestEndpointTypeHelp.d.ts.map +1 -1
- package/lib/RestEndpointTypeHelp.js +1 -1
- package/lib/RestEndpointTypes.d.ts +29 -7
- 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/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/mapCollection.d.ts.map +1 -1
- package/lib/mapCollection.js +1 -1
- package/lib/paramsToString.d.ts +1 -1
- package/lib/paramsToString.d.ts.map +1 -1
- package/lib/paramsToString.js +1 -1
- package/lib/paramsToString.native.d.ts +1 -1
- package/lib/paramsToString.native.d.ts.map +1 -1
- package/lib/paramsToString.native.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.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 +17 -15
- package/src/RestEndpoint.js +9 -4
- package/src/RestEndpointTypeHelp.ts +2 -3
- package/src/RestEndpointTypes.ts +173 -178
- package/src/__tests__/RestEndpoint.ts +54 -2
- package/src/createResource.ts +2 -2
- package/src/extractCollection.ts +13 -13
- package/src/index.ts +1 -0
- package/src/mapCollection.ts +14 -21
- package/src/paramsToString.native.ts +6 -1
- package/src/paramsToString.ts +7 -2
- package/src/pathTypes.ts +27 -36
- package/src/resourceExtensionTypes.ts +33 -48
- package/src/resourceTypes.ts +76 -80
- package/src/utiltypes.ts +3 -3
- package/ts4.0/RestEndpointTypes.d.ts +29 -7
- package/ts4.0/extractCollection.d.ts +2 -2
- package/ts4.0/index.d.ts +1 -0
- package/ts4.0/paramsToString.d.ts +1 -1
- package/ts4.0/paramsToString.native.d.ts +1 -1
- package/ts4.1/RestEndpointTypes.d.ts +29 -7
- package/ts4.1/extractCollection.d.ts +2 -2
- package/ts4.1/index.d.ts +1 -0
- package/ts4.1/paramsToString.d.ts +1 -1
- 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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
1
|
+
export default function paramsToString(searchParams?: string | URLSearchParams | Record<string, string> | string[][] | undefined): string;
|
|
2
2
|
//# sourceMappingURL=paramsToString.native.d.ts.map
|