@data-client/rest 0.7.5 → 0.8.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/dist/index.js +21 -79
- package/dist/index.umd.min.js +1 -1
- package/dist/next.js +0 -566
- package/legacy/NetworkError.js +2 -2
- package/legacy/RestEndpoint.js +16 -17
- package/legacy/RestEndpointTypes.js +1 -1
- package/legacy/createResource.js +5 -5
- package/legacy/hookifyResource.js +2 -2
- package/legacy/index.js +1 -2
- package/legacy/next/index.js +2 -4
- package/legacy/resourceTypes.js +1 -1
- package/lib/NetworkError.d.ts +1 -1
- package/lib/NetworkError.js +2 -2
- package/lib/RestEndpoint.d.ts +1 -1
- package/lib/RestEndpoint.js +16 -17
- package/lib/RestEndpointTypes.d.ts +15 -15
- package/lib/RestEndpointTypes.d.ts.map +1 -1
- package/lib/RestEndpointTypes.js +1 -1
- package/lib/createResource.d.ts +1 -1
- package/lib/createResource.js +5 -5
- package/lib/hookifyResource.d.ts +1 -1
- package/lib/hookifyResource.js +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- package/lib/next/index.d.ts +0 -5
- package/lib/next/index.d.ts.map +1 -1
- package/lib/next/index.js +2 -4
- package/lib/resourceTypes.d.ts +13 -13
- package/lib/resourceTypes.d.ts.map +1 -1
- package/lib/resourceTypes.js +1 -1
- package/package.json +2 -2
- package/src/NetworkError.ts +1 -1
- package/src/RestEndpoint.d.ts +1 -1
- package/src/RestEndpoint.js +14 -13
- package/src/RestEndpointTypes.ts +15 -15
- package/src/__tests__/Resource.test.ts +10 -8
- package/src/__tests__/RestEndpoint.ts +55 -13
- package/src/__tests__/__snapshots__/RestEndpoint.ts.snap +9 -1
- package/src/__tests__/createResource.test.ts +16 -16
- package/src/__tests__/hookifyResource.ts +9 -9
- package/src/createResource.ts +4 -4
- package/src/hookifyResource.ts +1 -1
- package/src/index.ts +6 -1
- package/src/next/index.ts +0 -5
- package/src/resourceTypes.ts +13 -13
- package/ts4.0/NetworkError.d.ts +1 -1
- package/ts4.0/RestEndpoint.d.ts +1 -1
- package/ts4.0/RestEndpointTypes.d.ts +15 -15
- package/ts4.0/createResource.d.ts +1 -1
- package/ts4.0/hookifyResource.d.ts +1 -1
- package/ts4.0/index.d.ts +1 -1
- package/ts4.0/next/index.d.ts +0 -5
- package/ts4.0/resourceTypes.d.ts +13 -13
- package/ts4.1/NetworkError.d.ts +1 -1
- package/ts4.1/RestEndpoint.d.ts +1 -1
- package/ts4.1/RestEndpointTypes.d.ts +15 -15
- package/ts4.1/createResource.d.ts +1 -1
- package/ts4.1/hookifyResource.d.ts +1 -1
- package/ts4.1/index.d.ts +1 -1
- package/ts4.1/next/index.d.ts +0 -5
- package/ts4.1/resourceTypes.d.ts +13 -13
- package/legacy/getArrayPath.js +0 -19
- package/legacy/paginationUpdate.js +0 -36
- package/lib/getArrayPath.d.ts +0 -3
- package/lib/getArrayPath.d.ts.map +0 -1
- package/lib/getArrayPath.js +0 -19
- package/lib/paginationUpdate.d.ts +0 -8
- package/lib/paginationUpdate.d.ts.map +0 -1
- package/lib/paginationUpdate.js +0 -40
- package/src/__tests__/getArrayPath.test.ts +0 -30
- package/src/getArrayPath.ts +0 -20
- package/src/paginationUpdate.ts +0 -49
- package/ts4.0/getArrayPath.d.ts +0 -3
- package/ts4.0/paginationUpdate.d.ts +0 -10
- package/ts4.1/getArrayPath.d.ts +0 -3
- package/ts4.1/paginationUpdate.d.ts +0 -10
package/ts4.0/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, Fet
|
|
|
3
3
|
export { default as createResource } from './createResource.js';
|
|
4
4
|
export type { Resource } from './resourceTypes.js';
|
|
5
5
|
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
|
6
|
+
export type { ResourceExtension, ResourceEndpointExtensions, CustomResource, ExtendedResource, } from './resourceExtensionTypes.js';
|
|
6
7
|
export { default as hookifyResource } from './hookifyResource.js';
|
|
7
8
|
export type { HookResource, HookableEndpointInterface, } from './hookifyResource.js';
|
|
8
9
|
export { default as NetworkError } from './NetworkError.js';
|
|
9
|
-
export { default as paginationUpdate } from './paginationUpdate.js';
|
|
10
10
|
export type { OptionsToFunction } from './OptionsToFunction.js';
|
|
11
11
|
export type { ShortenPath, PathArgs, PathKeys, KeysToArgs, PathArgsAndSearch, } from './pathTypes.js';
|
|
12
12
|
export * from '@data-client/endpoint';
|
package/ts4.0/next/index.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export * from '../RestEndpoint.js';
|
|
2
|
-
export { default as RestEndpoint } from '../RestEndpoint.js';
|
|
3
|
-
export { default as createResource } from '../createResource.js';
|
|
4
|
-
export type { Resource } from '../resourceTypes.js';
|
|
5
|
-
export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
|
|
6
1
|
//# sourceMappingURL=index.d.ts.map
|
package/ts4.0/resourceTypes.d.ts
CHANGED
|
@@ -6,28 +6,28 @@ import { Extendable } from './resourceExtendable.js';
|
|
|
6
6
|
import RestEndpoint, { GetEndpoint, MutateEndpoint, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
|
|
7
7
|
/** The typed (generic) options for a Resource */
|
|
8
8
|
export interface ResourceGenerics {
|
|
9
|
-
/** @see https://
|
|
9
|
+
/** @see https://dataclient.io/rest/api/createResource#path */
|
|
10
10
|
readonly path: ResourcePath;
|
|
11
|
-
/** @see https://
|
|
11
|
+
/** @see https://dataclient.io/rest/api/createResource#schema */
|
|
12
12
|
readonly schema: Schema;
|
|
13
13
|
/** Only used for types */
|
|
14
14
|
/** @see https://dataclient.io/rest/api/createResource#body */
|
|
15
15
|
readonly body?: any;
|
|
16
16
|
/** Only used for types */
|
|
17
|
-
/** @see https://
|
|
17
|
+
/** @see https://dataclient.io/rest/api/createResource#searchParams */
|
|
18
18
|
readonly searchParams?: any;
|
|
19
|
-
/** @see https://
|
|
19
|
+
/** @see https://dataclient.io/rest/api/createResource#paginationfield */
|
|
20
20
|
readonly paginationField?: string;
|
|
21
21
|
}
|
|
22
22
|
/** The untyped options for createResource() */
|
|
23
23
|
export interface ResourceOptions {
|
|
24
|
-
/** @see https://
|
|
24
|
+
/** @see https://dataclient.io/rest/api/createResource#endpoint */
|
|
25
25
|
Endpoint?: typeof RestEndpoint;
|
|
26
26
|
/** @see https://dataclient.io/rest/api/createResource#collection */
|
|
27
27
|
Collection?: typeof Collection;
|
|
28
|
-
/** @see https://
|
|
28
|
+
/** @see https://dataclient.io/rest/api/createResource#optimistic */
|
|
29
29
|
optimistic?: boolean;
|
|
30
|
-
/** @see https://
|
|
30
|
+
/** @see https://dataclient.io/rest/api/createResource#urlprefix */
|
|
31
31
|
urlPrefix?: string;
|
|
32
32
|
requestInit?: RequestInit;
|
|
33
33
|
getHeaders?(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
|
|
@@ -46,7 +46,7 @@ export interface ResourceOptions {
|
|
|
46
46
|
errorPolicy?(error: any): 'hard' | 'soft' | undefined;
|
|
47
47
|
}
|
|
48
48
|
/** Resources are a collection of methods for a given data model.
|
|
49
|
-
* @see https://
|
|
49
|
+
* @see https://dataclient.io/rest/api/createResource
|
|
50
50
|
*/
|
|
51
51
|
export interface Resource<O extends ResourceGenerics = {
|
|
52
52
|
path: ResourcePath;
|
|
@@ -54,7 +54,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
54
54
|
}> extends Extendable<O> {
|
|
55
55
|
/** Get a singular item
|
|
56
56
|
*
|
|
57
|
-
* @see https://
|
|
57
|
+
* @see https://dataclient.io/rest/api/createResource#get
|
|
58
58
|
*/
|
|
59
59
|
get: GetEndpoint<{
|
|
60
60
|
path: O['path'];
|
|
@@ -62,7 +62,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
62
62
|
}>;
|
|
63
63
|
/** Get a list of item
|
|
64
64
|
*
|
|
65
|
-
* @see https://
|
|
65
|
+
* @see https://dataclient.io/rest/api/createResource#getlist
|
|
66
66
|
*/
|
|
67
67
|
getList: 'searchParams' extends keyof O ? GetEndpoint<{
|
|
68
68
|
path: ShortenPath<O['path']>;
|
|
@@ -99,7 +99,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
99
99
|
}>;
|
|
100
100
|
/** Update an item (PUT)
|
|
101
101
|
*
|
|
102
|
-
* @see https://
|
|
102
|
+
* @see https://dataclient.io/rest/api/createResource#update
|
|
103
103
|
*/
|
|
104
104
|
update: 'body' extends keyof O ? MutateEndpoint<{
|
|
105
105
|
path: O['path'];
|
|
@@ -112,7 +112,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
112
112
|
}>;
|
|
113
113
|
/** Update an item (PATCH)
|
|
114
114
|
*
|
|
115
|
-
* @see https://
|
|
115
|
+
* @see https://dataclient.io/rest/api/createResource#partialupdate
|
|
116
116
|
*/
|
|
117
117
|
partialUpdate: 'body' extends keyof O ? MutateEndpoint<{
|
|
118
118
|
path: O['path'];
|
|
@@ -125,7 +125,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
125
125
|
}>;
|
|
126
126
|
/** Delete an item (DELETE)
|
|
127
127
|
*
|
|
128
|
-
* @see https://
|
|
128
|
+
* @see https://dataclient.io/rest/api/createResource#delete
|
|
129
129
|
*/
|
|
130
130
|
delete: RestTypeNoBody<PathArgs<O['path']>, O['schema'] extends schema.EntityInterface & {
|
|
131
131
|
process: any;
|
package/ts4.1/NetworkError.d.ts
CHANGED
package/ts4.1/RestEndpoint.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RestEndpointConstructor } from './RestEndpointTypes.js';
|
|
|
3
3
|
export * from './RestEndpointTypes.js';
|
|
4
4
|
/** Simplifies endpoint definitions that follow REST patterns
|
|
5
5
|
*
|
|
6
|
-
* @see https://
|
|
6
|
+
* @see https://dataclient.io/rest/api/RestEndpoint
|
|
7
7
|
*/
|
|
8
8
|
export declare let RestEndpoint: RestEndpointConstructor;
|
|
9
9
|
export default RestEndpoint;
|
|
@@ -11,37 +11,37 @@ export interface RestInstanceBase<F extends FetchFunction = FetchFunction, S ext
|
|
|
11
11
|
} = {
|
|
12
12
|
path: string;
|
|
13
13
|
}> extends EndpointInstanceInterface<F, S, M> {
|
|
14
|
-
/** @see https://
|
|
14
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#body */
|
|
15
15
|
readonly body?: 'body' extends keyof O ? O['body'] : any;
|
|
16
|
-
/** @see https://
|
|
16
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
|
|
17
17
|
readonly searchParams?: 'searchParams' extends keyof O ? O['searchParams'] : unknown;
|
|
18
18
|
/** Pattern to construct url based on Url Parameters
|
|
19
|
-
* @see https://
|
|
19
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#path
|
|
20
20
|
*/
|
|
21
21
|
readonly path: O['path'];
|
|
22
22
|
/** Prepended to all urls
|
|
23
|
-
* @see https://
|
|
23
|
+
* @see https://dataclient.io/rest/api/RestEndpoint#urlPrefix
|
|
24
24
|
*/
|
|
25
25
|
readonly urlPrefix: string;
|
|
26
26
|
readonly requestInit: RequestInit;
|
|
27
|
-
/** @see https://
|
|
27
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#method */
|
|
28
28
|
readonly method: (O & {
|
|
29
29
|
method: string;
|
|
30
30
|
})['method'];
|
|
31
31
|
readonly signal: AbortSignal | undefined;
|
|
32
32
|
readonly paginationField?: string;
|
|
33
33
|
url(...args: Parameters<F>): string;
|
|
34
|
-
/** @see https://
|
|
34
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#getRequestInit */
|
|
35
35
|
getRequestInit(this: any, body?: RequestInit['body'] | Record<string, unknown>): Promise<RequestInit> | RequestInit;
|
|
36
|
-
/** @see https://
|
|
36
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#getHeaders */
|
|
37
37
|
getHeaders(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
|
|
38
|
-
/** @see https://
|
|
38
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#fetchResponse */
|
|
39
39
|
fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
|
|
40
|
-
/** @see https://
|
|
40
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#parseResponse */
|
|
41
41
|
parseResponse(response: Response): Promise<any>;
|
|
42
|
-
/** @see https://
|
|
42
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
43
43
|
process(value: any, ...args: Parameters<F>): ResolveType<F>;
|
|
44
|
-
/** @see https://
|
|
44
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#testKey */
|
|
45
45
|
testKey(key: string): boolean;
|
|
46
46
|
/** Creates a child endpoint that inherits from this while overriding provided `options`.
|
|
47
47
|
* @see https://dataclient.io/rest/api/RestEndpoint#extend
|
|
@@ -134,11 +134,11 @@ export type RestExtendedEndpoint<O extends PartialRestGenerics, E extends RestIn
|
|
|
134
134
|
paginationField: E['getPage']['paginationField'];
|
|
135
135
|
} : unknown), RestInstance<(...args: Parameters<E>) => O['process'] extends {} ? Promise<ReturnType<O['process']>> : ReturnType<E>, 'schema' extends keyof O ? O['schema'] : E['schema'], 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']>> & Omit<O, KeyofRestEndpoint> & Omit<E, KeyofRestEndpoint | keyof O>;
|
|
136
136
|
export interface PartialRestGenerics {
|
|
137
|
-
/** @see https://
|
|
137
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#path */
|
|
138
138
|
readonly path?: string;
|
|
139
|
-
/** @see https://
|
|
139
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#schema */
|
|
140
140
|
readonly schema?: Schema | undefined;
|
|
141
|
-
/** @see https://
|
|
141
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#method */
|
|
142
142
|
readonly method?: string;
|
|
143
143
|
/** Only used for types */
|
|
144
144
|
/** @see https://dataclient.io/rest/api/RestEndpoint#body */
|
|
@@ -148,7 +148,7 @@ export interface PartialRestGenerics {
|
|
|
148
148
|
searchParams?: any;
|
|
149
149
|
/** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
|
|
150
150
|
readonly paginationField?: string;
|
|
151
|
-
/** @see https://
|
|
151
|
+
/** @see https://dataclient.io/rest/api/RestEndpoint#process */
|
|
152
152
|
process?(value: any, ...args: any): any;
|
|
153
153
|
}
|
|
154
154
|
export interface RestGenerics extends PartialRestGenerics {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResourceGenerics, ResourceOptions, Resource } from './resourceTypes.js';
|
|
2
2
|
/** Creates collection of Endpoints for common operations on a given data/schema.
|
|
3
3
|
*
|
|
4
|
-
* @see https://
|
|
4
|
+
* @see https://dataclient.io/rest/api/createResource
|
|
5
5
|
*/
|
|
6
6
|
export default function createResource<O extends ResourceGenerics>({ path, schema, Endpoint, Collection, optimistic, paginationField, ...extraOptions }: Readonly<O> & ResourceOptions): Resource<O>;
|
|
7
7
|
//# sourceMappingURL=createResource.d.ts.map
|
|
@@ -5,7 +5,7 @@ export interface HookableEndpointInterface extends EndpointInterface {
|
|
|
5
5
|
/** Turns a collection of Endpoints (Resource) into a collection of hooks.
|
|
6
6
|
* This is useful for Endpoints that need hooks to prepare their fetch requests.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://dataclient.io/rest/api/hookifyResource
|
|
9
9
|
*/
|
|
10
10
|
export default function hookifyResource<R extends {}>(resource: R, useRequestInit: () => RequestInit): HookResource<R>;
|
|
11
11
|
export type HookResource<R extends {}> = {
|
package/ts4.1/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export type { GetEndpoint, MutateEndpoint, Defaults, RestGenerics, FetchGet, Fet
|
|
|
3
3
|
export { default as createResource } from './createResource.js';
|
|
4
4
|
export type { Resource } from './resourceTypes.js';
|
|
5
5
|
export type { ResourceOptions, ResourceGenerics } from './resourceTypes.js';
|
|
6
|
+
export type { ResourceExtension, ResourceEndpointExtensions, CustomResource, ExtendedResource, } from './resourceExtensionTypes.js';
|
|
6
7
|
export { default as hookifyResource } from './hookifyResource.js';
|
|
7
8
|
export type { HookResource, HookableEndpointInterface, } from './hookifyResource.js';
|
|
8
9
|
export { default as NetworkError } from './NetworkError.js';
|
|
9
|
-
export { default as paginationUpdate } from './paginationUpdate.js';
|
|
10
10
|
export type { OptionsToFunction } from './OptionsToFunction.js';
|
|
11
11
|
export type { ShortenPath, PathArgs, PathKeys, KeysToArgs, PathArgsAndSearch, } from './pathTypes.js';
|
|
12
12
|
export * from '@data-client/endpoint';
|
package/ts4.1/next/index.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export * from '../RestEndpoint.js';
|
|
2
|
-
export { default as RestEndpoint } from '../RestEndpoint.js';
|
|
3
|
-
export { default as createResource } from '../createResource.js';
|
|
4
|
-
export type { Resource } from '../resourceTypes.js';
|
|
5
|
-
export type { ResourceOptions, ResourceGenerics } from '../resourceTypes.js';
|
|
6
1
|
//# sourceMappingURL=index.d.ts.map
|
package/ts4.1/resourceTypes.d.ts
CHANGED
|
@@ -6,28 +6,28 @@ import { Extendable } from './resourceExtendable.js';
|
|
|
6
6
|
import RestEndpoint, { GetEndpoint, MutateEndpoint, RestInstanceBase, RestTypeNoBody } from './RestEndpoint.js';
|
|
7
7
|
/** The typed (generic) options for a Resource */
|
|
8
8
|
export interface ResourceGenerics {
|
|
9
|
-
/** @see https://
|
|
9
|
+
/** @see https://dataclient.io/rest/api/createResource#path */
|
|
10
10
|
readonly path: ResourcePath;
|
|
11
|
-
/** @see https://
|
|
11
|
+
/** @see https://dataclient.io/rest/api/createResource#schema */
|
|
12
12
|
readonly schema: Schema;
|
|
13
13
|
/** Only used for types */
|
|
14
14
|
/** @see https://dataclient.io/rest/api/createResource#body */
|
|
15
15
|
readonly body?: any;
|
|
16
16
|
/** Only used for types */
|
|
17
|
-
/** @see https://
|
|
17
|
+
/** @see https://dataclient.io/rest/api/createResource#searchParams */
|
|
18
18
|
readonly searchParams?: any;
|
|
19
|
-
/** @see https://
|
|
19
|
+
/** @see https://dataclient.io/rest/api/createResource#paginationfield */
|
|
20
20
|
readonly paginationField?: string;
|
|
21
21
|
}
|
|
22
22
|
/** The untyped options for createResource() */
|
|
23
23
|
export interface ResourceOptions {
|
|
24
|
-
/** @see https://
|
|
24
|
+
/** @see https://dataclient.io/rest/api/createResource#endpoint */
|
|
25
25
|
Endpoint?: typeof RestEndpoint;
|
|
26
26
|
/** @see https://dataclient.io/rest/api/createResource#collection */
|
|
27
27
|
Collection?: typeof Collection;
|
|
28
|
-
/** @see https://
|
|
28
|
+
/** @see https://dataclient.io/rest/api/createResource#optimistic */
|
|
29
29
|
optimistic?: boolean;
|
|
30
|
-
/** @see https://
|
|
30
|
+
/** @see https://dataclient.io/rest/api/createResource#urlprefix */
|
|
31
31
|
urlPrefix?: string;
|
|
32
32
|
requestInit?: RequestInit;
|
|
33
33
|
getHeaders?(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
|
|
@@ -46,7 +46,7 @@ export interface ResourceOptions {
|
|
|
46
46
|
errorPolicy?(error: any): 'hard' | 'soft' | undefined;
|
|
47
47
|
}
|
|
48
48
|
/** Resources are a collection of methods for a given data model.
|
|
49
|
-
* @see https://
|
|
49
|
+
* @see https://dataclient.io/rest/api/createResource
|
|
50
50
|
*/
|
|
51
51
|
export interface Resource<O extends ResourceGenerics = {
|
|
52
52
|
path: ResourcePath;
|
|
@@ -54,7 +54,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
54
54
|
}> extends Extendable<O> {
|
|
55
55
|
/** Get a singular item
|
|
56
56
|
*
|
|
57
|
-
* @see https://
|
|
57
|
+
* @see https://dataclient.io/rest/api/createResource#get
|
|
58
58
|
*/
|
|
59
59
|
get: GetEndpoint<{
|
|
60
60
|
path: O['path'];
|
|
@@ -62,7 +62,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
62
62
|
}>;
|
|
63
63
|
/** Get a list of item
|
|
64
64
|
*
|
|
65
|
-
* @see https://
|
|
65
|
+
* @see https://dataclient.io/rest/api/createResource#getlist
|
|
66
66
|
*/
|
|
67
67
|
getList: 'searchParams' extends keyof O ? GetEndpoint<{
|
|
68
68
|
path: ShortenPath<O['path']>;
|
|
@@ -99,7 +99,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
99
99
|
}>;
|
|
100
100
|
/** Update an item (PUT)
|
|
101
101
|
*
|
|
102
|
-
* @see https://
|
|
102
|
+
* @see https://dataclient.io/rest/api/createResource#update
|
|
103
103
|
*/
|
|
104
104
|
update: 'body' extends keyof O ? MutateEndpoint<{
|
|
105
105
|
path: O['path'];
|
|
@@ -112,7 +112,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
112
112
|
}>;
|
|
113
113
|
/** Update an item (PATCH)
|
|
114
114
|
*
|
|
115
|
-
* @see https://
|
|
115
|
+
* @see https://dataclient.io/rest/api/createResource#partialupdate
|
|
116
116
|
*/
|
|
117
117
|
partialUpdate: 'body' extends keyof O ? MutateEndpoint<{
|
|
118
118
|
path: O['path'];
|
|
@@ -125,7 +125,7 @@ export interface Resource<O extends ResourceGenerics = {
|
|
|
125
125
|
}>;
|
|
126
126
|
/** Delete an item (DELETE)
|
|
127
127
|
*
|
|
128
|
-
* @see https://
|
|
128
|
+
* @see https://dataclient.io/rest/api/createResource#delete
|
|
129
129
|
*/
|
|
130
130
|
delete: RestTypeNoBody<PathArgs<O['path']>, O['schema'] extends schema.EntityInterface & {
|
|
131
131
|
process: any;
|
package/legacy/getArrayPath.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { schema } from '@data-client/endpoint';
|
|
2
|
-
export default function getArrayPath(s) {
|
|
3
|
-
if (typeof s !== 'object') return false;
|
|
4
|
-
if (s === undefined || s instanceof schema.Array || Array.isArray(s)) {
|
|
5
|
-
return [];
|
|
6
|
-
}
|
|
7
|
-
const o = s instanceof schema.Object ? s.schema : s;
|
|
8
|
-
for (const k in o) {
|
|
9
|
-
if (!o[k]) continue;
|
|
10
|
-
const path = getArrayPath(o[k]);
|
|
11
|
-
if (path !== false) {
|
|
12
|
-
// mutation is ok because there is only one path
|
|
13
|
-
path.unshift(k);
|
|
14
|
-
return path;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJzY2hlbWEiLCJnZXRBcnJheVBhdGgiLCJzIiwidW5kZWZpbmVkIiwiQXJyYXkiLCJpc0FycmF5IiwibyIsIk9iamVjdCIsImsiLCJwYXRoIiwidW5zaGlmdCJdLCJzb3VyY2VzIjpbIi4uL3NyYy9nZXRBcnJheVBhdGgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgU2NoZW1hLCBzY2hlbWEgfSBmcm9tICdAZGF0YS1jbGllbnQvZW5kcG9pbnQnO1xuXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiBnZXRBcnJheVBhdGgoczogU2NoZW1hIHwgdW5kZWZpbmVkKTogc3RyaW5nW10gfCBmYWxzZSB7XG4gIGlmICh0eXBlb2YgcyAhPT0gJ29iamVjdCcpIHJldHVybiBmYWxzZTtcbiAgaWYgKHMgPT09IHVuZGVmaW5lZCB8fCBzIGluc3RhbmNlb2Ygc2NoZW1hLkFycmF5IHx8IEFycmF5LmlzQXJyYXkocykpIHtcbiAgICByZXR1cm4gW107XG4gIH1cbiAgY29uc3QgbzogUmVjb3JkPHN0cmluZywgU2NoZW1hPiA9XG4gICAgcyBpbnN0YW5jZW9mIHNjaGVtYS5PYmplY3QgPyAocyBhcyBhbnkpLnNjaGVtYSA6IHM7XG4gIGZvciAoY29uc3QgayBpbiBvKSB7XG4gICAgaWYgKCFvW2tdKSBjb250aW51ZTtcbiAgICBjb25zdCBwYXRoID0gZ2V0QXJyYXlQYXRoKG9ba10pO1xuICAgIGlmIChwYXRoICE9PSBmYWxzZSkge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default function paginationUpdate(endpoint, removeCursor) {
|
|
3
|
-
// infer path from schema. if schema is undefined assume array is top level
|
|
4
|
-
const path = getArrayPath(endpoint.schema);
|
|
5
|
-
if (path === false) throw new Error('schema has no array');
|
|
6
|
-
return (newPage, ...args) => ({
|
|
7
|
-
[endpoint.key(...removeCursor(...args))]: existing => {
|
|
8
|
-
const existingList = getIn(existing, path);
|
|
9
|
-
// using set so our lookups are O(1) in case this is large
|
|
10
|
-
const existingSet = new Set(existingList);
|
|
11
|
-
const addedList = getIn(newPage, path).filter(pk => !existingSet.has(pk));
|
|
12
|
-
const mergedResults = [...existingList, ...addedList];
|
|
13
|
-
return setIn(newPage, path, mergedResults);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const getIn = (results, path) => {
|
|
18
|
-
let cur = results;
|
|
19
|
-
for (const p of path) {
|
|
20
|
-
if (!cur) return [];
|
|
21
|
-
cur = cur[p];
|
|
22
|
-
}
|
|
23
|
-
return cur || [];
|
|
24
|
-
};
|
|
25
|
-
const setIn = (results, path, values) => {
|
|
26
|
-
if (path.length === 0) return values;
|
|
27
|
-
const newResults = Object.assign({}, results);
|
|
28
|
-
let cur = newResults;
|
|
29
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
30
|
-
const p = path[i];
|
|
31
|
-
cur = cur[p] = Object.assign({}, cur[p]);
|
|
32
|
-
}
|
|
33
|
-
cur[path[path.length - 1]] = values;
|
|
34
|
-
return newResults;
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJnZXRBcnJheVBhdGgiLCJwYWdpbmF0aW9uVXBkYXRlIiwiZW5kcG9pbnQiLCJyZW1vdmVDdXJzb3IiLCJwYXRoIiwic2NoZW1hIiwiRXJyb3IiLCJuZXdQYWdlIiwiYXJncyIsImtleSIsImV4aXN0aW5nIiwiZXhpc3RpbmdMaXN0IiwiZ2V0SW4iLCJ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DLE1BQUEsS0FBUU4sR0FBRyxDQUFDQyxDQUFDLENBQUMsQ0FBRTtFQUM5QjtFQUNBRCxHQUFHLENBQUNsQixJQUFJLENBQUNBLElBQUksQ0FBQ3FCLE1BQU0sR0FBRyxDQUFDLENBQUMsQ0FBQyxHQUFHRCxNQUFNO0VBQ25DLE9BQU9FLFVBQVU7QUFDbkIsQ0FBQyJ9
|
package/lib/getArrayPath.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getArrayPath.d.ts","sourceRoot":"","sources":["../src/getArrayPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,uBAAuB,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,KAAK,CAiB5E"}
|
package/lib/getArrayPath.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { schema } from '@data-client/endpoint';
|
|
2
|
-
export default function getArrayPath(s) {
|
|
3
|
-
if (typeof s !== 'object') return false;
|
|
4
|
-
if (s === undefined || s instanceof schema.Array || Array.isArray(s)) {
|
|
5
|
-
return [];
|
|
6
|
-
}
|
|
7
|
-
const o = s instanceof schema.Object ? s.schema : s;
|
|
8
|
-
for (const k in o) {
|
|
9
|
-
if (!o[k]) continue;
|
|
10
|
-
const path = getArrayPath(o[k]);
|
|
11
|
-
if (path !== false) {
|
|
12
|
-
// mutation is ok because there is only one path
|
|
13
|
-
path.unshift(k);
|
|
14
|
-
return path;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJzY2hlbWEiLCJnZXRBcnJheVBhdGgiLCJzIiwidW5kZWZpbmVkIiwiQXJyYXkiLCJpc0FycmF5IiwibyIsIk9iamVjdCIsImsiL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FBRSxPQUFPLEtBQUs7RUFDdkMsSUFBSUEsQ0FBQyxLQUFLQyxTQUFTLElBQUlELENBQUMsWUFBWUYsTUFBTSxDQUFDSSxLQUFLLElBQUlBLEtBQUssQ0FBQ0MsT0FBTyxDQUFDSCxDQUFDLENBQUMsRUFBRTtJQUNwRSxPQUFPLEVBQUU7RUFDWDtFQUNBLE1BQU1JLENBQXlCLEdBQzdCSixDQUFDLFlBQVlGLE1BQU0sQ0FBQ08sTUFBTSxHQUFJTCxDQUFDLENBQVNGLE1BQU0sR0FBR0UsQ0FBQztFQUNwRCxLQUFLLE1BQU1NLENBQUMsSUFBSUYsQ0FBQyxFQUFFO0lBQ2pCLElBQUksQ0FBQ0EsQ0FBQyxDQUFDRSxDQUFDLENBQUMsRUFBRTtJQUNYLE1BQU1DLElBQUksR0FBR1IsWUFBWSxDQUFDSyxDQUFDLENBQUNFLENBQUMsQ0FBQyxDQUFDO0lBQy9CLElBQUlDLElBQUksS0FBSyxLQUFLLEVBQUU7TUFDbEI7TUFDQUEsSUFBSSxDQUFDQyxPQUFPLENBQUNGLENBQUMsQ0FBQztNQUNmLE9BQU9DLElBQUk7SUFDYjtFQUNGO0VBQ0EsT0FBTyxLQUFLO0FBQ2QifQ==
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@data-client/endpoint';
|
|
2
|
-
export default function paginationUpdate<E extends {
|
|
3
|
-
schema: Schema;
|
|
4
|
-
key: any;
|
|
5
|
-
} & ((...args: any) => Promise<any>), A extends any[]>(endpoint: E, removeCursor: (...args: A) => readonly [...Parameters<typeof endpoint>]): (newPage: any, ...args: A) => {
|
|
6
|
-
[x: number]: (existing: any) => any;
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=paginationUpdate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginationUpdate.d.ts","sourceRoot":"","sources":["../src/paginationUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,EACzE,CAAC,SAAS,GAAG,EAAE,EAEf,QAAQ,EAAE,CAAC,EACX,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,SAAS,CAAC,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,aAMtD,GAAG,WAAW,CAAC;4BACgC,GAAG;EAWpE"}
|
package/lib/paginationUpdate.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import getArrayPath from './getArrayPath.js';
|
|
2
|
-
export default function paginationUpdate(endpoint, removeCursor) {
|
|
3
|
-
// infer path from schema. if schema is undefined assume array is top level
|
|
4
|
-
const path = getArrayPath(endpoint.schema);
|
|
5
|
-
if (path === false) throw new Error('schema has no array');
|
|
6
|
-
return (newPage, ...args) => ({
|
|
7
|
-
[endpoint.key(...removeCursor(...args))]: existing => {
|
|
8
|
-
const existingList = getIn(existing, path);
|
|
9
|
-
// using set so our lookups are O(1) in case this is large
|
|
10
|
-
const existingSet = new Set(existingList);
|
|
11
|
-
const addedList = getIn(newPage, path).filter(pk => !existingSet.has(pk));
|
|
12
|
-
const mergedResults = [...existingList, ...addedList];
|
|
13
|
-
return setIn(newPage, path, mergedResults);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const getIn = (results, path) => {
|
|
18
|
-
let cur = results;
|
|
19
|
-
for (const p of path) {
|
|
20
|
-
if (!cur) return [];
|
|
21
|
-
cur = cur[p];
|
|
22
|
-
}
|
|
23
|
-
return cur || [];
|
|
24
|
-
};
|
|
25
|
-
const setIn = (results, path, values) => {
|
|
26
|
-
if (path.length === 0) return values;
|
|
27
|
-
const newResults = {
|
|
28
|
-
...results
|
|
29
|
-
};
|
|
30
|
-
let cur = newResults;
|
|
31
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
32
|
-
const p = path[i];
|
|
33
|
-
cur = cur[p] = {
|
|
34
|
-
...cur[p]
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
cur[path[path.length - 1]] = values;
|
|
38
|
-
return newResults;
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJnZXRBcnJheVBhdGgiLCJwYWdpbmF0aW9uVXBkYXRlIiwiZW5kcG9pbnQiLCJyZW1vdmVDdXJzb3IiLCJwYXRoIiwic2NoZW1hIiwiRXJyb3IiLCJuZXdQYWdlIiwiYXJncyIsImtleSIsImV4aXN0aW5nIiwiZXhpc3RpbmdMaXN0IiwiZ2V0SW4iLCJleGlzdGluZ1NldCIsIlNldCIsImFkZGVkTGlzdCIsImZpbHRlciIsInBrIiwiaGFzIiwibWVyZ2VkUmVzdWx0cyIsInNldEluIiwicmVzdWx0cyIsImN1ciIsInAiLCJ2YWx1ZXMiLCJsZW5ndGgiLCJuZXdSZXN1bHRzIiwiaSJdLCJzb3VyY2VzIjpbIi4uL3NyYy9wYWdpbmF0aW9uVXBkYXRlLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IFNjaGVtYSB9IGZyb20gJ0BkYXRhLWNsaWVudC9lbmRwb2ludCc7XG5cbmltcG9ydCBnZXRBcnJheVBhdGggZnJvbSAnLi9nZXRBcnJheVBhdGguanMnO1xuXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiBwYWdpbmF0aW9uVXBkYXRlPFxuICBFIGV4dGVuZHMgeyBzY2hlbWE6IFNjaGVtYTsga2V5OiBhbnkgfSAmICgoLi4uYXJnczogYW55KSA9PiBQcm9taXNlPGFueT4pLFxuICBBIGV4dGVuZHMgYW55W10sXG4+K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xFQUFFb0IsTUFBYSxLQUFRO0VBQ2pFLElBQUlwQixJQUFJLENBQUNxQixNQUFNLEtBQUssQ0FBQyxFQUFFLE9BQU9ELE1BQU07RUFDcEMsTUFBTUUsVUFBVSxHQUFHO0lBQUUsR0FBR0w7RUFBUSxDQUFDO0VBQ2pDLElBQUlDLEdBQVEsR0FBR0ksVUFBVTtFQUN6QixLQUFLLElBQUlDLENBQUMsR0FBRyxDQUFDLEVBQUVBLENBQUMsR0FBR3ZCLElBQUksQ0FBQ3FCLE1BQU0sR0FBRyxDQUFDLEVBQUVFLENBQUMsRUFBRSxFQUFFO0lBQ3hDLE1BQU1KLENBQUMsR0FBR25CLElBQUksQ0FBQ3VCLENBQUMsQ0FBQztJQUNqQkwsR0FBRyxHQUFHQSxHQUFHLENBQUNDLENBQUMsQ0FBQyxHQUFHO01BQUUsR0FBR0QsR0FBRyxDQUFDQyxDQUFDO0lBQUUsQ0FBQztFQUM5QjtFQUNBRCxHQUFHLENBQUNsQixJQUFJLENBQUNBLElBQUksQ0FBQ3FCLE1BQU0sR0FBRyxDQUFDLENBQUMsQ0FBQyxHQUFHRCxNQUFNO0VBQ25DLE9BQU9FLFVBQVU7QUFDbkIsQ0FBQyJ9
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CoolerArticle } from '__tests__/new';
|
|
2
|
-
|
|
3
|
-
import { schema } from '..';
|
|
4
|
-
import getArrayPath from '../getArrayPath';
|
|
5
|
-
|
|
6
|
-
describe('getArrayPath()', () => {
|
|
7
|
-
it('should be false when there is no array', () => {
|
|
8
|
-
expect(getArrayPath({ data: 5 })).toBe(false);
|
|
9
|
-
expect(getArrayPath({ data: 5, other: undefined, stringer: 'hi' })).toBe(
|
|
10
|
-
false,
|
|
11
|
-
);
|
|
12
|
-
});
|
|
13
|
-
it('should find entity inside pojo', () => {
|
|
14
|
-
expect(
|
|
15
|
-
getArrayPath({ data: 5, right: [CoolerArticle], stringer: 'hi' }),
|
|
16
|
-
).toStrictEqual(['right']);
|
|
17
|
-
});
|
|
18
|
-
it('should find entity inside schema.Object', () => {
|
|
19
|
-
expect(
|
|
20
|
-
getArrayPath(
|
|
21
|
-
new schema.Object({ data: 5, right: [CoolerArticle], stringer: 'hi' }),
|
|
22
|
-
),
|
|
23
|
-
).toStrictEqual(['right']);
|
|
24
|
-
});
|
|
25
|
-
it('should be false when has entity but no array', () => {
|
|
26
|
-
expect(
|
|
27
|
-
getArrayPath({ data: 5, right: CoolerArticle, stringer: 'hi' }),
|
|
28
|
-
).toStrictEqual(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
package/src/getArrayPath.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Schema, schema } from '@data-client/endpoint';
|
|
2
|
-
|
|
3
|
-
export default function getArrayPath(s: Schema | undefined): string[] | false {
|
|
4
|
-
if (typeof s !== 'object') return false;
|
|
5
|
-
if (s === undefined || s instanceof schema.Array || Array.isArray(s)) {
|
|
6
|
-
return [];
|
|
7
|
-
}
|
|
8
|
-
const o: Record<string, Schema> =
|
|
9
|
-
s instanceof schema.Object ? (s as any).schema : s;
|
|
10
|
-
for (const k in o) {
|
|
11
|
-
if (!o[k]) continue;
|
|
12
|
-
const path = getArrayPath(o[k]);
|
|
13
|
-
if (path !== false) {
|
|
14
|
-
// mutation is ok because there is only one path
|
|
15
|
-
path.unshift(k);
|
|
16
|
-
return path;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
}
|
package/src/paginationUpdate.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@data-client/endpoint';
|
|
2
|
-
|
|
3
|
-
import getArrayPath from './getArrayPath.js';
|
|
4
|
-
|
|
5
|
-
export default function paginationUpdate<
|
|
6
|
-
E extends { schema: Schema; key: any } & ((...args: any) => Promise<any>),
|
|
7
|
-
A extends any[],
|
|
8
|
-
>(
|
|
9
|
-
endpoint: E,
|
|
10
|
-
removeCursor: (...args: A) => readonly [...Parameters<typeof endpoint>],
|
|
11
|
-
) {
|
|
12
|
-
// infer path from schema. if schema is undefined assume array is top level
|
|
13
|
-
const path = getArrayPath(endpoint.schema);
|
|
14
|
-
if (path === false) throw new Error('schema has no array');
|
|
15
|
-
|
|
16
|
-
return (newPage: any, ...args: A) => ({
|
|
17
|
-
[endpoint.key(...(removeCursor(...args) as any))]: (existing: any) => {
|
|
18
|
-
const existingList = getIn(existing, path);
|
|
19
|
-
// using set so our lookups are O(1) in case this is large
|
|
20
|
-
const existingSet: Set<string> = new Set(existingList);
|
|
21
|
-
const addedList = getIn(newPage, path).filter(
|
|
22
|
-
(pk: string) => !existingSet.has(pk),
|
|
23
|
-
);
|
|
24
|
-
const mergedResults: string[] = [...existingList, ...addedList];
|
|
25
|
-
return setIn(newPage, path, mergedResults);
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const getIn = (results: any, path: string[]): any[] => {
|
|
31
|
-
let cur = results;
|
|
32
|
-
for (const p of path) {
|
|
33
|
-
if (!cur) return [];
|
|
34
|
-
cur = cur[p];
|
|
35
|
-
}
|
|
36
|
-
return cur || [];
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const setIn = <T>(results: T, path: string[], values: any[]): T => {
|
|
40
|
-
if (path.length === 0) return values as any;
|
|
41
|
-
const newResults = { ...results };
|
|
42
|
-
let cur: any = newResults;
|
|
43
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
44
|
-
const p = path[i];
|
|
45
|
-
cur = cur[p] = { ...cur[p] };
|
|
46
|
-
}
|
|
47
|
-
cur[path[path.length - 1]] = values;
|
|
48
|
-
return newResults;
|
|
49
|
-
};
|
package/ts4.0/getArrayPath.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@data-client/endpoint';
|
|
2
|
-
export default function paginationUpdate<E extends {
|
|
3
|
-
schema: Schema;
|
|
4
|
-
key: any;
|
|
5
|
-
} & ((...args: any) => Promise<any>), A extends any[]>(endpoint: E, removeCursor: (...args: A) => readonly [
|
|
6
|
-
...Parameters<typeof endpoint>
|
|
7
|
-
]): (newPage: any, ...args: A) => {
|
|
8
|
-
[x: number]: (existing: any) => any;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=paginationUpdate.d.ts.map
|
package/ts4.1/getArrayPath.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@data-client/endpoint';
|
|
2
|
-
export default function paginationUpdate<E extends {
|
|
3
|
-
schema: Schema;
|
|
4
|
-
key: any;
|
|
5
|
-
} & ((...args: any) => Promise<any>), A extends any[]>(endpoint: E, removeCursor: (...args: A) => readonly [
|
|
6
|
-
...Parameters<typeof endpoint>
|
|
7
|
-
]): (newPage: any, ...args: A) => {
|
|
8
|
-
[x: number]: (existing: any) => any;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=paginationUpdate.d.ts.map
|